summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2012-06-05 16:16:33 +0000
committerache <ache@FreeBSD.org>2012-06-05 16:16:33 +0000
commit3515d45cd06756bbd9d7cd27096d00af1e6148bf (patch)
treebede6748ca4ca7234f3af4c6eee4fa5c0b47f359 /lib
parentfe9edacbccc1b0d60fd1f7e22580414c570a7eb9 (diff)
downloadFreeBSD-src-3515d45cd06756bbd9d7cd27096d00af1e6148bf.zip
FreeBSD-src-3515d45cd06756bbd9d7cd27096d00af1e6148bf.tar.gz
1) Although unpublished version of standard
http://austingroupbugs.net/view.php?id=385#c713 (Resolved state) recommend this way for the current standard (called "earlier" in the text) "However, earlier versions of this standard did not require this, and the same example had to be written as: // buf was obtained by malloc(buflen) ret = write(fd, buf, buflen); if (ret < 0) { int save = errno; free(buf); errno = save; return ret; } " from feedback I have for previous commit it seems that many people prefer to avoid mass code change needed for current standard compliance and prefer to track unpublished standard instead, which requires now that free() itself must save errno, not its usage code. So, I back out "save errno across free()" part of previous commit, and will fill PR for changing free() isntead. 2) Remove now unused serrno. MFC after: 1 week
Diffstat (limited to 'lib')
-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 185dbb6..aded9b2 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';
OpenPOWER on IntegriCloud