diff --git a/coreutils/cp.c b/coreutils/cp.c index 3da12b7..ab2ed61 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -81,8 +81,6 @@ int get_stat(const char *path, struct stat *stat_path) { } int cptree(const char *src, const char *dst) { - printf("%s %s\n", src, dst); - struct stat stat_path; get_stat(src, &stat_path); @@ -132,29 +130,16 @@ int cptree(const char *src, const char *dst) { } int main(const int argc, const char **argv) { - /* Recursion */ - unsigned int r_flag; - int i; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') break; - else if (!strcmp(argv[i], "-r")) - r_flag = 1; - else if (!strcmp(argv[i], "-h")) { - printf("cp [-r] [Src] [Dst]\n"); + printf("cp [Src] [Dst]\n"); return 0; } } - if (argc - i >= 2) { - if (r_flag) - return cptree(argv[i], argv[argc - 1]); - else - return copy(argv[i], argv[argc - 1]); - } - - return 0; + return cptree(argv[i], argv[argc - 1]); } diff --git a/coreutils/ls.c b/coreutils/ls.c index 34f6880..04428ad 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -13,7 +13,7 @@ int list(const char *path, int flag, int label) { } /* If its file */ - if (!S_ISDIR(statbuf.st_mode)) { + if (S_ISDIR(statbuf.st_mode) == 0) { puts(path); return 0; } diff --git a/coreutils/mv.c b/coreutils/mv.c index 9fcac85..bf44f57 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -12,9 +12,10 @@ int move(const char *src, const char *dst) { return 1; char *bname = basename(copy); + size_t len = strlen(dst) + strlen(bname) + 2; char *new_path = malloc(len + 1); - if (!new_path) + if (new_path == NULL) return 1; snprintf(new_path, len, "%s/%s", dst, bname); diff --git a/coreutils/rm.c b/coreutils/rm.c index cc5f539..40bbae9 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -22,7 +22,7 @@ int rmtree(const char *path) { if (S_ISDIR(stat_path.st_mode) == 0) { if (unlink(path) < 0) { fprintf(stderr, "rm: %s: is not directory\n", path); - return -1; + return 1; } return 0; @@ -31,7 +31,7 @@ int rmtree(const char *path) { DIR *dir = opendir(path); if (dir == NULL) { fprintf(stderr, "rm: %s: Can`t open directory\n", path); - return -1; + return 1; } struct dirent *ep; @@ -73,3 +73,4 @@ int main(const int argc, char **argv) { return 0; } +