Mercurial > hg > toybox
comparison toys/posix/ln.c @ 1144:58daf9c9a0b1 draft
ln -v support from Ashwini Sharma (comment tweak from me)
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 18 Dec 2013 10:25:02 -0600 |
parents | 3d7526f6115b |
children | 0752b2d58909 |
comparison
equal
deleted
inserted
replaced
1143:2115856395e2 | 1144:58daf9c9a0b1 |
---|---|
2 * | 2 * |
3 * Copyright 2012 Andre Renaud <andre@bluewatersys.com> | 3 * Copyright 2012 Andre Renaud <andre@bluewatersys.com> |
4 * | 4 * |
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/ln.html | 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/ln.html |
6 | 6 |
7 USE_LN(NEWTOY(ln, "<1nfs", TOYFLAG_BIN)) | 7 USE_LN(NEWTOY(ln, "<1vnfs", TOYFLAG_BIN)) |
8 | 8 |
9 config LN | 9 config LN |
10 bool "ln" | 10 bool "ln" |
11 default y | 11 default y |
12 help | 12 help |
13 usage: ln [-sfn] [FROM...] TO | 13 usage: ln [-sfnv] [FROM...] TO |
14 | 14 |
15 Create a link between FROM and TO. | 15 Create a link between FROM and TO. |
16 With only one argument, create link in current directory. | 16 With only one argument, create link in current directory. |
17 | 17 |
18 -s Create a symbolic link | 18 -s Create a symbolic link |
19 -f Force the creation of the link, even if TO already exists | 19 -f Force the creation of the link, even if TO already exists |
20 -n Symlink at destination treated as file | 20 -n Symlink at destination treated as file |
21 -v Verbose | |
21 */ | 22 */ |
22 | 23 |
23 #define FOR_ln | 24 #define FOR_ln |
24 #include "toys.h" | 25 #include "toys.h" |
25 | 26 |
47 int rc; | 48 int rc; |
48 char *try = toys.optargs[i]; | 49 char *try = toys.optargs[i]; |
49 | 50 |
50 if (S_ISDIR(buf.st_mode)) new = xmsprintf("%s/%s", dest, basename(try)); | 51 if (S_ISDIR(buf.st_mode)) new = xmsprintf("%s/%s", dest, basename(try)); |
51 else new = dest; | 52 else new = dest; |
52 /* Silently unlink the existing target. If it doesn't exist, | 53 // Silently unlink the existing target (if any) |
53 * then we just move on */ | |
54 if (toys.optflags & FLAG_f) unlink(new); | 54 if (toys.optflags & FLAG_f) unlink(new); |
55 | 55 |
56 rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new); | 56 rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new); |
57 if (rc) | 57 if (rc) |
58 perror_exit("cannot create %s link from '%s' to '%s'", | 58 perror_exit("cannot create %s link from '%s' to '%s'", |
59 (toys.optflags & FLAG_s) ? "symbolic" : "hard", try, new); | 59 (toys.optflags & FLAG_s) ? "symbolic" : "hard", try, new); |
60 else if (toys.optflags & FLAG_v) | |
61 fprintf(stderr, "'%s' -> '%s'\n", new, try); | |
60 if (new != dest) free(new); | 62 if (new != dest) free(new); |
61 } | 63 } |
62 } | 64 } |