summaryrefslogtreecommitdiff
path: root/openbsd-compat/realpath.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/realpath.c')
-rw-r--r--openbsd-compat/realpath.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c
index 77da14e7c..b9035ca22 100644
--- a/openbsd-compat/realpath.c
+++ b/openbsd-compat/realpath.c
@@ -13,9 +13,6 @@
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 * 16 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -35,7 +32,7 @@
35#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) 32#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
36 33
37#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $"; 35static char *rcsid = "$OpenBSD: realpath.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $";
39#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
40 37
41#include <sys/param.h> 38#include <sys/param.h>
@@ -65,7 +62,7 @@ char *
65realpath(const char *path, char *resolved) 62realpath(const char *path, char *resolved)
66{ 63{
67 struct stat sb; 64 struct stat sb;
68 int fd, n, needslash, serrno = 0; 65 int fd, n, rootd, serrno = 0;
69 char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; 66 char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN];
70 int symlinks = 0; 67 int symlinks = 0;
71 68
@@ -141,18 +138,18 @@ loop:
141 * happens if the last component is empty, or the dirname is root. 138 * happens if the last component is empty, or the dirname is root.
142 */ 139 */
143 if (resolved[0] == '/' && resolved[1] == '\0') 140 if (resolved[0] == '/' && resolved[1] == '\0')
144 needslash = 0; 141 rootd = 1;
145 else 142 else
146 needslash = 1; 143 rootd = 0;
147 144
148 if (*wbuf) { 145 if (*wbuf) {
149 if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { 146 if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
150 serrno = ENAMETOOLONG; 147 serrno = ENAMETOOLONG;
151 goto err1; 148 goto err1;
152 } 149 }
153 if (needslash == 0) 150 if (rootd == 0)
154 strlcat(resolved, "/", MAXPATHLEN); 151 (void)strcat(resolved, "/");
155 strlcat(resolved, wbuf, MAXPATHLEN); 152 (void)strcat(resolved, wbuf);
156 } 153 }
157 154
158 /* Go back to where we came from. */ 155 /* Go back to where we came from. */