2 * realpath -- canonicalize pathnames, resolving symlinks
4 * usage: realpath [-csv] pathname [pathname...]
6 * options: -c check whether or not each resolved path exists
7 * -s no output, exit status determines whether path is valid
8 * -v produce verbose output
11 * exit status: 0 if all pathnames resolved
12 * 1 if any of the pathname arguments could not be resolved
15 * Bush loadable builtin version
22 Copyright (C) 1999-2009 Free Software Foundation, Inc.
24 This file is part of GNU Bush.
25 Bush is free software: you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
27 the Free Software Foundation, either version 3 of the License, or
28 (at your option) any later version.
30 Bush is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU General Public License for more details.
35 You should have received a copy of the GNU General Public License
36 along with Bush. If not, see <http://www.gnu.org/licenses/>.
41 #include <sys/types.h>
54 #include "bushgetopt.h"
61 extern char *sh_realpath();
64 realpath_builtin(list
)
67 int opt
, cflag
, vflag
, sflag
, es
;
68 char *r
, realbuf
[PATH_MAX
], *p
;
76 vflag
= cflag
= sflag
= 0;
77 reset_internal_getopt();
78 while ((opt
= internal_getopt (list
, "csv")) != -1) {
103 for (es
= EXECUTION_SUCCESS
; list
; list
= list
->next
) {
104 p
= list
->word
->word
;
105 r
= sh_realpath(p
, realbuf
);
107 es
= EXECUTION_FAILURE
;
109 builtin_error("%s: cannot resolve: %s", p
, strerror(errno
));
112 if (cflag
&& (stat(realbuf
, &sb
) < 0)) {
113 es
= EXECUTION_FAILURE
;
115 builtin_error("%s: %s", p
, strerror(errno
));
120 printf ("%s -> ", p
);
121 printf("%s\n", realbuf
);
127 char *realpath_doc
[] = {
128 "Display pathname in canonical form.",
130 "Display the canonicalized version of each PATHNAME argument, resolving",
131 "symbolic links. The -c option checks whether or not each resolved name",
132 "exists. The -s option produces no output; the exit status determines the",
133 "validity of each PATHNAME. The -v option produces verbose output. The",
134 "exit status is 0 if each PATHNAME was resolved; non-zero otherwise.",
138 struct builtin realpath_struct
= {
139 "realpath", /* builtin name */
140 realpath_builtin
, /* function implementing the builtin */
141 BUILTIN_ENABLED
, /* initial flags for builtin */
142 realpath_doc
, /* array of long documentation strings */
143 "realpath [-csv] pathname [pathname...]", /* usage synopsis */
144 0 /* reserved for internal use */