[systemd-commits] 2 commits - .gitignore src/shared

Kay Sievers kay at kemper.freedesktop.org
Mon Oct 22 05:34:43 PDT 2012


 .gitignore        |    1 +
 src/shared/util.c |   24 ++++++++++++++++++++++++
 src/shared/util.h |    4 ++++
 3 files changed, 29 insertions(+)

New commits:
commit b87377fca3c938303a2fb25229abf8c14814841b
Author: Kay Sievers <kay at vrfy.org>
Date:   Mon Oct 22 14:33:35 2012 +0200

    update .gitignore

diff --git a/.gitignore b/.gitignore
index 123873a..84c5e14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,7 @@
 /test-strv
 /systemd-ac-power
 /systemd-timestamp
+/systemd-coredumpctl
 /systemd-cryptsetup
 /systemd-cryptsetup-generator
 /systemd-tty-ask-password-agent

commit a9e12476ed32256690eb801099c41526834b6390
Author: Kay Sievers <kay at vrfy.org>
Date:   Mon Oct 22 14:31:46 2012 +0200

    util: add (x)bsearch_r(), the missing counterpart of qsort_r()

diff --git a/src/shared/util.c b/src/shared/util.c
index 42a2e27..2f0aba8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6069,3 +6069,27 @@ finish:
 
         return 0;
 }
+
+/* hey glibc, APIs with callbacks without a user pointer are so useless */
+void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
+                 int (*compar) (const void *, const void *, void *),
+                 void *arg) {
+        size_t l, u, idx;
+        const void *p;
+        int comparison;
+
+        l = 0;
+        u = nmemb;
+        while (l < u) {
+                idx = (l + u) / 2;
+                p = (void *)(((const char *) base) + (idx * size));
+                comparison = compar(key, p, arg);
+                if (comparison < 0)
+                        u = idx;
+                else if (comparison > 0)
+                        l = idx + 1;
+                else
+                        return (void *)p;
+        }
+        return NULL;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 77d2875..a9c39b8 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -563,3 +563,7 @@ bool filename_is_safe(const char *p);
 bool string_is_safe(const char *p);
 
 int parse_timestamp(const char *t, usec_t *usec);
+
+void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
+                 int (*compar) (const void *, const void *, void *),
+                 void *arg);



More information about the systemd-commits mailing list