summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cc4group.c74
1 files changed, 66 insertions, 8 deletions
diff --git a/src/cc4group.c b/src/cc4group.c
index 9415dd1..56d307a 100644
--- a/src/cc4group.c
+++ b/src/cc4group.c
@@ -124,7 +124,7 @@ static void cc4group_applyMemoryManagementEnd(CC4Group_MemoryManagement const ma
}
static const uint8_t* cc4group_getOnlyEntryData(CC4Group* const this, const C4GroupEntryData* entry);
-static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const this, const char* const entryPath);
+static const C4GroupEntryData* cc4group_getEntryByPath(CC4Group* const this, const char* const entryPath, bool* error);
static const C4GroupEntryData* cc4group_getDirectoryByPath(CC4Group* const this, const char* const entryPath);
static const C4GroupEntryData* cc4group_getFileByPath(CC4Group* const this, const char* const entryPath);
static const C4GroupEntryData* cc4group_getFileOrDirectoryByPath(CC4Group* const this, const char* const entryPath);
@@ -1222,8 +1222,8 @@ static bool cc4group_extractAll(CC4Group* const this, const char* const targetPa
}
-// does not set any error
-static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const this, const char* const entryPath)
+// sets *error to true if any error is set
+static const C4GroupEntryData* cc4group_getEntryByPath(CC4Group* const this, const char* const entryPath, bool* error)
{
assert(this);
assert(this->root.children);
@@ -1237,6 +1237,13 @@ static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const thi
const C4GroupEntryData* currentParent = &this->root;
char* path = strdup(entryPath);
+ if(path == NULL)
+ {
+ *error = true;
+ SET_ERRNO_ERROR("strdup: duplicating the path");
+ return NULL;
+ }
+
for(char* tokenIn = path, *savePtr; ; tokenIn = NULL)
{
const char* part = strtok_r(tokenIn, "/", &savePtr);
@@ -1279,7 +1286,13 @@ static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const thi
static const C4GroupEntryData* cc4group_getDirectoryByPath(CC4Group* const this, const char* const entryPath)
{
// asserts are in cc4group_getEntryByPath
- const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath);
+ bool error = false;
+ const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath, &error);
+ if(error)
+ {
+ return NULL;
+ }
+
if(entry == NULL)
{
SET_MESSAGE_ERROR("The dirctory was not found in the group file");
@@ -1299,7 +1312,13 @@ static const C4GroupEntryData* cc4group_getDirectoryByPath(CC4Group* const this,
static const C4GroupEntryData* cc4group_getFileByPath(CC4Group* const this, const char* const entryPath)
{
// asserts are in cc4group_getEntryByPath
- const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath);
+ bool error = false;
+ const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath, &error);
+ if(error)
+ {
+ return NULL;
+ }
+
if(entry == NULL)
{
SET_MESSAGE_ERROR("The file was not found in the group file");
@@ -1319,7 +1338,13 @@ static const C4GroupEntryData* cc4group_getFileByPath(CC4Group* const this, cons
static const C4GroupEntryData* cc4group_getFileOrDirectoryByPath(CC4Group* const this, const char* const entryPath)
{
// asserts are in cc4group_getEntryByPath
- const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath);
+ bool error = false;
+ const C4GroupEntryData* entry = cc4group_getEntryByPath(this, entryPath, &error);
+ if(error)
+ {
+ return false;
+ }
+
if(entry == NULL)
{
SET_MESSAGE_ERROR("The file or directory was not found in the group file");
@@ -1699,6 +1724,13 @@ static bool cc4group_getParentAndChildEntries(CC4Group* const this, const char*
const C4GroupEntryData* parent;
char* myPath = strdup(path);
+
+ if(myPath == NULL)
+ {
+ SET_ERRNO_ERROR("strdup: duplicating the path");
+ return false;
+ }
+
const char* parentPath;
char* entryName = cc4group_splitParentAndChildPaths(myPath, &parentPath);
@@ -1781,12 +1813,18 @@ static bool cc4group_renameEntry(CC4Group* const this, const char* const oldPath
assert(oldPath);
assert(newPath);
- if(cc4group_getEntryByPath(this, newPath) != NULL)
+ bool error = false;
+ if(cc4group_getEntryByPath(this, newPath, &error) != NULL)
{
SET_MESSAGE_ERROR("The desired target path already exists");
return false;
}
+ if(error)
+ {
+ return false;
+ }
+
const C4GroupEntryData* oldParent;
GroupEntryListEntry* entry = NULL;
@@ -1796,6 +1834,13 @@ static bool cc4group_renameEntry(CC4Group* const this, const char* const oldPath
}
char* targetPath = strdup(newPath);
+
+ if(targetPath == NULL)
+ {
+ SET_ERRNO_ERROR("strdup: duplicating the new path");
+ return false;
+ }
+
const char* targetDirectory;
char* targetName = cc4group_splitParentAndChildPaths(targetPath, &targetDirectory);
@@ -1816,13 +1861,26 @@ static bool cc4group_renameEntry(CC4Group* const this, const char* const oldPath
static C4GroupEntryData* cc4group_createEntry(CC4Group* const this, const char* const path)
{
- if(cc4group_getEntryByPath(this, path) != NULL)
+ bool error = false;
+ if(cc4group_getEntryByPath(this, path, &error) != NULL)
{
SET_MESSAGE_ERROR("The desired target path already exists");
return NULL;
}
+ if(error)
+ {
+ return false;
+ }
+
char* targetPath = strdup(path);
+
+ if(targetPath == NULL)
+ {
+ SET_ERRNO_ERROR("strdup: duplicating the path");
+ return NULL;
+ }
+
const char* targetDirectory;
char* targetName = cc4group_splitParentAndChildPaths(targetPath, &targetDirectory);