From owner-svn-src-all@FreeBSD.ORG Mon Jun 4 21:34:50 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6340F106566C; Mon, 4 Jun 2012 21:34:50 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 33E018FC12; Mon, 4 Jun 2012 21:34:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q54LYodD067687; Mon, 4 Jun 2012 21:34:50 GMT (envelope-from ache@svn.freebsd.org) Received: (from ache@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q54LYoVJ067685; Mon, 4 Jun 2012 21:34:50 GMT (envelope-from ache@svn.freebsd.org) Message-Id: <201206042134.q54LYoVJ067685@svn.freebsd.org> From: "Andrey A. Chernov" Date: Mon, 4 Jun 2012 21:34:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236582 - head/lib/libc/stdlib X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2012 21:34:50 -0000 Author: ache Date: Mon Jun 4 21:34:49 2012 New Revision: 236582 URL: http://svn.freebsd.org/changeset/base/236582 Log: 1) IEEE Std 1003.1-2008, "errno" section, is explicit that "The setting of errno after a successful call to a function is unspecified unless the description of that function specifies that errno shall not be modified." However, free() in IEEE Std 1003.1-2008 does not mention its interaction with errno, so MAY modify it after successful call (it depends on particular free() implementation, OS-specific, etc.). So, save errno across free() calls to make code portable and POSIX-conformant. 2) Remove unused serrno assignment. MFC after: 1 week Modified: head/lib/libc/stdlib/realpath.c Modified: head/lib/libc/stdlib/realpath.c ============================================================================== --- head/lib/libc/stdlib/realpath.c Mon Jun 4 20:56:40 2012 (r236581) +++ head/lib/libc/stdlib/realpath.c Mon Jun 4 21:34:49 2012 (r236582) @@ -65,7 +65,6 @@ realpath(const char * __restrict path, c errno = ENOENT; return (NULL); } - serrno = errno; if (resolved == NULL) { resolved = malloc(PATH_MAX); if (resolved == NULL) @@ -83,9 +82,11 @@ realpath(const char * __restrict path, c left_len = strlcpy(left, path + 1, sizeof(left)); } else { if (getcwd(resolved, PATH_MAX) == NULL) { - if (m) + if (m) { + serrno = errno; free(resolved); - else { + errno = serrno; + } else { resolved[0] = '.'; resolved[1] = '\0'; } @@ -143,8 +144,11 @@ realpath(const char * __restrict path, c * occurence to not implement lookahead. */ if (lstat(resolved, &sb) != 0) { - if (m) + if (m) { + serrno = errno; free(resolved); + errno = serrno; + } return (NULL); } if (!S_ISDIR(sb.st_mode)) { @@ -184,8 +188,11 @@ realpath(const char * __restrict path, c if (lstat(resolved, &sb) != 0) { if (errno != ENOENT || p != NULL) errno = ENOTDIR; - if (m) + if (m) { + serrno = errno; free(resolved); + errno = serrno; + } return (NULL); } if (S_ISLNK(sb.st_mode)) { @@ -197,8 +204,11 @@ realpath(const char * __restrict path, c } slen = readlink(resolved, symlink, sizeof(symlink) - 1); if (slen < 0) { - if (m) + if (m) { + serrno = errno; free(resolved); + errno = serrno; + } return (NULL); } symlink[slen] = '\0';