]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libiberty/bsearch.c
c++: remove lookup_template_class's entering_scope flag
[thirdparty/gcc.git] / libiberty / bsearch.c
index 6a8ee33341d672e0976cd8224624519004fd1c95..18158b9591b98d23d67d882170f769e3627b129c 100644 (file)
  * SUCH DAMAGE.
  */
 
+/*
+
+@deftypefn Supplemental void* bsearch (const void *@var{key}, @
+  const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, @
+  int (*@var{compar})(const void *, const void *))
+
+Performs a search over an array of @var{nmemb} elements pointed to by
+@var{base} for a member that matches the object pointed to by @var{key}.
+The size of each member is specified by @var{size}.  The array contents
+should be sorted in ascending order according to the @var{compar}
+comparison function.  This routine should take two arguments pointing to
+the @var{key} and to an array member, in that order, and should return an
+integer less than, equal to, or greater than zero if the @var{key} object
+is respectively less than, matching, or greater than the array member.
+
+@end deftypefn
+
+*/
+
 #include "config.h"
 #include "ansidecl.h"
 #include <sys/types.h>         /* size_t */
  * look at item 3.
  */
 void *
-bsearch(key, base0, nmemb, size, compar)
-       register void *key;
-       void *base0;
-       size_t nmemb;
-       register size_t size;
-       register int (*compar)();
+bsearch (const void *key, const void *base0,
+         size_t nmemb, size_t size,
+         int (*compar)(const void *, const void *))
 {
-       register char *base = base0;
-       register int lim, cmp;
-       register void *p;
+       const char *base = (const char *) base0;
+       int lim, cmp;
+       const void *p;
 
        for (lim = nmemb; lim != 0; lim >>= 1) {
                p = base + (lim >> 1) * size;
                cmp = (*compar)(key, p);
                if (cmp == 0)
-                       return (p);
+                       return (void *)p;
                if (cmp > 0) {  /* key > p: move right */
-                       base = (char *)p + size;
+                       base = (const char *)p + size;
                        lim--;
                } /* else move left */
        }