blob: 993fa1c9d47d6cf14a02d5c9c4f349ead62d5461 [file] [log] [blame]
Bernhard Reutner-Fischerc7801c42006-05-19 18:35:03 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath62fae302002-12-10 00:14:33 +00002
Manuel Novoa III cad53642003-03-19 09:13:01 +00003/* 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-Fischerc7801c42006-05-19 18:35:03 +00009 *
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Manuel Novoa III cad53642003-03-19 09:13:01 +000011 */
12
Glenn L McGrath62fae302002-12-10 00:14:33 +000013#include <limits.h>
14#include <stdlib.h>
Glenn L McGrath62fae302002-12-10 00:14:33 +000015#include "busybox.h"
16
17int realpath_main(int argc, char **argv)
18{
Manuel Novoa III cad53642003-03-19 09:13:01 +000019 int retval = EXIT_SUCCESS;
20
"Vladimir N. Oleynik"a2eec602005-10-15 13:45:32 +000021#if PATH_MAX > (BUFSIZ+1)
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000022 RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
"Vladimir N. Oleynik"a2eec602005-10-15 13:45:32 +000023# 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 McGrath62fae302002-12-10 00:14:33 +000028
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000029 if (--argc == 0) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000030 bb_show_usage();
Glenn L McGrath62fae302002-12-10 00:14:33 +000031 }
32
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000033 do {
34 argv++;
35 if (realpath(*argv, resolved_path) != NULL) {
Glenn L McGrath62fae302002-12-10 00:14:33 +000036 puts(resolved_path);
37 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +000038 retval = EXIT_FAILURE;
39 bb_perror_msg("%s", *argv);
Glenn L McGrath62fae302002-12-10 00:14:33 +000040 }
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000041 } while (--argc);
42
"Vladimir N. Oleynik"a2eec602005-10-15 13:45:32 +000043#if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000044 RELEASE_CONFIG_BUFFER(resolved_path);
Manuel Novoa III cad53642003-03-19 09:13:01 +000045#endif
Glenn L McGrath62fae302002-12-10 00:14:33 +000046
Manuel Novoa III cad53642003-03-19 09:13:01 +000047 bb_fflush_stdout_and_exit(retval);
Glenn L McGrath7b4e89b2002-12-10 03:16:37 +000048}