lsearch.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. libc_hidden_proto(lfind)
  14. #ifdef L_lfind
  15. void *lfind(const void *key, const void *base, size_t *nmemb,
  16. size_t size, int (*compar)(const void *, const void *))
  17. {
  18. register int n = *nmemb;
  19. while (n--) {
  20. if ((*compar) (base, key) == 0)
  21. return ((void*)base);
  22. base += size;
  23. }
  24. return (NULL);
  25. }
  26. libc_hidden_def(lfind)
  27. #endif
  28. #ifdef L_lsearch
  29. libc_hidden_proto(memcpy)
  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