• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

The MinGW.org Windows System Libraries


Commit MetaInfo

Revision2d24930930ca530a8b9e6b4fb892cf15562fce4a (tree)
Time2018-02-24 04:51:52
AuthorKeith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Correct <sys/timeb.h> 32-bit vs. 64-bit time_t anomalies.

Change Summary

Incremental Difference

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,5 +1,33 @@
11 2018-02-22 Keith Marshall <keith@users.osdn.me>
22
3+ Correct <sys/timeb.h> 32-bit vs. 64-bit time_t anomalies.
4+
5+ * include/sys/timeb.h: Assert copyright; tidy layout.
6+ (_TIMEB_H_): Original multiple inclusion guard macro; rename it...
7+ (_SYS_TIMEB_H): ...conforming to this preferred naming convention.
8+ (GCC system_header): Add pragma, asserting it as such a header.
9+ (__need_time_t): Define for selective <sys/types.h> inclusion.
10+ (_BEGIN_C_DECLS, _END_C_DECLS): Use them as appropriate.
11+ (pragma pack): Push to pack all structs with 2-byte alignment.
12+ (struct timeb): Mark as deprecated, from POSIX.1-2001 onwards.
13+ (ftime): Likewise, mark as deprecated; always emulate it by in-line
14+ redirection to _ftime(), however this may be implemented.
15+ (struct __timeb32): Make its definition unconditionally visible.
16+ (_ftime32) [__MSVCRT_VERSION__ >= __MSVCR80_DLL]: Declare prototype.
17+ (_ftime32) [_WIN64 || _WIN32_WINNT >= _WIN32_WINNT_VISTA]: Likewise,
18+ otherwise emulate it by in-line redirection to 32-bit _ftime().
19+ (struct __timeb64, _ftime64): Make visibility condition symbolic...
20+ [__MSVCRT_VERSION__ >= __MSVCR61_DLL]: ...thus; add visibility for...
21+ [_WIN64 || _WIN32_WINNT >= _WIN32_WINNT_WIN2K]: ...these alternatives.
22+ (_ftime) [__MSVCRT_VERSION__ < __MSVCR80_DLL]: Declare prototype.
23+ (_ftime) [__MSVCRT_VERSION__ >= __MSVCR80_DLL]: Emulate it...
24+ [_USE_32BIT_TIME_T]: ...by in-line redirection to _ftime32(), else...
25+ [!_USE_32BIT_TIME_T]: ...to _ftime64().
26+
27+ * tests/headers.at [sys/timeb.h]: Suppress "deprecated" warnings.
28+
29+2018-02-22 Keith Marshall <keith@users.osdn.me>
30+
331 Correct Windows version support for <utime.h> functions.
432
533 * include/sys/utime.h: Tidy layout; assert copyright.
--- a/mingwrt/include/sys/timeb.h
+++ b/mingwrt/include/sys/timeb.h
@@ -1,97 +1,175 @@
11 /*
2- * timeb.h
3- * This file has no copyright assigned and is placed in the Public Domain.
4- * This file is a part of the mingw-runtime package.
5- * No warranty is given; refer to the file DISCLAIMER within the package.
2+ * sys/timeb.h
63 *
7- * Support for the UNIX System V ftime system call.
4+ * Support for the UNIX System V ftime() system call, and its various
5+ * Microsoft counterparts.
6+ *
7+ *
8+ * $Id$
9+ *
10+ * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
11+ * Copyright (C) 1997-2001, 2003, 2004, 2007, 2018, MinGW.org Project
12+ *
13+ *
14+ * Permission is hereby granted, free of charge, to any person obtaining a
15+ * copy of this software and associated documentation files (the "Software"),
16+ * to deal in the Software without restriction, including without limitation
17+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18+ * and/or sell copies of the Software, and to permit persons to whom the
19+ * Software is furnished to do so, subject to the following conditions:
20+ *
21+ * The above copyright notice and this permission notice (including the next
22+ * paragraph) shall be included in all copies or substantial portions of the
23+ * Software.
24+ *
25+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31+ * DEALINGS IN THE SOFTWARE.
832 *
933 */
34+#ifndef _SYS_TIMEB_H
35+#pragma GCC system_header
36+#define _SYS_TIMEB_H
1037
11-#ifndef _TIMEB_H_
12-#define _TIMEB_H_
13-
14-/* All the headers include this file. */
1538 #include <_mingw.h>
39+#define __need_time_t 1
1640 #include <sys/types.h>
41+#undef __need_time_t
1742
18-#ifndef RC_INVOKED
43+#ifndef RC_INVOKED
1944
20-/*
21- * TODO: Structure not tested.
45+/* Tests conducted on 32-bit Win7 indicate that all timeb structs,
46+ * on Win32 hosts, are packed with 2-byte alignment.
47+ *
48+ * FIXME: Is this also true for Win64 hosts?
49+ */
50+#pragma pack( push, 2 )
51+
52+#ifndef _NO_OLDNAMES
53+/* This is the standard POSIX/Unix System V API declaration; this
54+ * API was declared as deprecated in POSIX.1-2001, and subsequently
55+ * deleted from POSIX.1-2008 onwards.
56+ */
57+struct __POSIX_2001_DEPRECATED timeb
58+{ time_t time;
59+ short millitm;
60+ short timezone;
61+ short dstflag;
62+};
63+#endif
64+/* Microsoft's equivalent of the above uses their typically ugly
65+ * underscore decorated name; in common with the POSIX variant, it
66+ * is susceptible to bugs resulting from time_t ambiguity, which
67+ * is endemic within non-free MSVCR80.DLL and later.
2268 */
2369 struct _timeb
24-{
25- time_t time;
26- short millitm;
27- short timezone;
28- short dstflag;
70+{ time_t time;
71+ short millitm;
72+ short timezone;
73+ short dstflag;
2974 };
3075
31-#if __MSVCRT_VERSION__ >= 0x0800
32-/*
33- * TODO: Structure not tested.
76+/* To avoid time_t ambiguity, the following is equivalent to struct
77+ * _timeb, with explicitly 32-bit time_t; strictly, Microsoft didn't
78+ * support this, on 32-bit Windows, until non-free MSVCR80.DLL, or
79+ * universally from Win-Vista onwards; we make it unconditionally
80+ * available, and back-port its associated _ftime32() function
81+ * for use on legacy Win32 hosts.
3482 */
3583 struct __timeb32
36-{
37- __time32_t time;
38- short millitm;
39- short timezone;
40- short dstflag;
84+{ __time32_t time;
85+ short millitm;
86+ short timezone;
87+ short dstflag;
4188 };
42-#endif /* __MSVCRT_VERSION__ >= 0x0800 */
4389
44-#ifndef _NO_OLDNAMES
45-/*
46- * TODO: Structure not tested.
90+#pragma pack( pop )
91+
92+_BEGIN_C_DECLS
93+
94+#if defined _WIN64 /* Always supported on Win64; otherwise... */ \
95+ || __MSVCRT_VERSION__ >= __MSVCR61_DLL || _WIN32_WINNT >= _WIN32_WINNT_WIN2K
96+/* The _ftime64() function, and its associated struct __timeb64 data type, were
97+ * first introduced in the non-free MSVCR61.DLL runtime, and subsequently, they
98+ * were retrofitted to MSVCRT.DLL from Win2K onwards.
4799 */
48-struct timeb
49-{
50- time_t time;
51- short millitm;
52- short timezone;
53- short dstflag;
100+#pragma pack( push, 2 )
101+
102+struct __timeb64
103+{ __time64_t time;
104+ short millitm;
105+ short timezone;
106+ short dstflag;
54107 };
55-#endif
56108
57-#ifdef __cplusplus
58-extern "C" {
59-#endif
109+#pragma pack( pop )
60110
61-/* TODO: Not tested. */
62-_CRTIMP void __cdecl __MINGW_NOTHROW _ftime (struct _timeb*);
111+_CRTIMP __cdecl __MINGW_NOTHROW void _ftime64 (struct __timeb64 *);
63112
64-#ifndef _NO_OLDNAMES
65-/* FIXME for __MSVCRT_VERSION__ >= 0x0800 */
66-_CRTIMP void __cdecl __MINGW_NOTHROW ftime (struct timeb*);
67-#endif /* Not _NO_OLDNAMES */
113+#endif /* _WIN64 || __MSVCR61_DLL || _WIN32_WINNT_WIN2K and later */
68114
69-/* This requires newer versions of msvcrt.dll (6.10 or higher). */
70-#if __MSVCRT_VERSION__ >= 0x0601
71-struct __timeb64
72-{
73- __time64_t time;
74- short millitm;
75- short timezone;
76- short dstflag;
77-};
115+#if __MSVCRT_VERSION__ < __MSVCR80_DLL
116+/* Non-free MSVCR80.DLL, and later, don't povide _ftime() directly;
117+ * (it must be emulated); when NOT using any of these non-free DLLs,
118+ * we may import it from MSVCRT.DLL
119+ */
120+_CRTIMP __cdecl __MINGW_NOTHROW void _ftime (struct _timeb *);
121+#endif /* !__MSVCR80_DLL or later */
122+
123+#if defined _WIN64 /* Also always supported on Win64, but... */ \
124+ || __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
125+/* Conversely, the complementary _ftime32() function, and its associated struct
126+ * __timeb32 data type, were not introduced until non-free MSVCR80.DLL runtime,
127+ * nor retrofitted to MSVCRT.DLL until Win-Vista onwards.
128+ */
129+_CRTIMP __cdecl __MINGW_NOTHROW void _ftime32 (struct __timeb32 *);
78130
79-_CRTIMP void __cdecl __MINGW_NOTHROW _ftime64 (struct __timeb64*);
80-#endif /* __MSVCRT_VERSION__ >= 0x0601 */
131+#else /* !(_WIN64 || __MSVCR80_DLL || _WIN32_WINNT_VISTA and later) */
132+/* This is a legacy _WIN32 system, pre-Win-Vista, and NOT using MSVCR80.DLL,
133+ * or later; it is convenient for us to emulate _ftime32(), by the expedient
134+ * of mapping it to the legacy 32-bit _ftime() implementation.
135+ */
136+__CRT_ALIAS __cdecl __MINGW_NOTHROW
137+void _ftime32 (struct __timeb32 *__t) {_ftime ((struct _timeb *)(__t));}
81138
82-#if __MSVCRT_VERSION__ >= 0x0800
83-_CRTIMP void __cdecl __MINGW_NOTHROW _ftime32 (struct __timeb32*);
84-#ifndef _USE_32BIT_TIME_T
85-_CRTALIAS void __cdecl __MINGW_NOTHROW _ftime (struct _timeb* _v) { return(_ftime64 ((struct __timeb64*)_v)); }
86-#else
87-_CRTALIAS void __cdecl __MINGW_NOTHROW _ftime (struct _timeb* _v) { return(_ftime32 ((struct __timeb32*)_v)); }
88-#endif
89-#endif /* __MSVCRT_VERSION__ >= 0x0800 */
139+#endif /* !(_WIN64 || __MSVCR80_DLL || _WIN32_WINNT_VISTA and later) */
90140
91-#ifdef __cplusplus
92-}
93-#endif
141+#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
142+/* When linking with any non-free runtime, from MSVCR80.DLL onwards,
143+ * we must emulate _ftime(), by redirection to either _ftime32(), or
144+ * _ftime64(), depending on (error prone) user feature selection...
145+ */
146+# ifdef _USE_32BIT_TIME_T
147+ /* ...of an API with an explicitly 32-bit time_t...
148+ */
149+__CRT_ALIAS __cdecl __MINGW_NOTHROW
150+void _ftime (struct _timeb * __t) {_ftime32 ((struct __timeb32*)__t);}
151+
152+# else
153+ /* ...or the Microsoft default, (incompatible with 32-bit MSVCRT.DLL,
154+ * and not consistently implemented within all 32-bit WinAPI modules),
155+ * 64-bit time_t
156+ */
157+__CRT_ALIAS __cdecl __MINGW_NOTHROW
158+void _ftime (struct _timeb * __t) {_ftime64 ((struct __timeb64*)__t);}
159+
160+# endif /* !_USE_32BIT_TIME_T */
161+#endif /* __MSVCR80_DLL and later */
162+
163+#ifndef _NO_OLDNAMES
164+/* Regardless of how the _ftime() function may be implemented, we provide
165+ * the deprecated POSIX.1 equivalent API, by in-line mapping of the ftime()
166+ * function to that _ftime() implementation.
167+ */
168+__CRT_ALIAS __cdecl __MINGW_NOTHROW __POSIX_2001_DEPRECATED
169+void ftime (struct timeb *__t) {_ftime ((struct _timeb *)(__t)); }
170+#endif /* !_NO_OLDNAMES */
94171
95-#endif /* Not RC_INVOKED */
172+_END_C_DECLS
96173
97-#endif /* Not _TIMEB_H_ */
174+#endif /* ! RC_INVOKED */
175+#endif /* !_SYS_TIMEB_H: $RCSfile$: end of file */
--- a/mingwrt/tests/headers.at
+++ b/mingwrt/tests/headers.at
@@ -115,6 +115,7 @@ m4_foreach_w([HEADER],MINGWRT_AT_PACKAGE_HEADERS,[dnl
115115 AT_SETUP([#include <]HEADER[>])AT_KEYWORDS([$1 $1-headers])
116116 AS_VAR_APPEND([CPPFLAGS],[" -Wall -Wextra -Wsystem-headers"])
117117 m4_if(HEADER,[unistd.h],AS_VAR_APPEND([CPPFLAGS],[" -Wno-deprecated-declarations"]))
118+m4_if(HEADER,[sys/timeb.h],AS_VAR_APPEND([CPPFLAGS],[" -Wno-deprecated-declarations"]))
118119 m4_if(HEADER,[sys/stat.h],AS_VAR_APPEND([CPPFLAGS],[" -D_MINGW_S_IFBLK_KLUDGE"]))
119120 MINGW_AT_CHECK_COMPILE([dnl
120121 #define __IN_MINGWRT_TESTSUITE__ 1
@@ -136,7 +137,7 @@ m4_foreach([LANG],[C,C++],[MINGWRT_AT_CHECK_HEADERS_STANDALONE(LANG)])
136137 m4_define([MINGWRT_AT_CHECK_HEADERS_COMBINED],[MINGW_AT_LANG([$1])dnl
137138 AT_SETUP([#include all; language = $1])AT_KEYWORDS([$1 $1-headers])
138139 AS_VAR_APPEND([CPPFLAGS],[" -Wall -Wextra -Wsystem-headers"])
139-m4_if([$1],[C],AS_VAR_APPEND([CPPFLAGS],[" -Wno-deprecated-declarations"]))
140+AS_VAR_APPEND([CPPFLAGS],[" -Wno-deprecated-declarations"])
140141 MINGW_AT_CHECK_COMPILE([dnl
141142 #define _MINGW_S_IFBLK_KLUDGE 1
142143 #define __IN_MINGWRT_TESTSUITE__ 1