Fix recursion in rm
This commit is contained in:
parent
51b51a6eb1
commit
d840baba07
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user