Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/readlink.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/readlink.c
r1765 r2725 5 5 * Copyright (C) 2000,2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> 6 6 * 7 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 */ 9 #include "libbb.h" 10 11 /* 12 * # readlink --version 13 * readlink (GNU coreutils) 6.10 14 * # readlink --help 15 * -f, --canonicalize 16 * canonicalize by following every symlink in 17 * every component of the given name recursively; 18 * all but the last component must exist 19 * -e, --canonicalize-existing 20 * canonicalize by following every symlink in 21 * every component of the given name recursively, 22 * all components must exist 23 * -m, --canonicalize-missing 24 * canonicalize by following every symlink in 25 * every component of the given name recursively, 26 * without requirements on components existence 27 * -n, --no-newline do not output the trailing newline 28 * -q, --quiet, -s, --silent suppress most error messages 29 * -v, --verbose report error messages 30 * 31 * bbox supports: -f -n -v (fully), -q -s (accepts but ignores) 8 32 */ 9 33 10 #include <getopt.h> 11 12 #include "libbb.h" 13 14 int readlink_main(int argc, char **argv); 15 int readlink_main(int argc, char **argv) 34 int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 35 int readlink_main(int argc UNUSED_PARAM, char **argv) 16 36 { 17 37 char *buf; 18 38 char *fname; 19 39 20 USE_FEATURE_READLINK_FOLLOW(40 IF_FEATURE_READLINK_FOLLOW( 21 41 unsigned opt; 22 42 /* We need exactly one non-option argument. */ 23 43 opt_complementary = "=1"; 24 opt = getopt32(argv, "f ");44 opt = getopt32(argv, "fnvsq"); 25 45 fname = argv[optind]; 26 46 ) 27 SKIP_FEATURE_READLINK_FOLLOW(47 IF_NOT_FEATURE_READLINK_FOLLOW( 28 48 const unsigned opt = 0; 29 49 if (argc != 2) bb_show_usage(); … … 32 52 33 53 /* compat: coreutils readlink reports errors silently via exit code */ 34 logmode = LOGMODE_NONE; 54 if (!(opt & 4)) /* not -v */ 55 logmode = LOGMODE_NONE; 35 56 36 if (opt ) {37 buf = realpath(fname, bb_common_bufsiz1);57 if (opt & 1) { /* -f */ 58 buf = xmalloc_realpath(fname); 38 59 } else { 39 60 buf = xmalloc_readlink_or_warn(fname); … … 42 63 if (!buf) 43 64 return EXIT_FAILURE; 44 p uts(buf);65 printf((opt & 2) ? "%s" : "%s\n", buf); 45 66 46 if (ENABLE_FEATURE_CLEAN_UP && !opt)67 if (ENABLE_FEATURE_CLEAN_UP) 47 68 free(buf); 48 69
Note:
See TracChangeset
for help on using the changeset viewer.