This commit is contained in:
Your Name 2023-11-02 19:49:59 +03:00
parent 81d1c15e59
commit e61dc1ffaa
2 changed files with 22 additions and 7 deletions

2
TODO
View File

@ -10,12 +10,10 @@ cal
nice
renice
nohup
chmod
split
truncate
date
tee
ln
tr
cut
shuf

View File

@ -2,11 +2,16 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "make_path.h"
/* Symbolic */
unsigned int s_flag;
unsigned int f_flag;
int ln(const char *src, const char *dst) {
if (f_flag)
unlink(dst);
int single_link(const char *src, const char *dst) {
if (s_flag)
return symlink(src, dst);
@ -24,17 +29,29 @@ int main(const int argc, const char **argv) {
else if (!strcmp("-s", argv[i]))
s_flag = 1;
else if (!strcmp("-f", argv[i]))
f_flag = 1;
else if (!strcmp("--help", argv[i])) {
printf("ln [-s] [TARGET] [LINK/DIR]\n");
printf("ln [-f force] [-s symbolic] [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;
if (ln(argv[i], argv[i + 1])) {
char *new_path = mu_make_path("ln", argv[i + 1], argv[i]);
if (new_path == NULL)
return 1;
if (ln(argv[i], new_path)) {
free(new_path);
fprintf(stderr, "ln: %s %s\n", argv[i], strerror(errno));
return 1;
}
free(new_path);
}
}