Bernhard Reutner-Fischer | c7801c4 | 2006-05-19 18:35:03 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denys Vlasenko | a02a4e9 | 2017-10-05 15:19:25 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 4 | * |
| 5 | * Now does proper error checking on output and returns a failure exit code |
Denis Vlasenko | e1a0d48 | 2006-10-20 13:28:22 +0000 | [diff] [blame] | 6 | * if one or more paths cannot be resolved. |
Bernhard Reutner-Fischer | c7801c4 | 2006-05-19 18:35:03 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 10 | //config:config REALPATH |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 11 | //config: bool "realpath (1.1 kb)" |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 12 | //config: default y |
| 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 14 | //config: Return the canonicalized absolute pathname. |
| 15 | //config: This isn't provided by GNU shellutils, but where else does it belong. |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 16 | |
Denys Vlasenko | 39194f0 | 2017-08-03 19:00:01 +0200 | [diff] [blame] | 17 | //applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath)) |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 18 | |
| 19 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o |
| 20 | |
| 21 | /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 22 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 23 | //usage:#define realpath_trivial_usage |
| 24 | //usage: "FILE..." |
| 25 | //usage:#define realpath_full_usage "\n\n" |
| 26 | //usage: "Return the absolute pathnames of given FILE" |
| 27 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 28 | #include "libbb.h" |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 29 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 30 | int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 31 | int realpath_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 32 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 33 | int retval = EXIT_SUCCESS; |
| 34 | |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 35 | if (!*++argv) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 36 | bb_show_usage(); |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 39 | do { |
Denys Vlasenko | 39194f0 | 2017-08-03 19:00:01 +0200 | [diff] [blame] | 40 | /* NOFORK: only one alloc is allowed; must free */ |
Denys Vlasenko | 7471621 | 2018-05-24 17:29:14 +0200 | [diff] [blame^] | 41 | char *resolved_path = xmalloc_realpath_coreutils(*argv); |
Denys Vlasenko | 8f65b0c | 2010-07-06 18:46:02 +0200 | [diff] [blame] | 42 | if (resolved_path != NULL) { |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 43 | puts(resolved_path); |
Jérémie Koenig | fbedacf | 2010-03-26 19:08:53 +0100 | [diff] [blame] | 44 | free(resolved_path); |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 45 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 46 | retval = EXIT_FAILURE; |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 47 | bb_simple_perror_msg(*argv); |
Glenn L McGrath | 62fae30 | 2002-12-10 00:14:33 +0000 | [diff] [blame] | 48 | } |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 49 | } while (*++argv); |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 50 | |
Denis Vlasenko | f0ed376 | 2006-10-26 23:21:47 +0000 | [diff] [blame] | 51 | fflush_stdout_and_exit(retval); |
Glenn L McGrath | 7b4e89b | 2002-12-10 03:16:37 +0000 | [diff] [blame] | 52 | } |