2023-10-11 19:46:57 +03:00
|
|
|
#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 {
|
2023-10-12 22:11:52 +03:00
|
|
|
printf("ln [-s] [TARGET] [LINK/DIR]\n");
|
|
|
|
return 0;
|
2023-10-11 19:46:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|