]> git.notmuchmail.org Git - notmuch/commitdiff
new: Detect dirent.d_type support at configure time
authorAustin Clements <amdragon@MIT.EDU>
Thu, 13 Feb 2014 06:50:59 +0000 (01:50 -0500)
committerDavid Bremner <david@tethera.net>
Fri, 14 Feb 2014 12:42:45 +0000 (08:42 -0400)
Support for dirent.d_type is OS-specific.  Previously, we used
_DIRENT_HAVE_D_TYPE to detect support for this, but this is apparently
a glic-ism (FreeBSD, for example, supports d_type, but does not define
this).  Since there's no cross-platform way to detect support for
dirent.d_type, detect it using a test compile at configure time.

compat/have_d_type.c [new file with mode: 0644]
configure
notmuch-new.c

diff --git a/compat/have_d_type.c b/compat/have_d_type.c
new file mode 100644 (file)
index 0000000..9ca6c6e
--- /dev/null
@@ -0,0 +1,10 @@
+#include <dirent.h>
+
+int main()
+{
+    struct dirent ent;
+
+    (void) ent.d_type;
+
+    return 0;
+}
index 66aaedbe19081763b2afbdacd625f6f8cd0fef11..2eaed4a1697301303d440162331bb17787b9e5a5 100755 (executable)
--- a/configure
+++ b/configure
@@ -578,6 +578,17 @@ else
 fi
 rm -f compat/have_timegm
 
+printf "Checking for dirent.d_type... "
+if ${CC} -o compat/have_d_type "$srcdir"/compat/have_d_type.c > /dev/null 2>&1
+then
+    printf "Yes.\n"
+    have_d_type="1"
+else
+    printf "No (will use stat instead).\n"
+    have_d_type="0"
+fi
+rm -f compat/have_d_type
+
 printf "Checking for standard version of getpwuid_r... "
 if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
 then
@@ -769,6 +780,9 @@ HAVE_STRCASESTR = ${have_strcasestr}
 # build its own version)
 HAVE_STRSEP = ${have_strsep}
 
+# Whether struct dirent has d_type (if not, then notmuch will use stat)
+HAVE_D_TYPE = ${have_d_type}
+
 # Whether the Xapian version in use supports compaction
 HAVE_XAPIAN_COMPACT = ${have_xapian_compact}
 
@@ -829,6 +843,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
                   \$(VALGRIND_CFLAGS)                                   \\
                   -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                 \\
                   -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\
+                  -DHAVE_D_TYPE=\$(HAVE_D_TYPE)                         \\
                   -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\
                   -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\
                   -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)         \\
@@ -839,6 +854,7 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
                     \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\
                     -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)               \\
                     -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\
+                    -DHAVE_D_TYPE=\$(HAVE_D_TYPE)                       \\
                     -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\
                     -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\
                     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\
index cd744891c2439982ac3851435aa66ea1ed7e07fa..8529fdd3eac7e4214c47ef24317bed961b2912b5 100644 (file)
@@ -173,7 +173,7 @@ dirent_type (const char *path, const struct dirent *entry)
     char *abspath;
     int err, saved_errno;
 
-#ifdef _DIRENT_HAVE_D_TYPE
+#if HAVE_D_TYPE
     /* Mapping from d_type to stat mode_t.  We omit DT_LNK so that
      * we'll fall through to stat and get the real file type. */
     static const mode_t modes[] = {