Fix recursion in rm

This commit is contained in:
Your Name 2023-10-20 18:45:10 +03:00
parent 51b51a6eb1
commit d840baba07
3 changed files with 3 additions and 3 deletions

View File

@ -88,7 +88,7 @@ int cptree(const char *src, const char *dst) {
if (get_stat(src, &stat_path))
return 1;
if (S_ISDIR(stat_path.st_mode) == 0) {
if (!S_ISDIR(stat_path.st_mode)) {
if (copy(src, dst)) {
fprintf(stderr, "cp: %s: copy() failed (%s)\n", src, strerror(errno));
return 1;

View File

@ -44,7 +44,7 @@ int main(const int argc, const char **argv) {
flag = 1;
else if (!strcmp(argv[i], "-h")) {
printf("mkdir [-p (make parent dir)] [dir1 dir2...]");
printf("mkdir [-p (make parent dir)] [dir1 dir2...]\n");
return 0;
}
}

View File

@ -41,7 +41,7 @@ int rmtree(const char *path) {
continue;
size_t len = strlen(path) + strlen(ep->d_name) + 2;
char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1);
char *full_path = malloc(len + 1);
if (full_path == NULL) {
fprintf(stderr, "rm: malloc() returned NULL\n");
return 1;