Загрузить файлы в «src»

This commit is contained in:
8nlight 2023-10-11 19:46:57 +03:00
parent 1fcf263f22
commit 6a64fa8d99
2 changed files with 63 additions and 5 deletions

View File

@ -1,18 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main(const int argc, const char **argv) {
if (argc <= 2) {
fprintf(stderr, "chroot: missing operand\n");
fprintf(stderr, "chroot [dir] [\"command arg\"]\n");
return 1;
}
chroot(argv[1]);
chdir("/");
if (chroot(argv[1]) == -1) {
fprintf(stderr, "chroot: %s\n", strerror(errno));
return 1;
}
chdir("/");
for (int i = 2; i < argc; i++)
system(argv[i]);
}

56
src/ln.c Normal file
View File

@ -0,0 +1,56 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
/* Symbolic */
unsigned int s_flag;
int single_link(const char *src, const char *dst) {
if (s_flag)
return symlink(src, dst);
else
return link(src, dst);
}
int main(const int argc, const char **argv) {
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
else if (!strcmp("-s", argv[i]))
s_flag = 1;
else {
fprintf(stderr, "ln: invalid argument: %s\n", argv[i]);
return 1;
}
}
switch (argc - i) {
case 0:
fprintf(stderr, "ln: missing operand\n");
return 1;
case 1:
fprintf(stderr, "ln: missing destination\n");
return 1;
case 2:
if (single_link(argv[i], argv[i + 1])) {
fprintf(stderr, "ln: %s %s\n", argv[i], strerror(errno));
return 1;
}
break;
default:
break;
}
return 0;
}