Tcl Source Code

Artifact [97e8041bff]
Login

Artifact 97e8041bff00af5d83c601eb12bc70c2679b87dd:

Attachment "use-32bit-time-t-debacle.diff" to ticket [3571241fff] added by earnie 2013-05-22 04:28:53.
diff --git a/include/_mingw.h b/include/_mingw.h
index 821a872..07d950a 100644
--- a/include/_mingw.h
+++ b/include/_mingw.h
@@ -243,6 +243,33 @@
 # endif
 #endif
 
+/*
+ * We need to set a default MSVCRT_VERSION which describes the MSVCRT.DLL on
+ * the users system.  We are defaulting to XP but we recommend the user define
+ * this in his config.h or Makefile file based on the minimum supported version
+ * of OS for his program.
+ * ME = 600
+ * XP = 710
+ * VISTA = 800
+ * WIN7 = 900
+ * WIN8 = 1010
+ */
+#ifndef MSVCRT_VERSION
+#define MSVCRT_VERSION 710
+#endif
+
+#ifdef _USE_32BIT_TIME_T
+#if MSVCRT_VERSION < 800
+#warning Your MSVCRT_VERSION does not support the use of _USE_32BIT_TIME_T.
+#warning You should define MSVCRT_VERSION based on your MSVCRT.DLL version.
+#warning ME = 600, XP = 710, VISTA = 800, WIN7 = 900 and WIN8 = 1010.
+#endif /* MSVCRT_VERSION < 800 */
+#else
+#if MSVCRT_VERSION >= 800
+#define _USE_32BIT_TIME_T 1
+#endif /* MSVCRT_VERSION >= 800 */
+#endif /* _USE_32BIT_TIME_T */
+
 struct threadlocalinfostruct;
 struct threadmbinfostruct;
 typedef struct threadlocalinfostruct *pthreadlocinfo;
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 3d7ce9a..3e639a8 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -110,34 +110,38 @@ struct _stat32
 	__time32_t st_ctime;	/* Creation time */
 };
 
+#ifndef __STRICT_ANSI__
+struct stat {
+	_dev_t	   st_dev;	/* Equivalent to drive number 0=A 1=B ... */
+	_ino_t	   st_ino;	/* Always zero ? */
+	_mode_t    st_mode;	/* See above constants */
+	short	   st_nlink;	/* Number of links. */
+	short	   st_uid;	/* User: Maybe significant on NT ? */
+	short	   st_gid;	/* Group: Ditto */
+	_dev_t	   st_rdev;	/* Seems useless (not even filled in) */
+	_off_t	   st_size;	/* File size in bytes */
+	time_t	   st_atime;	/* Accessed date (always 00:00 hrs local
+				 * on FAT) */
+	time_t	   st_mtime;	/* Modified time */
+	time_t	   st_ctime;	/* Creation time */	
+};
+#endif /* __STRICT_ANSI__ */
+
 struct _stat64 {
-	dev_t	st_dev;		/* Equivalent to drive number 0=A 1=B ... */
-	ino_t	st_ino;		/* Always zero ? */
-	mode_t	st_mode;	/* See above constants */
-	short	st_nlink;	/* Number of links. */
-	short	st_uid;		/* User: Maybe significant on NT ? */
-	short	st_gid;		/* Group: Ditto */
-	dev_t	st_rdev;	/* Seems useless (not even filled in) */
-	__int64 st_size;	/* File size in bytes */
+	dev_t	   st_dev;	/* Equivalent to drive number 0=A 1=B ... */
+	ino_t	   st_ino;	/* Always zero ? */
+	mode_t	   st_mode;	/* See above constants */
+	short	   st_nlink;	/* Number of links. */
+	short	   st_uid;	/* User: Maybe significant on NT ? */
+	short	   st_gid;	/* Group: Ditto */
+	dev_t	   st_rdev;	/* Seems useless (not even filled in) */
+	_off64_t   st_size;	/* File size in bytes */
 	__time64_t st_atime;	/* Accessed date (always 00:00 hrs local
 				 * on FAT) */
 	__time64_t st_mtime;	/* Modified time */
 	__time64_t st_ctime;	/* Creation time */
 };
 
