Bernhard Reutner-Fischer | c7801c4 | 2006-05-19 18:35:03 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 2 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 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 can not be resolved. |
Bernhard Reutner-Fischer | c7801c4 | 2006-05-19 18:35:03 +0000 | [diff] [blame] | 9 | * |
| 10 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 13 | #include <limits.h> |
| 14 | #include <stdlib.h> |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 15 | #include "busybox.h" |
| 16 | |
| 17 | int realpath_main(int argc, char **argv) |
| 18 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 19 | int retval = EXIT_SUCCESS; |
| 20 | |
"Vladimir N. Oleynik" | a2eec60 | 2005-10-15 13:45:32 +0000 | [diff] [blame] | 21 | #if PATH_MAX > (BUFSIZ+1) |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 22 | RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX); |
"Vladimir N. Oleynik" | a2eec60 | 2005-10-15 13:45:32 +0000 | [diff] [blame] | 23 | # define resolved_path_MUST_FREE 1 |
| 24 | #else |
| 25 | #define resolved_path bb_common_bufsiz1 |
| 26 | # define resolved_path_MUST_FREE 0 |
| 27 | #endif |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 28 | |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 29 | if (--argc == 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 30 | bb_show_usage(); |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 33 | do { |
| 34 | argv++; |
| 35 | if (realpath(*argv, resolved_path) != NULL) { |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 36 | puts(resolved_path); |
| 37 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 38 | retval = EXIT_FAILURE; |
| 39 | bb_perror_msg("%s", *argv); |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 40 | } |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 41 | } while (--argc); |
| 42 | |
"Vladimir N. Oleynik" | a2eec60 | 2005-10-15 13:45:32 +0000 | [diff] [blame] | 43 | #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 44 | RELEASE_CONFIG_BUFFER(resolved_path); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 45 | #endif |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 46 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 47 | bb_fflush_stdout_and_exit(retval); |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 48 | } |