r18505: add configure checks for telldir() and seekdir()
authorStefan Metzmacher <metze@samba.org>
Thu, 14 Sep 2006 08:26:41 +0000 (08:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:18:40 +0000 (14:18 -0500)
telldir() is different on older OpenBSD versions
seekdir() is different Tru64

tridge: OpenBSD seems to like this replacement:-)
        while MAC OS 10 gets 134 runtime error:-(
lets wait what Tru64 will give

metze

source/lib/replace/libreplace_macros.m4
source/lib/replace/repdir.m4
source/lib/replace/repdir_getdirentries.c

index 41ec03f07ae6b8346baef17d0e22a053406ae4f8..91f816c75d0a823bf6775a664c4d061fc489f62f 100644 (file)
@@ -268,3 +268,23 @@ dnl AS_HELP_STRING is not available in autoconf 2.57, and AC_HELP_STRING is depr
 dnl in autoconf 2.59, so define AS_HELP_STRING to be AC_HELP_STRING unless it is already
 dnl defined.
 m4_ifdef([AS_HELP_STRING], , [m4_define([AS_HELP_STRING], m4_defn([AC_HELP_STRING]))])
+
+dnl check if the prototype in the header matches the given one
+dnl AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders])
+AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
+[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
+       AC_COMPILE_IFELSE([
+               AC_INCLUDES_DEFAULT
+               $5
+               $1
+               {
+                       $2
+               }
+       ],[
+               AS_TR_SH([ac_cv_c_prototype_$1])=yes
+               $3
+       ],[
+               AS_TR_SH([ac_cv_c_prototype_$1])=no
+               $4
+       ])
+)])
index 06a01964a8b1d0c997566a1b7a42a6a18676e7be..93bf4ec911189dcf41c53f791640d4ba1e6ad479 100644 (file)
@@ -14,7 +14,7 @@ if test x"$libreplace_READDIR_NEEDED" = x"yes"; then
 AC_CHECK_FUNCS(getdents)
 AC_CACHE_CHECK([for replacing readdir using getdents()],libreplace_READDIR_GETDENTS,[
        AC_TRY_RUN([
-#include "confdefs.h"
+#define _LIBREPLACE_REPLACE_H
 #include "$libreplacedir/repdir_getdents.c"
 #define test_readdir_os2_delete main
 #include "$libreplacedir/test/os2_delete.c"],
@@ -34,9 +34,26 @@ fi
 #
 if test x"$libreplace_READDIR_NEEDED" = x"yes"; then
 AC_CHECK_FUNCS(getdirentries)
+AC_VERIFY_C_PROTOTYPE([long telldir(const DIR *dir)],
+       [
+       return 0;
+       ],[
+       AC_DEFINE(TELLDIR_TAKES_CONST_DIR, 1, [Whether telldir takes a const pointer])
+       ],[],[
+       #include <dirent.h>
+       ])
+
+AC_VERIFY_C_PROTOTYPE([int seekdir(DIR *dir, long ofs)],
+       [
+       return 0;
+       ],[
+       AC_DEFINE(SEEKDIR_RETURNS_INT, 1, [Whether seekdir returns an int])
+       ],[],[
+       #include <dirent.h>
+       ])
 AC_CACHE_CHECK([for replacing readdir using getdirentries()],libreplace_READDIR_GETDIRENTRIES,[
        AC_TRY_RUN([
-#include "confdefs.h"
+#define _LIBREPLACE_REPLACE_H
 #include "$libreplacedir/repdir_getdirentries.c"
 #define test_readdir_os2_delete main
 #include "$libreplacedir/test/os2_delete.c"],
index a9c1c1ce82a5dc396ee34f5e6381c923be2dbd2c..9e4b63145cd9edf55d935396771c8156f4ae5a65 100644 (file)
@@ -48,6 +48,7 @@
   well. Contact the author.
 */
 
+#include "replace.h"
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -104,8 +105,6 @@ struct dirent *readdir(DIR *dir)
        return de;
 }
 
-#define TELLDIR_TAKES_CONST_DIR
-
 #ifdef TELLDIR_TAKES_CONST_DIR
 long telldir(const DIR *dir)
 #else
@@ -126,7 +125,11 @@ long telldir(DIR *dir)
        return d->seekpos + d->ofs;
 }
 
+#ifdef SEEKDIR_RETURNS_INT
+int seekdir(DIR *dir, long ofs)
+#else
 void seekdir(DIR *dir, long ofs)
+#endif
 {
        struct dir_buf *d = (struct dir_buf *)dir;
        long pos;
@@ -136,6 +139,9 @@ void seekdir(DIR *dir, long ofs)
        while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
                if (readdir(dir) == NULL) break;
        }
+#ifdef SEEKDIR_RETURNS_INT
+       return -1;
+#endif
 }
 
 void rewinddir(DIR *dir)