fix compile errors on readdir()-deficient platforms
authorMichael Poole <mdpoole@troilus.org>
Mon, 12 Apr 2004 03:25:03 +0000 (03:25 +0000)
committerMichael Poole <mdpoole@troilus.org>
Mon, 12 Apr 2004 03:25:03 +0000 (03:25 +0000)
* Cygwin does not have "struct dirent.d_type".  Check for that in the
configure script and use stat() to test for directory-ness instead.
git-archimport-id: srvx@srvx.net--2004-srvx/srvx--devo--1.3--patch-50

ChangeLog
configure.in
src/helpfile.c

index fb2dad97737002b9a710a7eec9139ad32ceac3ef..7433ad933beefa009d07852c3ecf9229636a9569 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--srvx@srvx.net--2004-srvx/srvx--devo--1.3
 #
 
+2004-04-12 03:25:03 GMT        Michael Poole <mdpoole@troilus.org>     patch-50
+
+    Summary:
+      fix compile errors on readdir()-deficient platforms
+    Revision:
+      srvx--devo--1.3--patch-50
+
+    * Cygwin does not have "struct dirent.d_type".  Check for that in the
+    configure script and use stat() to test for directory-ness instead.
+
+    modified files:
+     ChangeLog configure.in src/helpfile.c
+
+
 2004-04-10 23:04:21 GMT        Michael Poole <mdpoole@troilus.org>     patch-49
 
     Summary:
index 203ecfa2f2370523b7758869cabbdf55a54f46a3..26ef7dd08e71511e2bdd62c4fcdbfdba63800ce2 100644 (file)
@@ -66,7 +66,11 @@ AC_HEADER_TIME
 AC_STRUCT_TM
 
 dnl Would rather not bail on headers, BSD has alot of the functions elsewhere. -Jedi
-AC_CHECK_HEADERS(fcntl.h malloc.h netdb.h netinet/in.h sys/resource.h sys/timeb.h sys/times.h sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h unistd.h getopt.h memory.h regex.h arpa/inet.h sys/mman.h sys/stat.h,,)
+AC_CHECK_HEADERS(fcntl.h malloc.h netdb.h netinet/in.h sys/resource.h sys/timeb.h sys/times.h sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h unistd.h getopt.h memory.h regex.h arpa/inet.h sys/mman.h sys/stat.h dirent.h,,)
+
+dnl Cygwin does not have d_type in struct dirent.  We use stat() as a fallback.
+AC_CHECK_MEMBER([struct dirent.d_type],
+        [AC_DEFINE(HAVE_DIRENT_D_TYPE, 1, [Define if struct dirent exists and includes the d_type element.])],,[#include <dirent.h>])
 
 dnl portability stuff, hurray! -Jedi
 AC_CHECK_FUNCS(gettimeofday)
index 466ec33c5d09a0ffb98df0b1a9b84613fe205526..a08c7b7316f0a7abcbb3d8bb1014deb61fa25e91 100644 (file)
 #include "modcmd.h"
 #include "nickserv.h"
 
+#if defined(HAVE_DIRENT_H)
 #include <dirent.h>
+#endif
+
+#if defined(HAVE_SYS_STAT_H)
+#include <sys/stat.h>
+#endif
 
 static const struct message_entry msgtab[] = {
     { "HFMSG_MISSING_HELPFILE", "The help file could not be found.  Sorry!" },
@@ -224,8 +230,20 @@ static void language_read_list(void)
     while ((dirent = readdir(dir))) {
         if (dirent->d_name[0] == '.')
             continue;
+#ifdef HAVE_DIRENT_D_TYPE
         if (dirent->d_type != DT_DIR)
             continue;
+#else
+        {
+            char namebuf[MAXLEN];
+            struct stat sbuf;
+            snprintf(namebuf, sizeof(namebuf), "languages/%s", dirent->d_name);
+            if (stat(namebuf, &sbuf) < 0)
+                continue;
+            if (!S_ISDIR(sbuf.st_mode))
+                continue;
+        }
+#endif
         language_alloc(dirent->d_name);
     }
     closedir(dir);