From d71226540130699469abd351ef81b7b3c8ff4687 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Oct 2023 17:32:50 +0300 Subject: [PATCH] . --- coreutils/cp.c | 2 +- coreutils/ls.c | 15 +++++++++++---- coreutils/rm.c | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/coreutils/cp.c b/coreutils/cp.c index dafca31..b4daa95 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -129,7 +129,7 @@ int cptree(const char *src, const char *dst) { return 0; } -int main(const int argc, const char **argv) { +int main(const int argc, char **argv) { int i; for (i = 1; i < argc; i++) { diff --git a/coreutils/ls.c b/coreutils/ls.c index b355648..7db9303 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -33,8 +34,13 @@ int list(const char *path, int label) { if (label) printf("\n%s: \n", path); + if (chdir(path)) { + fprintf(stderr, "ls: %s: %s\n", path, strerror(errno)); + return 1; + } + /* Open and print dir */ - DIR *dp = opendir(path); + DIR *dp = opendir("."); if (dp == NULL) { fprintf(stderr, "ls: %s: %s\n", path, strerror(errno)); return 1; @@ -64,14 +70,15 @@ int list(const char *path, int label) { return 1; } - printf(" %jd %jd %s ", (uintmax_t)sb.st_mode, (uintmax_t)sb.st_size, date); + printf(" %jd %jd %s %s\n", (uintmax_t)sb.st_mode, (uintmax_t)sb.st_size, date, ep->d_name); } - printf("%s ", ep->d_name); - printf("\n"); + else + printf("%s ", ep->d_name); } closedir(dp); + printf("\n"); return 0; } diff --git a/coreutils/rm.c b/coreutils/rm.c index 40bbae9..2100754 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -66,6 +66,9 @@ int main(const int argc, char **argv) { } for (int i = 1; i < argc; i++) { + if (argv[i][0] == '-') + continue; + int status = rmtree(argv[i]); if (status != 0) return status;