-/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
-Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
-This file is part of the GNU C Library.
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1993.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <malloc.h>
becomes zero. */
int
hcreate_r (nel, htab)
- unsigned int nel;
+ size_t nel;
struct hsearch_data *htab;
{
/* Test for correct arguments. */
}
-/* This is the search function. It uses double hashing with open adressing.
+/* This is the search function. It uses double hashing with open addressing.
The argument item.key has to be a pointer to an zero terminated, most
probably strings of chars. The function for generating a number of the
strings is simple but fast. It can be replaced by a more complex function
unsigned int len = strlen (item.key);
unsigned int idx;
- /* If table is full and another entry should be entered return with
- error. */
- if (action == ENTER && htab->filled == htab->size)
- {
- __set_errno (ENOMEM);
- *retval = NULL;
- return 0;
- }
-
/* Compute an value for the given string. Perhaps use a better method. */
hval = len;
count = len;
else
idx -= hval2;
+ /* If we visited all entries leave the loop unsuccessfully. */
+ if (idx == hval)
+ break;
+
/* If entry is found use it. */
if (htab->table[idx].used == hval
&& strcmp (item.key, htab->table[idx].entry.key) == 0)
/* An empty bucket has been found. */
if (action == ENTER)
{
+ /* If table is full and another entry should be entered return
+ with error. */
+ if (action == ENTER && htab->filled == htab->size)
+ {
+ __set_errno (ENOMEM);
+ *retval = NULL;
+ return 0;
+ }
+
htab->table[idx].used = hval;
htab->table[idx].entry = item;