_lsearch.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 *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) (key, base) == 0)
  20. return ((void*)base);
  21. base += size;
  22. }
  23. return (NULL);
  24. }
  25. libc_hidden_def(lfind)
  26. #endif
  27. #ifdef L_lsearch
  28. void *lsearch(const void *key, void *base, size_t *nmemb,
  29. size_t size, int (*compar)(const void *, const void *))
  30. {
  31. register char *p;
  32. if ((p = lfind(key, base, nmemb, size, compar)) == NULL) {
  33. p = memcpy((base + (size * (*nmemb))), key, size);
  34. ++(*nmemb);
  35. }
  36. return (p);
  37. }
  38. #endif