2006-05-19 18:35:03 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2017-10-05 15:19:25 +02:00
|
|
|
/*
|
|
|
|
* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
2003-03-19 09:13:01 +00:00
|
|
|
*
|
|
|
|
* Now does proper error checking on output and returns a failure exit code
|
2006-10-20 13:28:22 +00:00
|
|
|
* if one or more paths cannot be resolved.
|
2006-05-19 18:35:03 +00:00
|
|
|
*
|
2010-08-16 20:14:46 +02:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2003-03-19 09:13:01 +00:00
|
|
|
*/
|
2016-11-23 14:46:56 +01:00
|
|
|
//config:config REALPATH
|
2018-12-28 03:20:17 +01:00
|
|
|
//config: bool "realpath (1.6 kb)"
|
2016-11-23 14:46:56 +01:00
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 09:50:55 +02:00
|
|
|
//config: Return the canonicalized absolute pathname.
|
|
|
|
//config: This isn't provided by GNU shellutils, but where else does it belong.
|
2016-11-23 14:46:56 +01:00
|
|
|
|
2017-08-03 19:00:01 +02:00
|
|
|
//applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath))
|
2016-11-23 14:46:56 +01:00
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_REALPATH) += realpath.o
|
|
|
|
|
|
|
|
/* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
|
2003-03-19 09:13:01 +00:00
|
|
|
|
2011-03-31 14:43:25 +02:00
|
|
|
//usage:#define realpath_trivial_usage
|
|
|
|
//usage: "FILE..."
|
|
|
|
//usage:#define realpath_full_usage "\n\n"
|
|
|
|
//usage: "Return the absolute pathnames of given FILE"
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2002-12-10 00:14:33 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int realpath_main(int argc UNUSED_PARAM, char **argv)
|
2002-12-10 00:14:33 +00:00
|
|
|
{
|
2003-03-19 09:13:01 +00:00
|
|
|
int retval = EXIT_SUCCESS;
|
|
|
|
|
2008-03-17 09:09:09 +00:00
|
|
|
if (!*++argv) {
|
2003-03-19 09:13:01 +00:00
|
|
|
bb_show_usage();
|
2002-12-10 00:14:33 +00:00
|
|
|
}
|
|
|
|
|
2002-12-10 03:16:37 +00:00
|
|
|
do {
|
2017-08-03 19:00:01 +02:00
|
|
|
/* NOFORK: only one alloc is allowed; must free */
|
2018-05-24 17:29:14 +02:00
|
|
|
char *resolved_path = xmalloc_realpath_coreutils(*argv);
|
2010-07-06 18:46:02 +02:00
|
|
|
if (resolved_path != NULL) {
|
2002-12-10 00:14:33 +00:00
|
|
|
puts(resolved_path);
|
2010-03-26 19:08:53 +01:00
|
|
|
free(resolved_path);
|
2002-12-10 00:14:33 +00:00
|
|
|
} else {
|
2003-03-19 09:13:01 +00:00
|
|
|
retval = EXIT_FAILURE;
|
2007-10-01 11:58:38 +00:00
|
|
|
bb_simple_perror_msg(*argv);
|
2002-12-10 00:14:33 +00:00
|
|
|
}
|
2008-03-17 09:09:09 +00:00
|
|
|
} while (*++argv);
|
2002-12-10 03:16:37 +00:00
|
|
|
|
2006-10-26 23:21:47 +00:00
|
|
|
fflush_stdout_and_exit(retval);
|
2002-12-10 03:16:37 +00:00
|
|
|
}
|