Загрузить файлы в «src»
This commit is contained in:
parent
347f371ade
commit
cafbdc3ea6
4
src/ln.c
4
src/ln.c
@ -25,8 +25,8 @@ int main(const int argc, const char **argv) {
|
||||
s_flag = 1;
|
||||
|
||||
else {
|
||||
fprintf(stderr, "ln: invalid argument: %s\n", argv[i]);
|
||||
return 1;
|
||||
printf("ln [-s] [TARGET] [LINK/DIR]\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
81
src/mknod.c
Normal file
81
src/mknod.c
Normal file
@ -0,0 +1,81 @@
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned int parse_int(const char *str) {
|
||||
char *ptr = NULL;
|
||||
unsigned int value = (unsigned int)strtol(str, &ptr, 10);
|
||||
|
||||
if (*ptr) {
|
||||
fprintf(stderr, "mknod: not a number: %s\n", str);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
else if (value < 1) {
|
||||
fprintf(stderr, "mknod: number is negative: %s\n", str);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
int main(const int argc, const char **argv) {
|
||||
mode_t mode = 0666;
|
||||
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-')
|
||||
break;
|
||||
|
||||
else if (!strncmp("-m=", argv[i], 3)) {
|
||||
char *ptr = NULL;
|
||||
mode = (mode_t)strtol(argv[i] + 3, &ptr, 8);
|
||||
if (*ptr) {
|
||||
fprintf(stderr, "mknod: invalid mode %s\n", argv[i] + 3);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int major = 0;
|
||||
unsigned int minor = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (argc - i >= 2 && argc - i != 3) {
|
||||
if (argc - i == 4) {
|
||||
major = parse_int(argv[i + 2]);
|
||||
minor = parse_int(argv[i + 3]);
|
||||
dev = makedev(major, minor);
|
||||
}
|
||||
|
||||
|
||||
if (!strncmp("b", argv[i + 1], 1))
|
||||
mode |= S_IFBLK;
|
||||
|
||||
else if (!strncmp("c", argv[i + 1], 1) || !strncmp("u", argv[i + 1], 1))
|
||||
mode |= S_IFCHR;
|
||||
|
||||
else if (!strncmp("p", argv[i + 1], 1))
|
||||
mode |= S_IFIFO;
|
||||
|
||||
else if (!strncmp("s", argv[i + 1], 1))
|
||||
mode |= S_IFSOCK;
|
||||
|
||||
if (mknod(argv[i], mode, dev) < 0) {
|
||||
fprintf(stderr, "mknod: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
printf("mknod [-m=mode] [NAME] [TYPE] [MAJOR MINOR]\n");
|
||||
printf("Types:\n b - block deviece\n c or u - character device\n p - named pipe (MAJOR MINOR must be omitted)\n s - socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user