lsearch.c 1007 B

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