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 nice
renice renice
nohup nohup
chmod
split split
truncate truncate
date date
tee tee
ln
tr tr
cut cut
shuf shuf

View File

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