OSDN Git Service

Refactor to make <parts/time.h> redundant.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Tue, 16 Feb 2016 21:54:24 +0000 (21:54 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Tue, 16 Feb 2016 21:54:24 +0000 (21:54 +0000)
mingwrt/ChangeLog
mingwrt/include/parts/time.h [deleted file]
mingwrt/include/sys/types.h
mingwrt/include/time.h

index 22ecbf7..255f86b 100644 (file)
@@ -1,5 +1,22 @@
 2016-02-16  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
+       Refactor to make <parts/time.h> redundant.
+
+       * include/sys/types.h (time_t, __time32_t, __time32_t)
+       [__need_time_t && !__have_typedef_time_t]: Reproduce definitions...
+       * include/parts/time.h: ...from here; preserve selective exposure.
+
+       * include/time.h (time_t, __time32_t, __time32_t): Get them...
+       * include/sys/types.h: ...from here, by selective inclusion.
+
+       * include/time.h (struct timespec, struct __mingw_extended_timespec)
+       [__need_struct_timespec && !__struct_timespec_defined]: Reproduce...
+       * include/parts/time.h: ...from here; preserve selective exposure.
+
+       * include/parts/time.h: Delete file; it is no longer required.
+
+2016-02-16  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
        Declare the nanosleep() function where POSIX expects it.
 
        * include/time.h (__mingw_sleep): Declare function prototype.
diff --git a/mingwrt/include/parts/time.h b/mingwrt/include/parts/time.h
deleted file mode 100644 (file)
index 7965140..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * parts/time.h
- *
- * Internal header file, declaring types and structures which nominally
- * originate from time.h, but which POSIX requires to be made visible on
- * inclusion of certain other headers, without including time.h itself.
- *
- * $Id$
- *
- * Written by Keith Marshall  <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2014, 2015, MinGW.org Project.
- *
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice, this permission notice, and the following
- * disclaimer shall be included in all copies or substantial portions of
- * the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-#if _FAKE_TIME_H_SOURCED
-/*
- * Since we expect this part-header to be sourced exclusively by other
- * system headers, (nominally time.h), we don't apply any conventional
- * multiple inclusion guard; rather, we rely on the guard within time.h
- * itself, but allow other headers to fake it for one-shot inclusion
- * only...
- */
-# undef _FAKE_TIME_H_SOURCED
-
-#elif ! defined _TIME_H
-/*
- * ...otherwise, we fail if the time.h guard is not in place.
- */
-# error "Never include <parts/time.h> directly; use <time.h> instead"
-#endif
-
-#if defined __need_time_t || defined __need_struct_timespec
-/*
- * Wherever this is included, we usually need to define time_t, and
- * its unambiguously sized variants; don't guard these, as that would
- * deny the compiler the opportunity to reject inconsistencies, when
- * defined elsewhere, (although ideally, this file should ALWAYS be
- * included where these definitions are required; do note, however,
- * that some compilers, e.g. GCC < 4.x, may reject any attempt to
- * repeat a typedef, even when it is consistently duplicated; for
- * such compilers, a conditional guard is necessary).
- */
-# if __GCC__ >= 4 || ! defined __have_typedef_time_t
-
-   typedef __int32 __time32_t; /* unambiguous 32-bit time_t */
-   typedef __int64 __time64_t; /* unambiguous 64-bit time_t */
-
-#  if __MSVCRT_VERSION__ < 0x0800 || defined _USE_32BIT_TIME_T
-   /*
-    * From MSVCR80.DLL onwards, Microsoft have royally messed up the
-    * definition of time_t; maintain POSIX consistency, unless the user
-    * is explicitly using one of these brain damaged DLL variants, and
-    * has not elected to retain the 32-bit time_t representation.
-    */
-    typedef __time32_t time_t;
-
-#  else
-   /* Microsoft's brain damaged default, from MSVCR80.DLL onwards.
-    */
-    typedef __time64_t time_t;
-#  endif
-# endif
-# if __GCC__ < 4
-   /*
-    * Assume any compiler which is not GCC-4.x or newer may require
-    * guarding against repeated time_t typedefs.
-    */
-#  define __have_typedef_time_t  1
-# endif
-#endif
-
-#if defined __need_struct_timespec && ! __struct_timespec_defined
-/*
- * Structure timespec is mandated by POSIX, for specification of
- * intervals with the greatest precision supported by the OS kernel.
- * Although this allows for specification to nanosecond precision, do
- * not be deluded into any false expectation that such short intervals
- * can be realized on Windows; on Win9x derivatives, the metronome used
- * by the process scheduler has a period of ~55 milliseconds, while for
- * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
- * the shortest intervals which can be realistically timed will range
- * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
- * with period values normally distributed around means of ~27.5 ms
- * and ~7.5 ms, for the two system types respectively.
- */
-struct timespec
-{
-  /* Period is sum of tv_sec + tv_nsec; while 32-bits is sufficient
-   * to accommodate tv_nsec, we use 64-bit __time64_t for tv_sec, to
-   * ensure that we have a sufficiently large field to accommodate
-   * Microsoft's ambiguous __time32_t vs. __time64_t representation
-   * of time_t; we may resolve this ambiguity locally, by casting a
-   * pointer to a struct timespec to point to an identically sized
-   * struct __mingw32_timespec, which is defined below.
-   */
-  __time64_t     tv_sec;       /* seconds; accept 32 or 64 bits */
-  __int32        tv_nsec;      /* nanoseconds */
-};
-
-struct __mingw32_expanded_timespec
-{
-  /* Equivalent of struct timespec, with disambiguation for the
-   * 32-bit vs. 64-bit tv_sec field declaration.  Period is the
-   * sum of tv_sec + tv_nsec; we use explicitly sized types to
-   * avoid 32-bit vs. 64-bit time_t ambiguity...
-   */
-  union
-  { /* ...within this anonymous union, allowing tv_sec to accommodate
-     * seconds expressed in either of Microsoft's (ambiguously sized)
-     * time_t representations.
-     */
-    __time64_t __tv64_sec;     /* unambiguously 64 bits */
-    __time32_t __tv32_sec;     /* unambiguously 32 bits */
-    time_t       tv_sec;       /* ambiguously 32 or 64 bits */
-  };
-  __int32        tv_nsec;      /* nanoseconds */
-};
-
-# define __struct_timespec_defined  1
-#endif
-
-/* $RCSfile$: end of file */
index 1d60619..5ad62cf 100644 (file)
@@ -42,7 +42,7 @@
  * macros to make them selectively visible...
  */
 #if ! defined __need_off_t && ! defined __need___off64_t \
- && ! defined __need_ssize_t
+ && ! defined __need_ssize_t && ! defined __need_time_t
  /*
   * ...and define the multiple inclusion guard macro for this
   * header, ONLY IF no such selector macro is defined.
@@ -56,8 +56,7 @@
  */
 #if ! defined __have_typedef_off_t \
  && ( defined _SYS_TYPES_H || defined __need_off_t )
- /*
-  * We base this on an implementation specific private typedef,
+ /* We base this on an implementation specific private typedef,
   * analogous to our __off64_t (defined below)...
   */
   typedef __int32  __off32_t;
@@ -84,8 +83,7 @@
 
 #if ! defined __have_typedef___off64_t \
  && ( defined _SYS_TYPES_H || defined __need___off64_t )
- /*
-  * This is neither an ISO-C standard type, nor even a POSIX
+ /* This is neither an ISO-C standard type, nor even a POSIX
   * standard type; keep it runtime implementation specific.
   */
   typedef __int64  __off64_t;
 
 #if ! defined __have_typedef_ssize_t \
  && ( defined _SYS_TYPES_H || defined __need_ssize_t )
- /*
-  * POSIX ssize_t typedef, uglified by Microsoft as _ssize_t; ensure
+ /* POSIX ssize_t typedef, uglified by Microsoft as _ssize_t; ensure
   * that we support the Microsoft form...
   */
   typedef int  _ssize_t;
 # undef __need_ssize_t
 #endif
 
+#if ! defined __have_typedef_time_t \
+ && ( defined _SYS_TYPES_H || defined __need_time_t )
+ /* Current versions of MSVC define time_t ambiguously, in terms of
+  * one of the following unambiguous internal types:
+  */
+  typedef __int32 __time32_t;  /* unambiguous 32-bit time_t */
+  typedef __int64 __time64_t;  /* unambiguous 64-bit time_t */
+
+# if __MSVCRT_VERSION__ < __MSVCR80_DLL || defined _USE_32BIT_TIME_T
+  /* From MSVCR80.DLL onwards, Microsoft have royally messed up the
+   * definition of time_t; maintain POSIX consistency, (as MSVCRT.DLL
+   * itself does), unless the user is explicitly using one of these
+   * brain damaged DLL variants, and has not elected to retain the
+   * 32-bit time_t representation.
+   */
+   typedef __time32_t time_t;
+
+# else
+  /* Microsoft's brain damaged default, from MSVCR80.DLL onwards.
+   */
+   typedef __time64_t time_t;
+# endif
+# if __GCC__ < 4
+  /* Assume any compiler which is not GCC-4.x or newer may require
+   * guarding against repeated time_t typedefs.
+   */
+#  define __have_typedef_time_t  1
+# endif
+# undef __need_time_t
+#endif
+
 #ifdef _SYS_TYPES_H
 /* This is normal <sys/types.h> inclusion, i.e. for its own sake.
  *
 #define __need_wchar_t
 #include <stddef.h>
 
-/* Similarly, from this <time.h> subsidiary component...
- */
-#define __need_time_t
-#define _FAKE_TIME_H_SOURCED 1
-#include <parts/time.h>
-
 /* Today, Microsoft generally prefers to prefix POSIX type names
  * with an ugly initial underscore; ensure that we provide support
  * for this ungainly practice.
index 6d0c019..213c499 100644 (file)
  * the normal _TIME_H guard macro; initially, we also clear all of those
  * declaraction subset selection macros which are applicable herein.
  */
+#undef __need_time_t
 #undef __need_struct_timespec
 #undef __need_wchar_decls
 
 #if defined __WCHAR_H_SOURCED__
-/* This is selective inclusion by <wchar.h>, exposing only a subset of the
- * content from <time.h>; thus, we do not define the _TIME_H guard macro, so
- * we need to fake it, to get content from <parts/time.h>
+/* This is selective inclusion by <wchar.h>; thus, we do not define the
+ * _TIME_H guard macro, and we select only the minimally required subset
+ * of declarations to be exposed from within <time.h>
  */
-# define _FAKE_TIME_H_SOURCED 1
 # define __need_wchar_decls 1
 
 /* Both ISO-C and POSIX stipulate that <wchar.h> shall declare "struct tm"
@@ -74,16 +74,68 @@ struct tm;
 #endif
 
 #ifndef RC_INVOKED
-/* Some elements declared in <time.h> may also be required by other
- * header files, without necessarily including <time.h> itself; such
- * elements are declared in the local <parts/time.h> system header,
- * and must be selected prior to inclusion:
+/* Irrespective of whether this is normal or selective inclusion of
+ * <time.h>, we ALWAYS require the definition for time_t; get it by
+ * selective inclusion from its primary source, in <sys/types.h>
  */
-#define __need_time_t
-#include <parts/time.h>
+#define __need_time_t 1
+#include <sys/types.h>
+
+#if defined __need_struct_timespec && ! __struct_timespec_defined
+/* Structure timespec is mandated by POSIX, for specification of
+ * intervals with the greatest precision supported by the OS kernel.
+ * Although this allows for specification to nanosecond precision, do
+ * not be deluded into any false expectation that such short intervals
+ * can be realized on Windows; on Win9x derivatives, the metronome used
+ * by the process scheduler has a period of ~55 milliseconds, while for
+ * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
+ * the shortest intervals which can be realistically timed will range
+ * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
+ * with period values normally distributed around means of ~27.5 ms
+ * and ~7.5 ms, for the two system types respectively.
+ */
+struct timespec
+{ /* Period is sum of tv_sec + tv_nsec; while 32-bits is sufficient
+   * to accommodate tv_nsec, we use 64-bit __time64_t for tv_sec, to
+   * ensure that we have a sufficiently large field to accommodate
+   * Microsoft's ambiguous __time32_t vs. __time64_t representation
+   * of time_t; we may resolve this ambiguity locally, by casting a
+   * pointer to a struct timespec to point to an identically sized
+   * struct __mingw32_timespec, which is defined below.
+   */
+  __time64_t     tv_sec;       /* seconds; accept 32 or 64 bits */
+  __int32        tv_nsec;      /* nanoseconds */
+};
+
+# ifdef _MINGW32_EXTENDED_SOURCE
+struct __mingw32_expanded_timespec
+{
+  /* Equivalent of struct timespec, with disambiguation for the
+   * 32-bit vs. 64-bit tv_sec field declaration.  Period is the
+   * sum of tv_sec + tv_nsec; we use explicitly sized types to
+   * avoid 32-bit vs. 64-bit time_t ambiguity...
+   */
+  union
+  { /* ...within this anonymous union, allowing tv_sec to accommodate
+     * seconds expressed in either of Microsoft's (ambiguously sized)
+     * time_t representations.
+     */
+    __time64_t __tv64_sec;     /* unambiguously 64 bits */
+    __time32_t __tv32_sec;     /* unambiguously 32 bits */
+    time_t       tv_sec;       /* ambiguously 32 or 64 bits */
+  };
+  __int32        tv_nsec;      /* nanoseconds */
+};
+# endif /* _MINGW32_EXTENDED_SOURCE */
+
+# define __struct_timespec_defined  1
+#endif
 
 #ifdef _TIME_H
 #ifdef _MINGW32_EXTENDED_SOURCE
+
+_BEGIN_C_DECLS
+
 __CRT_ALIAS __LIBIMPL__(( FUNCTION = mingw_timespec ))
 /* This non-ANSI convenience function facilitates access to entities
  * defined as struct timespec, while exposing the broken down form of
@@ -94,7 +146,10 @@ __CRT_ALIAS __LIBIMPL__(( FUNCTION = mingw_timespec ))
  */
 struct __mingw32_expanded_timespec *mingw_timespec( struct timespec *__tv )
 { return (struct __mingw32_expanded_timespec *)(__tv); }
-#endif
+
+_END_C_DECLS
+
+#endif /* _MINGW32_EXTENDED_SOURCE */
 
 /* <time.h> is also required to duplicate the following type definitions,
  * which are nominally defined in <stddef.h>
@@ -266,7 +321,6 @@ __CRT_ALIAS __cdecl __MINGW_NOTHROW  struct tm *localtime (const time_t *__v)
  *          elements).
  */
 #ifdef __MSVCRT__
-
 /* These are for compatibility with pre-VC 5.0 supplied MSVCRT.DLL
  */
 extern _CRTIMP __cdecl __MINGW_NOTHROW  int   *__p__daylight (void);
@@ -316,8 +370,8 @@ __MINGW_IMPORT char *tzname[2];
  * of macros.
  */
 #define daylight  _daylight
-/*
- * NOTE: timezone not defined as a macro because it would conflict with
+
+/* NOTE: timezone not defined as a macro because it would conflict with
  * struct timezone in sys/time.h.  Also, tzname used to a be macro, but
  * now it's in moldname.
  */
@@ -334,21 +388,7 @@ __MINGW_IMPORT char        *tzname[2];
  */
 __cdecl __MINGW_NOTHROW
 int nanosleep( const struct timespec *, struct timespec * );
-/*
- * NOTE:
- *
- * Structure timespec is mandated by POSIX, for specification of
- * intervals with the greatest precision supported by the OS kernel.
- * Although this allows for specification to nanosecond precision, do
- * not be deluded into any false expectation that such short intervals
- * can be realized on Windows; on Win9x derivatives, the metronome used
- * by the process scheduler has a period of ~55 milliseconds, while for
- * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
- * the shortest intervals which can be realistically timed will range
- * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
- * with period values normally distributed around means of ~27.5 ms
- * and ~7.5 ms, for the two system types respectively.
- */
+
 #ifndef __NO_INLINE__
 /* We may conveniently provide an in-line implementation here,
  * in terms of the __mingw_sleep() helper function.
@@ -438,6 +478,7 @@ _END_C_DECLS
 
 /* We're done with all <time.h> specific content selectors; clear them.
  */
+#undef __need_time_t
 #undef __need_struct_timespec
 #undef __need_wchar_decls