[notmuch] [PATCH] Add tests to configure script to detect strndup and getline

Jeffrey C. Ollie jeff at ocjtech.us
Mon Nov 23 10:14:15 PST 2009


Add some simple tests to the configure script to detect strndup and
getline.  It's not important that the tests run, just that they
compile and link without any errors.

Signed-off-by: Jeffrey C. Ollie <jeff at ocjtech.us>
---
 configure     |   20 +++++++++++++++++++-
 getlinetest.c |   13 +++++++++++++
 strnduptest.c |   10 ++++++++++
 3 files changed, 42 insertions(+), 1 deletions(-)
 create mode 100644 getlinetest.c
 create mode 100644 strnduptest.c

diff --git a/configure b/configure
index b4770ec..44c1700 100755
--- a/configure
+++ b/configure
@@ -118,6 +118,24 @@ EOF
     exit 1
 fi
 
+if ! gcc -o strnduptest strnduptest.c > /dev/null 2>&1
+then
+    echo "Checking for strndup... No."
+    strndup=-Dstrndup=_notmuch_strndup
+else
+    echo "Checking for strndup... Yes."
+fi
+rm -f strnduptest
+
+if ! gcc -o getlinetest getlinetest.c > /dev/null 2>&1
+then
+    echo "Checking for getline... No."
+    getline=-Dgetline=_notmuch_getline
+else
+    echo "Checking for getline... Yes."
+fi
+rm -f getlinetest
+
 cat <<EOF
 
 All required packages were found. You may now run the following
@@ -132,5 +150,5 @@ EOF
 cat > Makefile.config <<EOF
 prefix = /usr/local
 bash_completion_dir = /etc/bash_completion.d
-CFLAGS += ${have_valgrind}
+CFLAGS += ${have_valgrind} ${strndup} ${getline}
 EOF
diff --git a/getlinetest.c b/getlinetest.c
new file mode 100644
index 0000000..2a21a50
--- /dev/null
+++ b/getlinetest.c
@@ -0,0 +1,13 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+
+int main()
+{
+  ssize_t count = 0;
+  size_t n = 0;
+  char **lineptr = NULL;
+  FILE *stream = NULL;
+
+  count = getline(lineptr, &n, stream);
+}
diff --git a/strnduptest.c b/strnduptest.c
new file mode 100644
index 0000000..97c7c80
--- /dev/null
+++ b/strnduptest.c
@@ -0,0 +1,10 @@
+#include <string.h>
+
+int main()
+{
+  char *d;
+  const char *s = "";
+  size_t n = 0;
+
+  d = strndup(s, n);
+}
-- 
1.6.5.2



More information about the notmuch mailing list