This commit is contained in:
Your Name 2023-10-22 09:22:12 +03:00
parent 671e4430be
commit 28c02fbae1
4 changed files with 15 additions and 13 deletions

View File

@ -4,20 +4,22 @@
#include <string.h>
#include <errno.h>
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;
}

View File

@ -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++) {

View File

@ -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++) {

View File

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