summaryrefslogtreecommitdiff
path: root/libc/misc/search
diff options
context:
space:
mode:
Diffstat (limited to 'libc/misc/search')
-rw-r--r--libc/misc/search/Makefile.in24
-rw-r--r--libc/misc/search/_hsearch_r.c20
-rw-r--r--libc/misc/search/_lsearch.c4
-rw-r--r--libc/misc/search/_tsearch.c18
-rw-r--r--libc/misc/search/hsearch.c8
-rw-r--r--libc/misc/search/insremque.c23
6 files changed, 45 insertions, 52 deletions
diff --git a/libc/misc/search/Makefile.in b/libc/misc/search/Makefile.in
index 2da1d6e01..d13766148 100644
--- a/libc/misc/search/Makefile.in
+++ b/libc/misc/search/Makefile.in
@@ -1,33 +1,35 @@
# Makefile for uClibc
#
-# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-CSRC := hsearch.c
+subdirs += libc/misc/search
+
+CSRC-y := hsearch.c
# multi source _tsearch.c
-CSRC += tsearch.c tfind.c tdelete.c twalk.c tdestroy.c
+CSRC-y += tsearch.c tfind.c tdelete.c twalk.c tdestroy.c
# multi source _lsearch.c
-CSRC += lfind.c lsearch.c
+CSRC-y += lfind.c lsearch.c
# multi source insremque.c
-CSRC += insque.c remque.c
+CSRC-y += insque.c remque.c
# multi source _hsearch_r.c
-CSRC += hcreate_r.c hdestroy_r.c hsearch_r.c
+CSRC-y += hcreate_r.c hdestroy_r.c hsearch_r.c
MISC_SEARCH_DIR := $(top_srcdir)libc/misc/search
MISC_SEARCH_OUT := $(top_builddir)libc/misc/search
-MISC_SEARCH_SRC := $(patsubst %.c,$(MISC_SEARCH_DIR)/%.c,$(CSRC))
-MISC_SEARCH_OBJ := $(patsubst %.c,$(MISC_SEARCH_OUT)/%.o,$(CSRC))
+MISC_SEARCH_SRC := $(patsubst %.c,$(MISC_SEARCH_DIR)/%.c,$(CSRC-y))
+MISC_SEARCH_OBJ := $(patsubst %.c,$(MISC_SEARCH_OUT)/%.o,$(CSRC-y))
libc-y += $(MISC_SEARCH_OBJ)
-objclean-y += misc_search_objclean
+objclean-y += CLEAN_libc/misc/search
-misc_search_objclean:
- $(RM) $(MISC_SEARCH_OUT)/*.{o,os}
+CLEAN_libc/misc/search:
+ $(do_rm) $(addprefix $(MISC_SEARCH_OUT)/*., o os)
diff --git a/libc/misc/search/_hsearch_r.c b/libc/misc/search/_hsearch_r.c
index c9c4a9ccf..7b57ce16c 100644
--- a/libc/misc/search/_hsearch_r.c
+++ b/libc/misc/search/_hsearch_r.c
@@ -13,12 +13,11 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
#include <string.h>
#include <search.h>
@@ -49,12 +48,12 @@ _ENTRY;
static int isprime (unsigned int number)
{
/* no even number will be passed */
- unsigned int div = 3;
+ unsigned int divisor = 3;
- while (div * div < number && number % div != 0)
- div += 2;
+ while (divisor * divisor < number && number % divisor != 0)
+ divisor += 2;
- return number % div != 0;
+ return number % divisor != 0;
}
@@ -64,7 +63,6 @@ static int isprime (unsigned int number)
indexing as explained in the comment for the hsearch function.
The contents of the table is zeroed, especially the field used
becomes zero. */
-libc_hidden_proto(hcreate_r)
int hcreate_r (size_t nel, struct hsearch_data *htab)
{
/* Test for correct arguments. */
@@ -100,7 +98,6 @@ libc_hidden_def(hcreate_r)
#ifdef L_hdestroy_r
/* After using the hash table it has to be destroyed. The used memory can
be freed and the local static variable can be marked as not used. */
-libc_hidden_proto(hdestroy_r)
void hdestroy_r (struct hsearch_data *htab)
{
/* Test for correct arguments. */
@@ -134,10 +131,7 @@ libc_hidden_def(hdestroy_r)
equality of the stored and the parameter value. This helps to prevent
unnecessary expensive calls of strcmp. */
-/* Experimentally off - libc_hidden_proto(strcmp) */
-/* Experimentally off - libc_hidden_proto(strlen) */
-libc_hidden_proto(hsearch_r)
int hsearch_r (ENTRY item, ACTION action, ENTRY **retval,
struct hsearch_data *htab)
{
diff --git a/libc/misc/search/_lsearch.c b/libc/misc/search/_lsearch.c
index e91ea9441..0cf496e26 100644
--- a/libc/misc/search/_lsearch.c
+++ b/libc/misc/search/_lsearch.c
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <search.h>
-libc_hidden_proto(lfind)
#ifdef L_lfind
@@ -22,7 +21,7 @@ void *lfind(const void *key, const void *base, size_t *nmemb,
register int n = *nmemb;
while (n--) {
- if ((*compar) (base, key) == 0)
+ if ((*compar) (key, base) == 0)
return ((void*)base);
base += size;
}
@@ -34,7 +33,6 @@ libc_hidden_def(lfind)
#ifdef L_lsearch
-/* Experimentally off - libc_hidden_proto(memcpy) */
void *lsearch(const void *key, void *base, size_t *nmemb,
size_t size, int (*compar)(const void *, const void *))
diff --git a/libc/misc/search/_tsearch.c b/libc/misc/search/_tsearch.c
index 3d43aa543..fe9eedfa9 100644
--- a/libc/misc/search/_tsearch.c
+++ b/libc/misc/search/_tsearch.c
@@ -13,8 +13,7 @@ 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., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+not, see <http://www.gnu.org/licenses/>. */
/*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -50,8 +49,7 @@ register node **rootp; address of tree root
int (*compar)(); ordering function
*/
-libc_hidden_proto(tsearch)
-void *tsearch(__const void *key, void **vrootp, __compar_fn_t compar)
+void *tsearch(const void *key, void **vrootp, __compar_fn_t compar)
{
register node *q;
register node **rootp = (node **) vrootp;
@@ -81,8 +79,7 @@ libc_hidden_def(tsearch)
#endif
#ifdef L_tfind
-libc_hidden_proto(tfind)
-void *tfind(__const void *key, void * __const *vrootp, __compar_fn_t compar)
+void *tfind(const void *key, void * const *vrootp, __compar_fn_t compar)
{
register node **rootp = (node **) vrootp;
@@ -109,7 +106,7 @@ char *key; key to be deleted
register node **rootp; address of the root of tree
int (*compar)(); comparison function
*/
-void *tdelete(__const void *key, void ** vrootp, __compar_fn_t compar)
+void *tdelete(const void *key, void ** vrootp, __compar_fn_t compar)
{
node *p;
register node *q;
@@ -159,7 +156,7 @@ register node *root; Root of the tree to be walked
register void (*action)(); Function to be called at each node
register int level;
*/
-static void trecurse(__const void *vroot, __action_fn_t action, int level)
+static void trecurse(const void *vroot, __action_fn_t action, int level)
{
register node *root = (node *) vroot;
@@ -182,9 +179,9 @@ node *root; Root of the tree to be walked
void (*action)(); Function to be called at each node
PTR
*/
-void twalk(__const void *vroot, __action_fn_t action)
+void twalk(const void *vroot, __action_fn_t action)
{
- register __const node *root = (node *) vroot;
+ register const node *root = (node *) vroot;
if (root != (node *)0 && action != (__action_fn_t) 0)
trecurse(root, action, 0);
@@ -208,7 +205,6 @@ tdestroy_recurse (node *root, __free_fn_t freefct)
free (root);
}
-libc_hidden_proto(tdestroy)
void tdestroy (void *vroot, __free_fn_t freefct)
{
node *root = (node *) vroot;
diff --git a/libc/misc/search/hsearch.c b/libc/misc/search/hsearch.c
index b1228e2ee..54acfc484 100644
--- a/libc/misc/search/hsearch.c
+++ b/libc/misc/search/hsearch.c
@@ -13,15 +13,11 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <search.h>
-libc_hidden_proto(hdestroy_r)
-libc_hidden_proto(hsearch_r)
-libc_hidden_proto(hcreate_r)
/* The non-reentrant version use a global space for storing the table. */
static struct hsearch_data htab;
diff --git a/libc/misc/search/insremque.c b/libc/misc/search/insremque.c
index 32edf7a4e..99399427e 100644
--- a/libc/misc/search/insremque.c
+++ b/libc/misc/search/insremque.c
@@ -13,8 +13,7 @@
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. */
+ see <http://www.gnu.org/licenses/>. */
#include <features.h>
#include <stddef.h>
@@ -27,12 +26,20 @@
void
insque (void *elem, void *prev)
{
- struct qelem *next = ((struct qelem *) prev)->q_forw;
- ((struct qelem *) prev)->q_forw = (struct qelem *) elem;
- if (next != NULL)
- next->q_back = (struct qelem *) elem;
- ((struct qelem *) elem)->q_forw = next;
- ((struct qelem *) elem)->q_back = (struct qelem *) prev;
+ if (prev == NULL)
+ {
+ ((struct qelem *) elem)->q_forw = NULL;
+ ((struct qelem *) elem)->q_back = NULL;
+ }
+ else
+ {
+ struct qelem *next = ((struct qelem *) prev)->q_forw;
+ ((struct qelem *) prev)->q_forw = (struct qelem *) elem;
+ if (next != NULL)
+ next->q_back = (struct qelem *) elem;
+ ((struct qelem *) elem)->q_forw = next;
+ ((struct qelem *) elem)->q_back = (struct qelem *) prev;
+ }
}
#endif