Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Jun 2012 16:16:33 +0000 (UTC)
From:      "Andrey A. Chernov" <ache@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r236618 - head/lib/libc/stdlib
Message-ID:  <201206051616.q55GGXt7029764@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ache
Date: Tue Jun  5 16:16:33 2012
New Revision: 236618
URL: http://svn.freebsd.org/changeset/base/236618

Log:
  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

Modified:
  head/lib/libc/stdlib/realpath.c

Modified: head/lib/libc/stdlib/realpath.c
==============================================================================
--- head/lib/libc/stdlib/realpath.c	Tue Jun  5 14:19:59 2012	(r236617)
+++ head/lib/libc/stdlib/realpath.c	Tue Jun  5 16:16:33 2012	(r236618)
@@ -54,7 +54,7 @@ realpath(const char * __restrict path, c
 	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, c
 		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, c
 			 * 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, c
 		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, c
 			}
 			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';



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206051616.q55GGXt7029764>