cleanup saving and restoring errno, and make it similar.

This commit is contained in:
christos 2011-05-18 01:59:39 +00:00
parent b11777e520
commit 713ea1897d
2 changed files with 9 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: jemalloc.c,v 1.23 2011/05/13 23:11:00 christos Exp $ */
/* $NetBSD: jemalloc.c,v 1.24 2011/05/18 01:59:39 christos Exp $ */
/*-
* Copyright (C) 2006,2007 Jason Evans <jasone@FreeBSD.org>.
@ -118,7 +118,7 @@
#include <sys/cdefs.h>
/* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
__RCSID("$NetBSD: jemalloc.c,v 1.23 2011/05/13 23:11:00 christos Exp $");
__RCSID("$NetBSD: jemalloc.c,v 1.24 2011/05/18 01:59:39 christos Exp $");
#ifdef __FreeBSD__
#include "libc_private.h"
@ -3337,6 +3337,7 @@ malloc_init_hard(void)
return (false);
}
serrno = errno;
/* Get number of CPUs. */
{
int mib[2];
@ -3372,7 +3373,6 @@ malloc_init_hard(void)
/* Get runtime configuration. */
switch (i) {
case 0:
serrno = errno;
if ((linklen = readlink("/etc/malloc.conf", buf,
sizeof(buf) - 1)) != -1) {
/*
@ -3382,7 +3382,6 @@ malloc_init_hard(void)
buf[linklen] = '\0';
opts = buf;
} else {
errno = serrno;
/* No configuration specified. */
buf[0] = '\0';
opts = buf;
@ -3518,6 +3517,7 @@ malloc_init_hard(void)
}
}
}
errno = serrno;
/* Take care to call atexit() only once. */
if (opt_print_stats) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: malloc.c,v 1.53 2011/05/13 23:11:00 christos Exp $ */
/* $NetBSD: malloc.c,v 1.54 2011/05/18 01:59:39 christos Exp $ */
/*
* ----------------------------------------------------------------------------
@ -90,7 +90,7 @@ void utrace(struct ut *, int);
#include <sys/cdefs.h>
#include "extern.h"
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: malloc.c,v 1.53 2011/05/13 23:11:00 christos Exp $");
__RCSID("$NetBSD: malloc.c,v 1.54 2011/05/18 01:59:39 christos Exp $");
#endif /* LIBC_SCCS and not lint */
int utrace(const char *, void *, size_t);
@ -447,7 +447,7 @@ malloc_init(void)
char b[64];
size_t i;
ssize_t j;
int save_errno = errno;
int serrno = errno;
/*
* Compute page-size related variables.
@ -467,12 +467,9 @@ malloc_init(void)
for (i = 0; i < 3; i++) {
if (i == 0) {
int serrno = errno;
j = readlink("/etc/malloc.conf", b, sizeof b - 1);
if (j == -1) {
errno = serrno;
if (j == -1)
continue;
}
b[j] = '\0';
p = b;
} else if (i == 1 && issetugid() == 0) {
@ -550,7 +547,7 @@ malloc_init(void)
*/
px = imalloc(sizeof *px);
errno = save_errno;
errno = serrno;
}
/*