Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/readlink.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 1063 byte(s)
-updated to busybox-1.13.4
1 niro 816 /* vi: set sw=4 ts=4: */
2     /*
3     * Mini readlink implementation for busybox
4     *
5     * Copyright (C) 2000,2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
6     *
7     * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
8     */
9    
10     #include "libbb.h"
11    
12     int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
13     int readlink_main(int argc UNUSED_PARAM, char **argv)
14     {
15     char *buf;
16     char *fname;
17     char pathbuf[PATH_MAX];
18    
19     USE_FEATURE_READLINK_FOLLOW(
20     unsigned opt;
21     /* We need exactly one non-option argument. */
22     opt_complementary = "=1";
23     opt = getopt32(argv, "f");
24     fname = argv[optind];
25     )
26     SKIP_FEATURE_READLINK_FOLLOW(
27     const unsigned opt = 0;
28     if (argc != 2) bb_show_usage();
29     fname = argv[1];
30     )
31    
32     /* compat: coreutils readlink reports errors silently via exit code */
33     logmode = LOGMODE_NONE;
34    
35     if (opt) {
36     buf = realpath(fname, pathbuf);
37     } else {
38     buf = xmalloc_readlink_or_warn(fname);
39     }
40    
41     if (!buf)
42     return EXIT_FAILURE;
43     puts(buf);
44    
45     if (ENABLE_FEATURE_CLEAN_UP && !opt)
46     free(buf);
47    
48     fflush_stdout_and_exit(EXIT_SUCCESS);
49     }