summaryrefslogtreecommitdiff
path: root/libc/misc/search/lsearch.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-12-02 16:20:50 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-12-02 16:20:50 +0000
commit0de7f32b93af44a9ae3b5126b1ec5558fd51e14f (patch)
tree1f75d7d4c61c262ffe0a0bb5a2f7915749a5339b /libc/misc/search/lsearch.c
parentbf10e6efd441bcd261c325323dda0957d529abf5 (diff)
Add hsearch and hsearch_r. Consolidate all functions prototyped in
search.h in one directory.
Diffstat (limited to 'libc/misc/search/lsearch.c')
-rw-r--r--libc/misc/search/lsearch.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libc/misc/search/lsearch.c b/libc/misc/search/lsearch.c
new file mode 100644
index 000000000..2a9996d47
--- /dev/null
+++ b/libc/misc/search/lsearch.c
@@ -0,0 +1,46 @@
+/*
+ * This file lifted in toto from 'Dlibs' on the atari ST (RdeBath)
+ *
+ *
+ * Dale Schumacher 399 Beacon Ave.
+ * (alias: Dalnefre') St. Paul, MN 55104
+ * dal@syntel.UUCP United States of America
+ * "It's not reality that's important, but how you perceive things."
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <search.h>
+
+#ifdef L_lfind
+
+void *lfind(const void *key, const void *base, size_t *nmemb,
+ size_t size, int (*compar)(const void *, const void *))
+{
+ register int n = *nmemb;
+
+ while (n--) {
+ if ((*compar) (base, key) == 0)
+ return ((void*)base);
+ base += size;
+ }
+ return (NULL);
+}
+
+#endif
+
+#ifdef L_lsearch
+
+void *lsearch(const void *key, void *base, size_t *nmemb,
+ size_t size, int (*compar)(const void *, const void *))
+{
+ register char *p;
+
+ if ((p = lfind(key, base, nmemb, size, compar)) == NULL) {
+ p = memcpy((base + (size * (*nmemb))), key, size);
+ ++(*nmemb);
+ }
+ return (p);
+}
+
+#endif