util-linux/lsusb.c: print manufacturer/product strings if available
[busybox-git.git] / coreutils / realpath.c
blob22820a7894babd12fceda3d117236a5987acdf3a
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
5 * Now does proper error checking on output and returns a failure exit code
6 * if one or more paths cannot be resolved.
8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 */
10 //config:config REALPATH
11 //config: bool "realpath (2.5 kb)"
12 //config: default y
13 //config: help
14 //config: Return the canonicalized absolute pathname.
15 //config: This isn't provided by GNU shellutils, but where else does it belong.
17 //applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath))
19 //kbuild:lib-$(CONFIG_REALPATH) += realpath.o
21 /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
23 //usage:#define realpath_trivial_usage
24 //usage: "FILE..."
25 //usage:#define realpath_full_usage "\n\n"
26 //usage: "Print absolute pathnames of FILEs"
28 #include "libbb.h"
30 int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
31 int realpath_main(int argc UNUSED_PARAM, char **argv)
33 int retval = EXIT_SUCCESS;
35 if (!*++argv) {
36 bb_show_usage();
39 do {
40 /* NOFORK: only one alloc is allowed; must free */
41 char *resolved_path = xmalloc_realpath_coreutils(*argv);
42 if (resolved_path != NULL) {
43 puts(resolved_path);
44 free(resolved_path);
45 } else {
46 retval = EXIT_FAILURE;
47 bb_simple_perror_msg(*argv);
49 } while (*++argv);
51 fflush_stdout_and_exit(retval);