1996-06-07 04:36:10 +00:00
|
|
|
/* Linear search functions.
|
2014-01-01 11:03:15 +00:00
|
|
|
Copyright (C) 1996-2014 Free Software Foundation, Inc.
|
1997-01-30 04:09:36 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-01-30 04:09:36 +00:00
|
|
|
|
|
|
|
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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-01-30 04:09:36 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1996-06-07 04:36:10 +00:00
|
|
|
|
|
|
|
#include <search.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
lsearch (const void *key, void *base, size_t *nmemb, size_t size,
|
|
|
|
__compar_fn_t compar)
|
|
|
|
{
|
|
|
|
void *result;
|
|
|
|
|
|
|
|
/* Try to find it. */
|
|
|
|
result = lfind (key, base, nmemb, size, compar);
|
|
|
|
if (result == NULL)
|
|
|
|
{
|
|
|
|
/* Not available. Insert at the end. */
|
1998-01-21 17:04:36 +00:00
|
|
|
result = memcpy (base + (*nmemb) * size, key, size);
|
1996-06-07 04:36:10 +00:00
|
|
|
++(*nmemb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
lfind (const void *key, const void *base, size_t *nmemb, size_t size,
|
|
|
|
__compar_fn_t compar)
|
|
|
|
{
|
|
|
|
const void *result = base;
|
|
|
|
size_t cnt = 0;
|
|
|
|
|
|
|
|
while (cnt < *nmemb && (*compar) (key, result) != 0)
|
|
|
|
{
|
|
|
|
result += size;
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt < *nmemb ? (void *) result : NULL;
|
|
|
|
}
|
* include/search.h: Use libc_hidden_proto for hsearch_r, lfind.
* misc/hsearch_r.c: Add libc_hidden_def.
* misc/lsearch.c: Likewise.
* include/ttyent.h: Use libc_hidden_proto for getttyent, setttyent,
endttyent.
* misc/getttyent.c: Add libc_hidden_def.
* include/mcheck.h: Use libc_hidden_proto for mcheck.
* malloc/mcheck.c: Add libc_hidden_def.
* include/envz.h: Use libc_hidden_proto for envz_entry, enz_remove.
* include/argz.h: Use libc_hidden_proto for argz_delete.
* string/argz-delete.c: Add libc_hidden_def.
* string/envz.c: Likewise. Use <envz.h>, not "envz.h".
* sysdeps/unix/sysv/linux/x86_64/clone.S (thread_start): Use
HIDDEN_JUMPTARGET for _exit.
* sysdeps/unix/sysv/linux/m68k/clone.S (thread_start): Likewise.
* sysdeps/unix/sysv/linux/i386/clone.S (thread_start): Likewise.
* sysdeps/unix/sysv/linux/powerpc/clone.S: Likewise.
* sysdeps/unix/_exit.S (_exit): Add libc_hidden_def.
* include/libc-symbols.h: Fix [__ASSEMBLY__] -> [__ASSEMBLER__].
[__ASSEMBLER__] (hidden_weak): Define using hidden_def, or to empty.
[__ASSEMBLER__] (HIDDEN_JUMPTARGET): New macro.
* sysdeps/unix/sysv/linux/i386/makecontext.S: Use it for exit.
* include/stdlib.h: Use libc_hidden_proto for abort,
__strtof_internal, __strtod_internal, __strtold_internal,
__strtol_internal, __strtoll_internal, __strtoul_internal,
__strtoull_internal. __strtof_l_internal, __strtod_l_internal,
__strtold_l_internal, __strtol_l_internal, __strtoll_l_internal,
__strtoul_l_internal, __strtoull_l_internal.
* include/wchar.h: Use libc_hidden_proto for __wcstof_internal,
__wcstod_internal, __wcstold_internal, __wcstol_internal,
__wcstoll_internal, __wcstoul_internal, ____wcstof_l_internal,
____wcstod_l_internal, ____wcstold_l_internal, ____wcstol_l_internal,
____wcstoll_l_internal, ____wcstoul_l_internal, __wcscasecmp_l,
__wcsncasecmp_l.
* sysdeps/generic/abort.c: Add libc_hidden_def.
* stdlib/strtod.c: Likewise.
* sysdeps/generic/strtol.c: Likewise.
* sysdeps/wordsize-64/strtol.c: Likewise.
* sysdeps/wordsize-64/wcstol.c: Likewise.
* sysdeps/wordsize-64/wcstol_l.c: Likewise.
2002-08-04 01:29:29 +00:00
|
|
|
libc_hidden_def (lfind)
|