micro-utils/coreutils/ln.c

57 lines
839 B
C
Raw Normal View History

#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 {
printf("ln [-s] [TARGET] [LINK/DIR]\n");
return 0;
}
}
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;
}