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
This commit is contained in:
parent
a687c5ecc9
commit
5f5a50728c
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user