lsearch.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * This file lifted in toto from 'Dlibs' on the atari ST (RdeBath)
  3. *
  4. *
  5. * Dale Schumacher 399 Beacon Ave.
  6. * (alias: Dalnefre') St. Paul, MN 55104
  7. * dal@syntel.UUCP United States of America
  8. * "It's not reality that's important, but how you perceive things."
  9. */
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <search.h>
  13. #ifdef L_lfind
  14. void attribute_hidden *__lfind(const void *key, const void *base, size_t *nmemb,
  15. size_t size, int (*compar)(const void *, const void *))
  16. {
  17. register int n = *nmemb;
  18. while (n--) {
  19. if ((*compar) (base, key) == 0)
  20. return ((void*)base);
  21. base += size;
  22. }
  23. return (NULL);
  24. }
  25. strong_alias(__lfind,lfind)
  26. #endif
  27. #ifdef L_lsearch
  28. extern void *__lfind (__const void *__key, __const void *__base,
  29. size_t *__nmemb, size_t __size, __compar_fn_t __compar) attribute_hidden;
  30. void *lsearch(const void *key, void *base, size_t *nmemb,
  31. size_t size, int (*compar)(const void *, const void *))
  32. {
  33. register char *p;
  34. if ((p = __lfind(key, base, nmemb, size, compar)) == NULL) {
  35. p = __memcpy((base + (size * (*nmemb))), key, size);
  36. ++(*nmemb);
  37. }
  38. return (p);
  39. }
  40. #endif