Libraries updates and cleanup

* Updating common/lib
 * Updating lib/csu
 * Updating lib/libc
 * Updating libexec/ld.elf_so
 * Corrected test on __minix in featuretest to actually follow the
   meaning of the comment.
 * Cleaned up _REENTRANT-related defintions.
 * Disabled -D_REENTRANT for libfetch
 * Removing some unneeded __NBSD_LIBC defines and tests

Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2
This commit is contained in:
2012-11-15 12:06:41 +01:00
parent f6aac1c3b5
commit f14fb60209
1285 changed files with 44244 additions and 14308 deletions

View File

@@ -1,4 +1,4 @@
/* $NetBSD: hcreate.c,v 1.6 2008/07/21 12:05:43 lukem Exp $ */
/* $NetBSD: hcreate.c,v 1.8 2011/09/17 16:54:39 christos Exp $ */
/*
* Copyright (c) 2001 Christopher G. Demetriou
@@ -12,12 +12,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the
* NetBSD Project. See http://www.NetBSD.org/ for
* information about NetBSD.
* 4. The name of the author may not be used to endorse or promote products
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
@@ -48,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: hcreate.c,v 1.6 2008/07/21 12:05:43 lukem Exp $");
__RCSID("$NetBSD: hcreate.c,v 1.8 2011/09/17 16:54:39 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#if !defined(lint)
@@ -88,21 +83,28 @@ SLIST_HEAD(internal_head, internal_entry);
/* Default hash function, from db/hash/hash_func.c */
extern u_int32_t (*__default_hash)(const void *, size_t);
static struct internal_head *htable;
static size_t htablesize;
static struct hsearch_data htable;
int
hcreate(size_t nel)
{
size_t idx;
unsigned int p2;
_DIAGASSERT(htable.table == NULL);
/* Make sure this isn't called when a table already exists. */
_DIAGASSERT(htable == NULL);
if (htable != NULL) {
if (htable.table != NULL) {
errno = EINVAL;
return 0;
}
return hcreate_r(nel, &htable);
}
int
hcreate_r(size_t nel, struct hsearch_data *head)
{
struct internal_head *table;
size_t idx;
unsigned int p2;
void *p;
/* If nel is too small, make it min sized. */
if (nel < MIN_BUCKETS)
@@ -121,76 +123,108 @@ hcreate(size_t nel)
}
/* Allocate the table. */
htablesize = nel;
htable = malloc(htablesize * sizeof htable[0]);
if (htable == NULL) {
head->size = nel;
head->filled = 0;
p = malloc(nel * sizeof table[0]);
if (p == NULL) {
errno = ENOMEM;
return 0;
}
head->table = p;
table = p;
/* Initialize it. */
for (idx = 0; idx < htablesize; idx++)
SLIST_INIT(&htable[idx]);
for (idx = 0; idx < nel; idx++)
SLIST_INIT(&table[idx]);
return 1;
}
void
hdestroy(void)
{
_DIAGASSERT(htable.table != NULL);
hdestroy_r(&htable);
}
void
hdestroy_r(struct hsearch_data *head)
{
struct internal_entry *ie;
size_t idx;
void *p;
struct internal_head *table;
_DIAGASSERT(htable != NULL);
if (htable == NULL)
if (head == NULL)
return;
for (idx = 0; idx < htablesize; idx++) {
while (!SLIST_EMPTY(&htable[idx])) {
ie = SLIST_FIRST(&htable[idx]);
SLIST_REMOVE_HEAD(&htable[idx], link);
p = head->table;
head->table = NULL;
table = p;
for (idx = 0; idx < head->size; idx++) {
while (!SLIST_EMPTY(&table[idx])) {
ie = SLIST_FIRST(&table[idx]);
SLIST_REMOVE_HEAD(&table[idx], link);
free(ie->ent.key);
free(ie);
}
}
free(htable);
htable = NULL;
free(table);
}
ENTRY *
hsearch(ENTRY item, ACTION action)
{
struct internal_head *head;
ENTRY *ep;
_DIAGASSERT(htable.table != NULL);
(void)hsearch_r(item, action, &ep, &htable);
return ep;
}
int
hsearch_r(ENTRY item, ACTION action, ENTRY **itemp, struct hsearch_data *head)
{
struct internal_head *table, *chain;
struct internal_entry *ie;
uint32_t hashval;
size_t len;
void *p;
_DIAGASSERT(htable != NULL);
_DIAGASSERT(item.key != NULL);
_DIAGASSERT(action == ENTER || action == FIND);
p = head->table;
table = p;
len = strlen(item.key);
hashval = (*__default_hash)(item.key, len);
head = &htable[hashval & (htablesize - 1)];
ie = SLIST_FIRST(head);
chain = &table[hashval & (head->size - 1)];
ie = SLIST_FIRST(chain);
while (ie != NULL) {
if (strcmp(ie->ent.key, item.key) == 0)
break;
ie = SLIST_NEXT(ie, link);
}
if (ie != NULL)
return &ie->ent;
else if (action == FIND)
return NULL;
if (ie != NULL) {
*itemp = &ie->ent;
return 1;
} else if (action == FIND) {
*itemp = NULL;
errno = ESRCH;
return 1;
}
ie = malloc(sizeof *ie);
if (ie == NULL)
return NULL;
return 0;
ie->ent.key = item.key;
ie->ent.data = item.data;
SLIST_INSERT_HEAD(head, ie, link);
return &ie->ent;
SLIST_INSERT_HEAD(chain, ie, link);
*itemp = &ie->ent;
head->filled++;
return 1;
}