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 * Bash loadable builtin version
22 Copyright (C) 1999-2009 Free Software Foundation, Inc.
24 This file is part of GNU Bash.
25 Bash 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 Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>.
41 #include <sys/types.h>
54 #include "bashgetopt.h"
61 extern char *sh_realpath();
63 realpath_builtin(list)
66 int opt, cflag, vflag, sflag, es;
67 char *r, realbuf[PATH_MAX], *p;
75 vflag = cflag = sflag = 0;
76 reset_internal_getopt();
77 while ((opt = internal_getopt (list, "csv")) != -1) {
98 for (es = EXECUTION_SUCCESS; list; list = list->next) {
100 r = sh_realpath(p, realbuf);
102 es = EXECUTION_FAILURE;
104 builtin_error("%s: cannot resolve: %s", p, strerror(errno));
107 if (cflag && (stat(realbuf, &sb) < 0)) {
108 es = EXECUTION_FAILURE;
110 builtin_error("%s: %s", p, strerror(errno));
115 printf ("%s -> ", p);
116 printf("%s\n", realbuf);
122 char *realpath_doc[] = {
123 "Display pathname in canonical form.",
125 "Display the canonicalized version of each PATHNAME argument, resolving",
126 "symbolic links. The -c option checks whether or not each resolved name",
127 "exists. The -s option produces no output; the exit status determines the",
128 "valididty of each PATHNAME. The -v option produces verbose output. The",
129 "exit status is 0 if each PATHNAME was resolved; non-zero otherwise.",
133 struct builtin realpath_struct = {
134 "realpath", /* builtin name */
135 realpath_builtin, /* function implementing the builtin */
136 BUILTIN_ENABLED, /* initial flags for builtin */
137 realpath_doc, /* array of long documentation strings */
138 "realpath [-csv] pathname [pathname...]", /* usage synopsis */
139 0 /* reserved for internal use */