Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: fusl/src/search/lsearch.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/search/insque.c ('k') | fusl/src/search/tdestroy.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/search/lsearch.c
diff --git a/fusl/src/search/lsearch.c b/fusl/src/search/lsearch.c
new file mode 100644
index 0000000000000000000000000000000000000000..63f319223a0abcd8c9f70544c0500bcdf9a6195b
--- /dev/null
+++ b/fusl/src/search/lsearch.c
@@ -0,0 +1,31 @@
+#include <search.h>
+#include <string.h>
+
+void *lsearch(const void *key, void *base, size_t *nelp, size_t width,
+ int (*compar)(const void *, const void *))
+{
+ char (*p)[width] = base;
+ size_t n = *nelp;
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (compar(p[i], key) == 0)
+ return p[i];
+ *nelp = n+1;
+ return memcpy(p[n], key, width);
+}
+
+void *lfind(const void *key, const void *base, size_t *nelp,
+ size_t width, int (*compar)(const void *, const void *))
+{
+ char (*p)[width] = (void *)base;
+ size_t n = *nelp;
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (compar(p[i], key) == 0)
+ return p[i];
+ return 0;
+}
+
+
« no previous file with comments | « fusl/src/search/insque.c ('k') | fusl/src/search/tdestroy.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698