43 lines
683 B
C
43 lines
683 B
C
#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 if (!strcmp("--help", argv[i])) {
|
|
printf("ln [-s] [TARGET] [LINK/DIR]\n");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
if (argc - i == 2) {
|
|
if (single_link(argv[i], argv[i + 1])) {
|
|
fprintf(stderr, "ln: %s %s\n", argv[i], strerror(errno));
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|