[project @ 2004-09-01 15:57:13 by ross]
[ghc-base.git] / aclocal.m4
1 dnl @synopsis FP_READDIR_EOF_ERRNO
2 dnl
3 dnl Check what readdir() sets 'errno' to upon reaching 
4 dnl end of directory; not setting it is the correct thing to do,
5 dnl but mingw based versions have set it to ENOENT until recently
6 dnl (summer 2004).
7 dnl
8 dnl
9 AC_DEFUN(FP_READDIR_EOF_ERRNO,
10 [AC_CACHE_CHECK([what readdir sets errno to upon EOF], fptools_cv_readdir_eof_errno,
11 [AC_TRY_RUN([#include <dirent.h>
12 #include <stdio.h>
13 #include <errno.h>
14 int
15 main(argc, argv)
16 int argc;
17 char **argv;
18 {
19   FILE *f=fopen("conftestval", "w");
20 #if defined(__MINGW32__)
21   int fd = mkdir("testdir");
22 #else
23   int fd = mkdir("testdir", 0666);
24 #endif
25   DIR* dp;
26   struct dirent* de;
27   int err = 0;
28
29   if (!f) return 1;
30   if (fd == -1) { 
31      fprintf(stderr,"unable to create directory; quitting.\n");
32      return 1;
33   }
34   close(fd);
35   dp = opendir("testdir");
36   if (!dp) { 
37      fprintf(stderr,"unable to browse directory; quitting.\n");
38      rmdir("testdir");
39      return 1;
40   }
41
42   /* the assumption here is that readdir() will only return NULL
43    * due to reaching the end of the directory.
44    */
45   while (de = readdir(dp)) {
46         ;
47   }
48   err = errno;
49   fprintf(f,"%d", err);
50   fclose(f);
51   closedir(de);
52   rmdir("testdir");
53   return 0;
54 }],fptools_cv_readdir_eof_errno=`cat conftestval`, fptools_cv_readdir_eof_errno=bogus, fptools_cv_readdir_eof_errno=0)])
55 dnl the cross value is somewhat bogus.
56 AC_DEFINE_UNQUOTED([READDIR_ERRNO_EOF], [$fptools_cv_readdir_eof_errno], [readdir() sets errno to this upon EOF])
57 ])
58
59 dnl @synopsis FP_DIRENT_FLAT_LAYOUT
60 dnl
61 dnl Check whether 'struct dirent' (in dirent.h) has d_name defined
62 dnl as being the final field in a struct, or a pointer to somewhere
63 dnl else. The former is the standardly thing to do, but mingw defns
64 dnl have for the longest time gone for the latter. They no longer do,
65 dnl hence the need to configure test for this.
66 dnl
67 dnl
68 AC_DEFUN(FP_DIRENT_FLAT_LAYOUT,
69 [AC_CACHE_CHECK([if struct dirent layout is flat], fptools_cv_dirent_flat_layout,
70 [AC_TRY_RUN([#include <dirent.h>
71 #include <stdio.h>
72 #include <string.h>
73 int
74 main(argc, argv)
75 int argc;
76 char **argv;
77 {
78   struct dirent de;
79   /*
80    * Check whether d_name is defined as
81    *    struct dirent { .... ; char d_name[..]; } 
82    * or
83    *    struct dirent { .... ; char* d_name; } 
84    * 
85    * Returns 0 if the former.
86    */
87   memset(&de,0,sizeof(struct dirent));
88   return ((int)de.d_name == 0);
89 }],fptools_cv_dirent_flat_layout=yes, fptools_cv_dirent_flat_layout=no, fptools_cv_dirent_flat_layout=yes)])
90 dnl the cross value is somewhat bogus.
91 if test "$fptools_cv_dirent_flat_layout" = yes; then
92 AC_DEFINE([STRUCT_DIRENT_FLAT_LAYOUT], [1], [Define to 1 if struct dirent is a flat structure])
93 fi
94 ])