X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Tue, 20 Jan 2004 11:57:20 +0200 (EET) From: Esa A E Peuha Sender: peuha AT sirppi DOT helsinki DOT fi To: djgpp-workers AT delorie DOT com Subject: Patch for bsearch Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com I noticed that bsearch currently casts between void * and char * quite unnecessarily, and uses unconst earlier than needed. I also changed the literal 0 to NULL (I wish there were some easy way to do this automatically): Index: bsearch.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/bsearch.c,v retrieving revision 1.1 diff -u -r1.1 bsearch.c --- bsearch.c 26 Dec 1994 20:35:04 -0000 1.1 +++ bsearch.c 20 Jan 2004 09:40:34 -0000 @@ -3,24 +3,23 @@ #include void * -bsearch(const void *key, const void *base0, size_t nelem, +bsearch(const void *key, const void *base, size_t nelem, size_t size, int (*cmp)(const void *ck, const void *ce)) { - char *base = unconst(base0, char *); int lim, cmpval; - void *p; + const void *p; for (lim = nelem; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; cmpval = (*cmp)(key, p); if (cmpval == 0) - return p; + return unconst(p, void *); if (cmpval > 0) { /* key > p: move right */ - base = (char *)p + size; + base = p + size; lim--; } /* else move left */ } - return 0; + return NULL; } -- Esa Peuha student of mathematics at the University of Helsinki http://www.helsinki.fi/~peuha/