summaryrefslogtreecommitdiffstats
path: root/src/cc4group.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cc4group.c')
-rw-r--r--src/cc4group.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cc4group.c b/src/cc4group.c
index ce4dbb1..0761370 100644
--- a/src/cc4group.c
+++ b/src/cc4group.c
@@ -51,6 +51,13 @@ static bool cc4group_getEntryData(CC4Group* const this, const char* const entryP
#define CC4GROUP_UNEXPECTED_EOD -100
#define CC4GROUP_MEM_ERROR -101
+typedef enum {
+ CC4Group_AllowedEntryTypes_File = 0x01,
+ CC4Group_AllowedEntryTypes_Directory = 0x02,
+
+ CC4Group_AllowedEntryTypes_All = CC4Group_AllowedEntryTypes_File | CC4Group_AllowedEntryTypes_Directory
+} CC4Group_AllowedEntryTypes;
+
struct list_GroupEntryList;
typedef struct C4GroupEntryData_t {
C4GroupEntryCore core;
@@ -3007,6 +3014,28 @@ static C4GroupEntryData* cc4group_createDirectory(CC4Group* const this, const ch
return entry;
}
+static bool cc4group_addFromDisk(CC4Group* const this, const char* const path, const char* const targetEntryPath, int const allowedEntryTypes)
+{
+ CC4Group_AllowedEntryTypes type = cc4group_isDirectory(path) ? CC4Group_AllowedEntryTypes_Directory : CC4Group_AllowedEntryTypes_File;
+ if(!(type & allowedEntryTypes))
+ {
+ SET_MESSAGE_ERROR("The specified path doesn't match the specified allowed entry type");
+ return false;
+ }
+
+ switch(type)
+ {
+ case CC4Group_AllowedEntryTypes_File:
+ return cc4group_addFileFromDisk(this, strdup(path), targetEntryPath, NULL) != NULL;
+ case CC4Group_AllowedEntryTypes_Directory:
+ return cc4group_addDirectoryFromDisk(this, strdup(path), targetEntryPath, NULL);
+ case CC4Group_AllowedEntryTypes_All:
+ assert(!"All is not a valid type determined for the path; This code should never be reached");
+ return false;
+ }
+
+ return false;
+}
static bool cc4group_createEmptyDirectory(CC4Group* const this, const char* const path)
{
@@ -3199,6 +3228,12 @@ static CC4Group_MemoryManagement_t referenceMemoryManagement = {
};
CC4Group_API cc4group = {
+ .AllowedEntryTypes = {
+ .File = CC4Group_AllowedEntryTypes_File,
+ .Directory = CC4Group_AllowedEntryTypes_Directory,
+ .All = CC4Group_AllowedEntryTypes_All
+ },
+
.MemoryManagement = {
.Take = &takeMemoryManagement,
.Copy = &copyMemoryManagement,
@@ -3253,6 +3288,7 @@ CC4Group_API cc4group = {
.setExecutable = cc4group_setExecutable,
+ .addFromDisk = cc4group_addFromDisk,
.createDirectory = cc4group_createEmptyDirectory,
.createFile = cc4group_createFile,
.renameEntry = cc4group_renameEntry,