malloc_conf_init: revert errno value when readlink(2) fail.

This commit is contained in:
Alexandre Perrin 2013-09-20 19:58:11 +02:00 committed by Jason Evans
parent a33488d648
commit dd6ef0302f

View File

@ -436,8 +436,9 @@ malloc_conf_init(void)
} }
break; break;
case 1: { case 1: {
int linklen = 0;
#ifndef _WIN32 #ifndef _WIN32
int linklen; int saved_errno = errno;
const char *linkname = const char *linkname =
# ifdef JEMALLOC_PREFIX # ifdef JEMALLOC_PREFIX
"/etc/"JEMALLOC_PREFIX"malloc.conf" "/etc/"JEMALLOC_PREFIX"malloc.conf"
@ -446,21 +447,20 @@ malloc_conf_init(void)
# endif # endif
; ;
if ((linklen = readlink(linkname, buf,
sizeof(buf) - 1)) != -1) {
/* /*
* Use the contents of the "/etc/malloc.conf" * Try to use the contents of the "/etc/malloc.conf"
* symbolic link's name. * symbolic link's name.
*/ */
linklen = readlink(linkname, buf, sizeof(buf) - 1);
if (linklen == -1) {
/* No configuration specified. */
linklen = 0;
/* restore errno */
set_errno(saved_errno);
}
#endif
buf[linklen] = '\0'; buf[linklen] = '\0';
opts = buf; opts = buf;
} else
#endif
{
/* No configuration specified. */
buf[0] = '\0';
opts = buf;
}
break; break;
} case 2: { } case 2: {
const char *envname = const char *envname =