This commit is contained in:
Your Name 2023-10-16 20:57:30 +03:00
parent c8d3fe0c97
commit 20f7eefb3e
4 changed files with 8 additions and 21 deletions

View File

@ -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]);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}