Mercurial > hg > toybox
comparison toys/other/readlink.c @ 708:50d759f8b371
Remove readlink -m for being poorly defined ("readlink -m /dev/null/and/more" answers what question, exactly?), rewrite xabspath() to work right and not depend on realpath, fix subtle longstanding bug in llist_traverse().
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 22 Nov 2012 21:18:09 -0600 |
parents | 977e19296b3f |
children | 0027cfa330da |
comparison
equal
deleted
inserted
replaced
707:977e19296b3f | 708:50d759f8b371 |
---|---|
1 /* readlink.c - Return string representation of a symbolic link. | 1 /* readlink.c - Return string representation of a symbolic link. |
2 * | 2 * |
3 * Copyright 2007 Rob Landley <rob@landley.net> | 3 * Copyright 2007 Rob Landley <rob@landley.net> |
4 | 4 |
5 USE_READLINK(NEWTOY(readlink, "<1>1femnq[-fem]", TOYFLAG_BIN)) | 5 USE_READLINK(NEWTOY(readlink, "<1>1fenq[-fe]", TOYFLAG_BIN)) |
6 | 6 |
7 config READLINK | 7 config READLINK |
8 bool "readlink" | 8 bool "readlink" |
9 default n | 9 default n |
10 help | 10 help |
12 | 12 |
13 With no options, show what symlink points to, return error if not symlink. | 13 With no options, show what symlink points to, return error if not symlink. |
14 | 14 |
15 Options for producing cannonical paths (all symlinks/./.. resolved): | 15 Options for producing cannonical paths (all symlinks/./.. resolved): |
16 | 16 |
17 -e cannonical path to existing file (fail if does not exist) | 17 -e cannonical path to existing entry (fail if nothing there) |
18 -f cannonical path to creatable file (fail if directory does not exist) | 18 -f full path (fail if location does not exist) |
19 -m cannonical path | |
20 -n no trailing newline | 19 -n no trailing newline |
21 -q quiet (no output, just error code) | 20 -q quiet (no output, just error code) |
22 */ | 21 */ |
23 | 22 |
24 #define FOR_readlink | 23 #define FOR_readlink |
28 { | 27 { |
29 char *s; | 28 char *s; |
30 | 29 |
31 // Calculating full cannonical path? | 30 // Calculating full cannonical path? |
32 | 31 |
33 if (toys.optflags & (FLAG_f|FLAG_e|FLAG_m)) { | 32 if (toys.optflags & (FLAG_f|FLAG_e)) |
34 unsigned u = 0; | 33 s = xabspath(*toys.optargs, toys.optflags & FLAG_e); |
35 | 34 else s = xreadlink(*toys.optargs); |
36 if (toys.optflags & FLAG_f) u++; | |
37 if (toys.optflags & FLAG_m) u=999999999; | |
38 | |
39 s = xabspath(*toys.optargs, u); | |
40 } else s = xreadlink(*toys.optargs); | |
41 | 35 |
42 if (s) { | 36 if (s) { |
43 if (!(toys.optflags & FLAG_q)) | 37 if (!(toys.optflags & FLAG_q)) |
44 xprintf((toys.optflags & FLAG_n) ? "%s" : "%s\n", s); | 38 xprintf((toys.optflags & FLAG_n) ? "%s" : "%s\n", s); |
45 if (CFG_TOYBOX_FREE) free(s); | 39 if (CFG_TOYBOX_FREE) free(s); |