-struct _stati64 {
-    _dev_t st_dev;
-    _ino_t st_ino;
-    _mode_t st_mode;
-    short st_nlink;
-    short st_uid;
-    short st_gid;
-    _dev_t st_rdev;
-    __int64 st_size;
-    time_t st_atime;
-    time_t st_mtime;
-    time_t st_ctime;
-};
 struct _stat32i64 {
 	_dev_t		st_dev;
 	_ino_t		st_ino;
@@ -146,11 +150,12 @@ struct _stat32i64 {
 	short		st_uid;
 	short		st_gid;
 	_dev_t		st_rdev;
-	__int64		st_size;
+	_off64_t	st_size;
 	__time32_t	st_atime;
 	__time32_t	st_mtime;
 	__time32_t	st_ctime;
 };
+
 struct _stat64i32 {
 	_dev_t		st_dev;
 	_ino_t		st_ino;
@@ -159,14 +164,14 @@ struct _stat64i32 {
 	short		st_uid;
 	short		st_gid;
 	_dev_t		st_rdev;
-	__int32		st_size;
+	_off_t		st_size;
 	__time64_t	st_atime;
 	__time64_t	st_mtime;
 	__time64_t	st_ctime;
 };
 
 #define __stat64 _stat64
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 #define _fstat      _fstat32
 #define _fstati64   _fstat32i64
 #define _stat       _stat32
@@ -243,13 +248,6 @@ int __cdecl __MINGW_NOTHROW _fstat64i32 (int, struct _stat64i32*);
 #endif
 
 #if !defined(_NO_OLDNAMES) && !defined(__STRICT_ANSI__)
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
-#define stat(a,b) _stat32(a,b)
-#define fstat(a,b) _fstat32(a,b)
-#else
-#define stat(a,b) _stat64i32(a,b)
-#define fstat(a,b) _fstat64i32(a,b)
-#endif
 #define stat _stat
 #define fstat _fstat
 #endif /* !defined(_NO_OLDNAMES) && !defined(__STRICT_ANSI__) */
@@ -286,7 +284,7 @@ int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*);
 #define _wstat64i32 _wstat64
 #endif
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 #define _wstat      _wstat32
 #define _wstati64   _wstat32i64
 #else /* !_USE_32BIT_TIME_T */
diff --git a/include/sys/timeb.h b/include/sys/timeb.h
index a1c6f1e..27be61d 100644
--- a/include/sys/timeb.h
+++ b/include/sys/timeb.h
@@ -93,7 +93,7 @@ _CRTIMP void __cdecl __MINGW_NOTHROW	_ftime64 (struct __timeb64*);
 
 _CRTIMP void __cdecl __MINGW_NOTHROW	_ftime32 (struct __timeb32*);
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 _CRTALIAS void __cdecl __MINGW_NOTHROW	_ftime (struct _timeb* _v) { return(_ftime32 ((struct __timeb32*)_v)); }
 #else
 
diff --git a/include/sys/types.h b/include/sys/types.h
index 9e12770..2784c5e 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -48,7 +48,7 @@ typedef __int64 __time64_t;
 #ifndef _TIME_T_DEFINED
 /* FIXME __STRICT_ANSI__ ! */
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 typedef	__time32_t time_t;
 #else
 
@@ -61,9 +61,18 @@ typedef	__time64_t time_t;
 #ifndef	_OFF_T_
 #define	_OFF_T_
 typedef long _off_t;
+#ifndef __STRICT_ANSI__
 typedef _off_t	off_t;
+#endif /* __STRICT_ANSI__ */
 #endif	/* Not _OFF_T_ */
 
+#ifndef _OFF64_T_
+#define _OFF64_T_
+typedef __int64 _off64_t;
+#ifndef __STRICT_ANSI__
+typedef __int64 off64_t;
+#endif /* __STRICT_ANSI__ */
+#endif /* ndef _OFF64_T */
 
 #ifndef _DEV_T_
 #define	_DEV_T_
diff --git a/include/time.h b/include/time.h
index 43bee23..536478d 100644
--- a/include/time.h
+++ b/include/time.h
@@ -61,7 +61,7 @@ typedef __int64 __time64_t;
 #endif
 
 #ifndef _TIME_T_DEFINED
-# if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+# if defined(_USE_32BIT_TIME_T)
    typedef	__time32_t time_t;
 # else
    typedef	__time64_t time_t;
@@ -142,7 +142,8 @@ _CRTIMP char* __cdecl __MINGW_NOTHROW _ctime64 (const __time64_t*);
 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _gmtime64 (const __time64_t*);
 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _localtime64 (const __time64_t*);
 
-/* These require newer versions of msvcrt.dll (8.00 or higher). */ 
+/* These require newer versions of msvcrt.dll (8.00 or higher). */
+#ifdef MSVCRT_VERSION >= 800
 _CRTIMP __time32_t __cdecl __MINGW_NOTHROW	_time32 (__time32_t*);
 _CRTIMP double	   __cdecl __MINGW_NOTHROW	_difftime32 (__time32_t, __time32_t);
 _CRTIMP double	   __cdecl __MINGW_NOTHROW	_difftime64 (__time64_t, __time64_t);
@@ -152,8 +153,9 @@ _CRTIMP __time64_t __cdecl __MINGW_NOTHROW	_mkgmtime64 (struct tm*);
 _CRTIMP char*	   __cdecl __MINGW_NOTHROW	_ctime32 (const __time32_t*);
 _CRTIMP struct tm* __cdecl __MINGW_NOTHROW	_gmtime32 (const __time32_t*);
 _CRTIMP struct tm* __cdecl __MINGW_NOTHROW	_localtime32 (const __time32_t*);
+#endif /* MSVCRT_VERSION >= 800 */
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 _CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	time (time_t* _v)		  { return(_time32 (_v)); }
 _CRTALIAS double	   __cdecl __MINGW_NOTHROW	difftime (time_t _v1, time_t _v2) { return(_difftime32 (_v1,_v2)); }
 _CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	mktime (struct tm* _v)		  { return(_mktime32 (_v)); }
@@ -163,12 +165,16 @@ _CRTALIAS struct tm*	   __cdecl __MINGW_NOTHROW	gmtime (const time_t* _v)	  { re
 _CRTALIAS struct tm*	   __cdecl __MINGW_NOTHROW	localtime (const time_t* _v)	  { return(_localtime32 (_v)); }
 #else
 _CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	time (time_t* _v)		  { return(_time64 (_v)); }
-_CRTALIAS double	   __cdecl __MINGW_NOTHROW	difftime (time_t _v1, time_t _v2) { return(_difftime64 (_v1,_v2)); }
 _CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	mktime (struct tm* _v)		  { return(_mktime64 (_v)); }
-_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	_mkgmtime (struct tm* _v)	  { return(_mkgmtime64 (_v)); }
 _CRTALIAS char*		   __cdecl __MINGW_NOTHROW	ctime (const time_t* _v)	  { return(_ctime64 (_v)); }
 _CRTALIAS struct tm*	   __cdecl __MINGW_NOTHROW	gmtime (const time_t* _v)	  { return(_gmtime64 (_v)); }
 _CRTALIAS struct tm*	   __cdecl __MINGW_NOTHROW	localtime (const time_t* _v)	  { return(_localtime64 (_v)); }
+# if MSVCRT_VERSION >= 800
+_CRTALIAS double	   __cdecl __MINGW_NOTHROW	difftime (time_t _v1, time_t _v2) { return(_difftime64 (_v1,_v2)); }
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	_mkgmtime (struct tm* _v)	  { return(_mkgmtime64 (_v)); }
+# else /* MSVCRT_VERSION < 800
+/* TODO: Add inline versions for difftime and _mkgmtime. */
+# endif /* MSVCRT_VERSION >= 800 */
 #endif /* _USE_32BIT_TIME_T */
 
 /*
diff --git a/include/wchar.h b/include/wchar.h
index e84bf05..d63753c 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -49,11 +49,9 @@
  */
 #include <wctype.h>
 
-#ifndef	__STRICT_ANSI__
 /* This is necessary to support the the non-ANSI wchar declarations
    here. */
 #include <sys/types.h>
-#endif /* __STRICT_ANSI__ */
 
 #define WCHAR_MIN	0
 #define WCHAR_MAX	0xffff
@@ -201,7 +199,7 @@ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wstrtime (wchar_t*);
 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wctime64 (const __time64_t*);
 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wctime32 (const __time32_t*);
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 _CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW	_wctime (const time_t* _v)	{ return(_wctime32 (_v)); }
 #else
 
@@ -418,7 +416,7 @@ _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindnext64(intptr_t, struct __wfindda
 _CRTIMP long __cdecl __MINGW_NOTHROW	_wfindfirst32 (const wchar_t*, struct __wfinddata32_t*);
 _CRTIMP int  __cdecl __MINGW_NOTHROW	_wfindnext32 (long, struct __wfinddata32_t*);
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 _CRTALIAS long __cdecl __MINGW_NOTHROW	_wfindfirst (const wchar_t* _v1, struct _wfinddata_t* _v2)	 { return(_wfindfirst32 (_v1,(struct __wfinddata32_t*)_v2)); }
 _CRTALIAS int  __cdecl __MINGW_NOTHROW	_wfindnext (long _v1, struct _wfinddata_t* _v2)			 { return(_wfindnext32  (_v1,(struct __wfinddata32_t*)_v2)); }
 _CRTALIAS long __cdecl __MINGW_NOTHROW	_wfindfirsti64 (const wchar_t* _v1, struct _wfinddatai64_t* _v2) { return(_wfindfirst32i64 (_v1,(struct _wfinddata32i64_t*)_v2)); }
@@ -468,6 +466,23 @@ struct _stat32
 	__time32_t st_ctime;	/* Creation time */
 };
 
+#ifndef __STRICT_ANSI__
+struct stat {
+    _dev_t  st_dev;	/* Equivalent to drive number 0=A 1=B ... */
+    _ino_t  st_ino;	/* Always zero ? */
+    _mode_t st_mode;	/* See above constants */
+    short   st_nlink;	/* Number of links. */
+    short   st_uid;	/* User: Maybe significant on NT ? */
+    short   st_gid;	/* Group: Ditto */
+    _dev_t  st_rdev;	/* Seems useless (not even filled in) */
+    _off_t  st_size;	/* File size in bytes */
+    time_t  st_atime;	/* Accessed date (always 00:00 hrs local
+			 * on FAT) */
+    time_t  st_mtime;	/* Modified time */
+    time_t  st_ctime;	/* Creation time */
+} ;
+#endif /* __STRICT_ANSI__ */
+
 struct _stat64 {
 	dev_t	st_dev;		/* Equivalent to drive number 0=A 1=B ... */
 	ino_t	st_ino;		/* Always zero ? */
@@ -476,26 +491,13 @@ struct _stat64 {
 	short	st_uid;		/* User: Maybe significant on NT ? */
 	short	st_gid;		/* Group: Ditto */
 	dev_t	st_rdev;	/* Seems useless (not even filled in) */
-	__int64 st_size;	/* File size in bytes */
+	_off64_t st_size;	/* File size in bytes */
 	__time64_t st_atime;	/* Accessed date (always 00:00 hrs local
 				 * on FAT) */
 	__time64_t st_mtime;	/* Modified time */
 	__time64_t st_ctime;	/* Creation time */
 };
 
-struct _stati64 {
-    _dev_t st_dev;
-    _ino_t st_ino;
-    _mode_t st_mode;
-    short st_nlink;
-    short st_uid;
-    short st_gid;
-    _dev_t st_rdev;
-    __int64 st_size;
-    time_t st_atime;
-    time_t st_mtime;
-    time_t st_ctime;
-};
 struct _stat32i64 {
 	_dev_t		st_dev;
 	_ino_t		st_ino;
@@ -504,11 +506,12 @@ struct _stat32i64 {
 	short		st_uid;
 	short		st_gid;
 	_dev_t		st_rdev;
-	__int64		st_size;
+	_off64_t	st_size;
 	__time32_t	st_atime;
 	__time32_t	st_mtime;
 	__time32_t	st_ctime;
-};
+} ;
+
 struct _stat64i32 {
 	_dev_t		st_dev;
 	_ino_t		st_ino;
@@ -517,14 +520,14 @@ struct _stat64i32 {
 	short		st_uid;
 	short		st_gid;
 	_dev_t		st_rdev;
-	__int32		st_size;
+	_off_t		st_size;
 	__time64_t	st_atime;
 	__time64_t	st_mtime;
 	__time64_t	st_ctime;
 };
 
 #define __stat64 _stat64
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 #define _fstat      _fstat32
 #define _fstati64   _fstat32i64
 #define _stat       _stat32
@@ -570,7 +573,7 @@ int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*);
 #define _wstat64i32 _wstat64
 #endif
 
-#if defined(_USE_32BIT_TIME_T) && defined(_HAVE_32BIT_TIME_T)
+#if defined(_USE_32BIT_TIME_T)
 #define _wstat      _wstat32
 #define _wstati64   _wstat32i64
 #else