Added CONFIG_CLEAR and CONFIG_RESET to config.maemo
[busybox4maemo] / coreutils / realpath.c
1 /* vi: set sw=4 ts=4: */
2
3 /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
4
5 /* Mar 16, 2003      Manuel Novoa III   (mjn3@codepoet.org)
6  *
7  * Now does proper error checking on output and returns a failure exit code
8  * if one or more paths cannot be resolved.
9  *
10  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11  */
12
13 #include "libbb.h"
14
15 int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int realpath_main(int argc ATTRIBUTE_UNUSED, char **argv)
17 {
18         int retval = EXIT_SUCCESS;
19
20 #if PATH_MAX > (BUFSIZ+1)
21         RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
22 # define resolved_path_MUST_FREE 1
23 #else
24 #define resolved_path bb_common_bufsiz1
25 # define resolved_path_MUST_FREE 0
26 #endif
27
28         if (!*++argv) {
29                 bb_show_usage();
30         }
31
32         do {
33                 if (realpath(*argv, resolved_path) != NULL) {
34                         puts(resolved_path);
35                 } else {
36                         retval = EXIT_FAILURE;
37                         bb_simple_perror_msg(*argv);
38                 }
39         } while (*++argv);
40
41 #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
42         RELEASE_CONFIG_BUFFER(resolved_path);
43 #endif
44
45         fflush_stdout_and_exit(retval);
46 }