summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/realpath.c
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2012-06-05 16:16:33 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2012-06-05 16:16:33 +0000
commit5f5a50728c89942f4c223cc8856ae1f978549240 (patch)
treebede6748ca4ca7234f3af4c6eee4fa5c0b47f359 /lib/libc/stdlib/realpath.c
parenta687c5ecc9b103006ca89b97e12bc1e338f11ad3 (diff)
Notes
Diffstat (limited to 'lib/libc/stdlib/realpath.c')
-rw-r--r--lib/libc/stdlib/realpath.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 185dbb6c4c55..aded9b244e78 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -54,7 +54,7 @@ realpath(const char * __restrict path, char * __restrict resolved)
char *p, *q, *s;
size_t left_len, resolved_len;
unsigned symlinks;
- int m, serrno, slen;
+ int m, slen;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
if (path == NULL) {
@@ -82,11 +82,9 @@ realpath(const char * __restrict path, char * __restrict resolved)
left_len = strlcpy(left, path + 1, sizeof(left));
} else {
if (getcwd(resolved, PATH_MAX) == NULL) {
- if (m) {
- serrno = errno;
+ if (m)
free(resolved);
- errno = serrno;
- } else {
+ else {
resolved[0] = '.';
resolved[1] = '\0';
}
@@ -144,11 +142,8 @@ realpath(const char * __restrict path, char * __restrict resolved)
* occurence to not implement lookahead.
*/
if (lstat(resolved, &sb) != 0) {
- if (m) {
- serrno = errno;
+ if (m)
free(resolved);
- errno = serrno;
- }
return (NULL);
}
if (!S_ISDIR(sb.st_mode)) {
@@ -188,11 +183,8 @@ realpath(const char * __restrict path, char * __restrict resolved)
if (lstat(resolved, &sb) != 0) {
if (errno != ENOENT || p != NULL)
errno = ENOTDIR;
- if (m) {
- serrno = errno;
+ if (m)
free(resolved);
- errno = serrno;
- }
return (NULL);
}
if (S_ISLNK(sb.st_mode)) {
@@ -204,11 +196,8 @@ realpath(const char * __restrict path, char * __restrict resolved)
}
slen = readlink(resolved, symlink, sizeof(symlink) - 1);
if (slen < 0) {
- if (m) {
- serrno = errno;
+ if (m)
free(resolved);
- errno = serrno;
- }
return (NULL);
}
symlink[slen] = '\0';