fixed rm, cp

This commit is contained in:
Your Name 2024-07-13 19:36:14 +03:00
parent 500bbb02ea
commit 2a90ce246c
2 changed files with 11 additions and 5 deletions

View File

@ -144,8 +144,6 @@ static int cptree(const char *src, const char *dst) {
free(src_path);
free(dst_path);
if (ret)
break;
}
closedir(dir);

View File

@ -12,10 +12,11 @@
static char *f_flag = "rm";
static char r_flag;
static char i_flag;
static char v_flag;
static int verbose(const char *path) {
if (v_flag) {
if (i_flag) {
fprintf(stderr, "rm: remove %s? [y/n] ", path);
fflush(stderr);
@ -30,6 +31,9 @@ static int verbose(const char *path) {
return key;
}
else if (v_flag && f_flag)
fprintf(stderr, "rm: removing %s\n", path);
return 1;
}
@ -62,7 +66,7 @@ static int rmd(const char *path, void *p) {
int main(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "frRi")) != -1) {
while ((opt = getopt(argc, argv, "friv")) != -1) {
switch (opt) {
case 'f':
f_flag = NULL;
@ -73,11 +77,15 @@ int main(int argc, char **argv) {
break;
case 'i':
i_flag = 1;
break;
case 'v':
v_flag = 1;
break;
default:
puts("rm [rif] [file1 file2...]\n\t-f Never prompt\n\t-r Recursive\n\t-i Print prompt before remove");
puts("rm [friv] [file1 file2/dir...]\n\t-f Never prompt\n\t-r Recursive\n\t-i Print prompt before remove\n\t-v Verbose");
return 0;
}
}