diff --git a/coreutils/chroot.c b/coreutils/chroot.c index 7f3268e..791eb97 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -4,20 +4,22 @@ #include #include -int main(const int argc, const char **argv) { - if (argc < 3) { +int main(const int argc, char **argv) { + if (argc < 3 || !strcmp(argv[argc - 1], "-h")) { printf("chroot [dir] [\"command arg\"]\n"); return 0; } - if (chroot(argv[1]) == -1) { + if (chroot(argv[1]) < 0) { fprintf(stderr, "chroot: %s\n", strerror(errno)); return 1; } chdir("/"); - for (int i = 1; i < argc; i++) - system(argv[i]); + if (execvp(argv[2], argv) < 0) { + fprintf(stderr, "chroot: %s\n", strerror(errno)); + return 1; + } return 0; } diff --git a/coreutils/mv.c b/coreutils/mv.c index bf44f57..cd3f4c2 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -31,9 +31,9 @@ int move(const char *src, const char *dst) { } int main(const int argc, const char **argv) { - if (argc == 2) { - printf("mv: missing operand\n"); - return 1; + if (argc <= 2 || !strcmp(argv[argc - 1], "-h")) { + printf("mv [Src1 src2...] [Dst]\n"); + return 0; } for (int i = 1; i < argc - 1; i++) { diff --git a/coreutils/rm.c b/coreutils/rm.c index 35da044..44ac6f6 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -59,9 +59,9 @@ int rmtree(const char *path) { } int main(const int argc, char **argv) { - if (argc == 1) { - printf("rm: missing operand\n"); - return 1; + if (argc == 1 || !strcmp(argv[argc - 1], "-h")) { + printf("rm [src1 src2...]\n"); + return 0; } for (int i = 1; i < argc; i++) { diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 3fe2b30..96ad38f 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -13,8 +13,8 @@ double convert(const char *num) { } int main(const int argc, const char **argv) { - if (argc == 1) { - printf("sleep [num[m - minute / h - hour / d - days].. ] / [inf (infinity)]\n"); + if (argc == 1 || !strcmp(argv[argc - 1], "-h")) { + printf("sleep [num[m - minute / h - hour / d - days]] / [inf (infinity)]\n"); return 0; }