Fix exit() in library code, add --include/--max-size/--min-size

This commit is contained in:
2026-07-16 14:15:38 +02:00
parent 07207cd71d
commit bbdf027be8
27 changed files with 568 additions and 264 deletions
+8 -2
View File
@@ -8,10 +8,12 @@
#include <sys/stat.h>
#include <unistd.h>
void mkdir_r(char *path) {
bool mkdir_r(char *path) {
char *path_duplicate = malloc(strlen(path) + 1);
if (!path_duplicate) return false;
strcpy(path_duplicate, path);
char *path_current = (char *)malloc((strlen(path) + 2) * sizeof(char));
if (!path_current) { free(path_duplicate); return false; }
char *path_current_position = path_current;
if (path[0] == '/') {
strcpy(path_current, "/");
@@ -21,6 +23,7 @@ void mkdir_r(char *path) {
}
const char *delimiter = "/";
char *part = strtok(path_duplicate, delimiter);
bool ok = true;
while (part != NULL) {
strcpy(path_current_position, part);
path_current_position += strlen(part) * sizeof(char);
@@ -30,13 +33,15 @@ void mkdir_r(char *path) {
if (stat(path_current, &st) != 0) {
if (mkdir(path_current, 0755) != 0) {
perror("Could not create directory");
exit(EXIT_FAILURE);
ok = false;
break;
}
}
part = strtok(NULL, delimiter);
}
free(path_duplicate);
free(path_current);
return ok;
}
char *str_dup(const char *string) {
@@ -131,6 +136,7 @@ char *path_cat(char *path1, char *path2) {
path2_len -= 1;
}
char *new_path = malloc(path1_len + path2_len + 2);
if (new_path == NULL) return NULL;
memcpy(new_path, path1, path1_len);
new_path[path1_len] = '/';
memcpy(new_path + path1_len + 1, path2_pointer, path2_len);