1 /* readlink.c - Return string representation of a symbolic link. 2 * 3 * Copyright 2007 Rob Landley <rob@landley.net> 4 5 USE_READLINK(NEWTOY(readlink, "<1>1fenq[-fe]", TOYFLAG_USR|TOYFLAG_BIN)) 6 7 config READLINK 8 bool "readlink" 9 default y 10 help 11 usage: readlink FILE 12 13 With no options, show what symlink points to, return error if not symlink. 14 15 Options for producing cannonical paths (all symlinks/./.. resolved): 16 17 -e cannonical path to existing entry (fail if missing) 18 -f full path (fail if directory missing) 19 -n no trailing newline 20 -q quiet (no output, just error code) 21 */ 22 23 #define FOR_readlink 24 #include "toys.h" 25 readlink_main(void)26void readlink_main(void) 27 { 28 char *s; 29 30 // Calculating full cannonical path? 31 32 if (toys.optflags & (FLAG_f|FLAG_e)) 33 s = xabspath(*toys.optargs, toys.optflags & FLAG_e); 34 else s = xreadlink(*toys.optargs); 35 36 if (s) { 37 if (!(toys.optflags & FLAG_q)) 38 xprintf((toys.optflags & FLAG_n) ? "%s" : "%s\n", s); 39 if (CFG_TOYBOX_FREE) free(s); 40 } else toys.exitval = 1; 41 } 42