Declare ctime_r on Mac OS
authorRoman Leshchinskiy <rl@cse.unsw.edu.au>
Thu, 6 Sep 2007 00:16:13 +0000 (00:16 +0000)
committerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Thu, 6 Sep 2007 00:16:13 +0000 (00:16 +0000)
On Mac OS, ctime_r is not declared in time.h if _POSIX_C_SOURCE is defined. We
work around this by providing a declaration ourselves.

configure.ac
rts/RtsUtils.c

index 8dec569..cac3d38 100644 (file)
@@ -1066,6 +1066,13 @@ fi
 dnl ** check for more functions
 dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
 AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r])
+dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
+dnl ** _POSIX_C_SOURCE is defined
+AC_CHECK_DECLS([ctime_r], , ,
+[#define _POSIX_SOURCE 1
+#define _POSIX_C_SOURCE 199506L
+#include <time.h>])
+
 dnl ** For ghc/rts/gmp:
 AC_CHECK_FUNCS([getpagesize])
 
index c730d7a..0123531 100644 (file)
 #include <time.h>
 #endif
 
+/* HACK: On Mac OS X 10.4 (at least), time.h doesn't declare ctime_r with
+ *       _POSIX_C_SOURCE. If this is the case, we declare it ourselves.
+ */
+#if HAVE_CTIME_R && !HAVE_DECL_CTIME_R
+extern char *ctime_r(const time_t *, char *);
+#endif
+
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif