This commit is contained in:
Your Name 2023-10-16 20:29:24 +03:00
parent b5819fbc96
commit b917633313
1 changed files with 2 additions and 1 deletions

View File

@ -39,13 +39,14 @@ int rmtree(const char *path) {
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
continue;
size_t len = strlen(path) + strlen(ep->d_name) + 2;
char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1);
if (full_path == NULL) {
fprintf(stderr, "rm: malloc() returned NULL\n");
return 1;
}
sprintf(full_path, "%s/%s", path, ep->d_name);
snprintf(full_path, len, "%s/%s", path, ep->d_name);
rmtree(full_path);
free(full_path);