blob: 0c2d544e4ab0af2a373dec7c328879f143659d6c
1 | /* vi: set sw=4 ts=4: */ |
2 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
3 | * |
4 | * Now does proper error checking on output and returns a failure exit code |
5 | * if one or more paths cannot be resolved. |
6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ |
9 | //config:config REALPATH |
10 | //config: bool "realpath" |
11 | //config: default y |
12 | //config: help |
13 | //config: Return the canonicalized absolute pathname. |
14 | //config: This isn't provided by GNU shellutils, but where else does it belong. |
15 | |
16 | //applet:IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP)) |
17 | |
18 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o |
19 | |
20 | /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */ |
21 | |
22 | //usage:#define realpath_trivial_usage |
23 | //usage: "FILE..." |
24 | //usage:#define realpath_full_usage "\n\n" |
25 | //usage: "Return the absolute pathnames of given FILE" |
26 | |
27 | #include "libbb.h" |
28 | |
29 | int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
30 | int realpath_main(int argc UNUSED_PARAM, char **argv) |
31 | { |
32 | int retval = EXIT_SUCCESS; |
33 | |
34 | if (!*++argv) { |
35 | bb_show_usage(); |
36 | } |
37 | |
38 | do { |
39 | char *resolved_path = xmalloc_realpath(*argv); |
40 | if (resolved_path != NULL) { |
41 | puts(resolved_path); |
42 | free(resolved_path); |
43 | } else { |
44 | retval = EXIT_FAILURE; |
45 | bb_simple_perror_msg(*argv); |
46 | } |
47 | } while (*++argv); |
48 | |
49 | fflush_stdout_and_exit(retval); |
50 | } |
51 |