OSDN Git Service

Factor <sys/time.h> duplicate content out of winsock headers.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 15 Sep 2017 20:35:48 +0000 (21:35 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 15 Sep 2017 20:35:48 +0000 (21:35 +0100)
mingwrt/ChangeLog
mingwrt/include/sys/time.h
w32api/ChangeLog
w32api/include/winsock.h
w32api/include/winsock2.h

index 4e7500d..9886e4c 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-15  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Factor <sys/time.h> duplicate content out of winsock headers.
+
+       * include/sys/time.h: Assert copyright; tidy layout.
+       [_BEGIN_C_DECLS, _END_C_DECLS]: Use them to avoid C++ name mangling.
+       [__WINSOCK_H_SOURCED__] (_SYS_TIME_H): Do not define it; hence...
+       [!defined _SYS_TIME_H]: ...selectively expose definitions for only...
+       (timerclear, timerisset, timercmp): ...these functional macros, and...
+       (struct timeval): ...this data type; inhibit redefinition on...
+       [defined _SYS_TIME_H && _WINSOCK_H]: ...second reading.
+       (_TIMEVAL_DEFINED): Do not define; it isn't required.
+
 2017-09-09  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Factor BSD non-standard type definitions into common header.
index e11a2ba..c2d9839 100644 (file)
-#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
+/*
+ * sys/time.h
+ *
+ * Time type definitions pertaining to system timer and clock APIs
+ *
+ *
+ * $Id$
+ *
+ * Written by Danny Smith <dannysmith@users.sourceforge.net>
+ * Copyright (C) 2002, 2004, 2006, 2007, 2017, 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 and this permission notice (including the next
+ * paragraph) 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 OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef _SYS_TIME_H
+#pragma GCC system_header
+
+#ifndef __WINSOCK_H_SOURCED__
+#define _SYS_TIME_H
+
+/* FIXME: Do we need to do this?  There's nothing here which
+ * explicitly requires it; are users entitled to assume that
+ * including <sys/time.h> will also expose all of <time.h>?
+ * (If not <time.h>, we do need <_mingw.h> instead).
+ */
 #include <time.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+_BEGIN_C_DECLS
 
-#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
-#define _TIMEVAL_DEFINED
-struct timeval {
-  long tv_sec;
-  long tv_usec;
-};
-#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
-#define timercmp(tvp, uvp, cmp) \
-       (((tvp)->tv_sec != (uvp)->tv_sec) ? \
-       ((tvp)->tv_sec cmp (uvp)->tv_sec) : \
-       ((tvp)->tv_usec cmp (uvp)->tv_usec))
-#define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
-#endif /* _TIMEVAL_DEFINED */
-
-/* Provided for compatibility with code that assumes that
-   the presence of gettimeofday function implies a definition
-   of struct timezone. */
-struct timezone
-{
-  int tz_minuteswest; /* of Greenwich */
-  int tz_dsttime;     /* type of dst correction to apply */
+#endif /* !__WINSOCK_H_SOURCED__ */
+
+#if ! (defined _SYS_TIME_H && defined _WINSOCK_H)
+/* The following definitions must be exposed both when <sys/time.h>
+ * is included in its own right, and when it is included selectively
+ * on behalf of <winsock.h>, but they must not be processed twice.
+ */
+struct timeval
+{ /* Nominally a BSD or POSIX.1 structure, (with tv_sec declared as
+   * time_t), but subverted by Microsoft with tv_sec declared as long,
+   * to avoid __time32_t vs. __time64_t ambiguity; (tv_sec is ALWAYS
+   * a 32-bit entity in Windows' use of this structure).  Addionally,
+   * POSIX.1-2001 mandates that tv_usec should be suseconds_t, (which
+   * is nominally an alias for long), but we retain long to maintain
+   * consistency with Microsoft usage.
+   */
+  long tv_sec;         /* whole number of seconds in interval */
+  long tv_usec;        /* additional fraction as microseconds */
 };
 
-/*
-   Implementation as per:
-   The Open Group Base Specifications, Issue 6
-   IEEE Std 1003.1, 2004 Edition
+/* FIXME: The following convenience macros, for manipulating data in
+ * timeval structures, are derived from BSD; they are neither standard
+ * in Windows code, nor specified in POSIX.1, but have been adopted by
+ * GNU.  Consider making them dependent on _BSD_SOURCE or _GNU_SOURCE
+ * feature test filters, (but note that <winsock.h> must be able to
+ * expose timerclear, timerisset, and timercmp, regardless of the
+ * order in which <sys/time.h> and <winsock.h> are included).
+ */
+#define timerclear( tvp )  (tvp)->tv_sec = (tvp)->tv_usec = 0
+#define timerisset( tvp )  ((tvp)->tv_sec || (tvp)->tv_usec)
+
+#define timercmp( tvp, uvp, cmp )  (((tvp)->tv_sec != (uvp)->tv_sec)   \
+         ? ((tvp)->tv_sec cmp (uvp)->tv_sec)                           \
+         : ((tvp)->tv_usec cmp (uvp)->tv_usec))
+
+#endif /* ! (_SYS_TIME_H && _WINSOCK_H) */
 
-   The timezone pointer arg is ignored.  Errors are ignored.
-*/
-int __cdecl __MINGW_NOTHROW gettimeofday(struct timeval *__restrict__,
-                        void *__restrict__  /* tzp (unused) */);
+#ifdef _SYS_TIME_H
+struct timezone
+{ /* FIXME: Deprecate this...
+   * Provided for compatibility with code that assumes that the
+   * presence of the gettimeofday() function implies that it may
+   * be safely assumed that a definition of struct timezone will
+   * also be provided.  This is an obsolete derivative from BSD;
+   * DO NOT USE IT!
+   */
+  int tz_minuteswest;          /* of the Greenwich meridian */
+  int tz_dsttime;              /* type of DST correction to apply */
+};
 
-#ifdef __cplusplus
-}
-#endif
+/* Declaration of POSIX.1 compatible gettimeofday() function:
+ *
+ * Implementation per POSIX.1-1996, (declared obsolescent in POSIX.1-2008),
+ * as described in the Open Group Base Specification, Issue 7, which is also
+ * designated as IEEE Std 1003.1, 2016 Edition; the struct timezone pointer
+ * argument of some Unix implementations (declared as a pointer to void in
+ * POSIX.1) is ignored, as are all error conditions.
+ *
+ * FIXME: Deprecate this for _POSIX_C_SOURCE >= 200809L
+ */
+int __cdecl __MINGW_NOTHROW gettimeofday
+(struct timeval *__restrict__, void *__restrict__ /* tzp (unused) */);
 
+_END_C_DECLS
 
-#endif /* _SYS_TIME_H_ */
+#endif /* _SYS_TIME_H */
+#endif /* !_SYS_TIME_H: $RCSfile$: end of file */
index 02dd0f0..5e2adf4 100644 (file)
@@ -1,3 +1,13 @@
+2017-09-15  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Factor <sys/time.h> duplicate content out of winsock headers.
+
+       * include/winsock.h include/winsock2.h [_TIMEVAL_DEFINED]: Delete
+       conditional block, and all its content; include <sys/time.h> instead.
+       (__WINSOCK_H_SOURCED__): New macro; define it temporarily, only while
+       processing this header, such that only selected content from other
+       internally referenced headers is exposed.
+
 2017-09-09  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Source BSD non-standard type definitions from mingwrt header.
index d2511ec..715d736 100644 (file)
 #pragma GCC system_header
 
 #define _GNU_H_WINDOWS32_SOCKETS
+#define __WINSOCK_H_SOURCED__ 1
 
 #include <windows.h>
 #include <sys/bsdtypes.h>
+#include <sys/time.h>
 
 _BEGIN_C_DECLS
 
@@ -118,24 +120,6 @@ int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
 
 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
 
-#ifndef _TIMEVAL_DEFINED
-/* FIXME: These should be factored out; they are properly defined
- * in <sys/time.h>, whence they should be included.
- */
-#define _TIMEVAL_DEFINED
-struct timeval
-{ long           tv_sec;
-  long           tv_usec;
-};
-
-#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
-#define timercmp(tvp, uvp, cmp) \
-       (((tvp)->tv_sec != (uvp)->tv_sec) ? \
-       ((tvp)->tv_sec cmp (uvp)->tv_sec) : \
-       ((tvp)->tv_usec cmp (uvp)->tv_usec))
-#define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
-#endif /* _TIMEVAL_DEFINED */
-
 struct hostent
 { char          *h_name;
   char         **h_aliases;
@@ -614,4 +598,5 @@ _END_C_DECLS
  */
 #include <mswsock.h>
 
+#undef __WINSOCK_H_SOURCED__
 #endif /* _WINSOCK_H: $RCSfile$: end of file */
index dc908f0..2ff4f42 100644 (file)
 #pragma GCC system_header
 
 #define _GNU_H_WINDOWS32_SOCKETS
+#define __WINSOCK_H_SOURCED__ 1
 
 #include <windows.h>
 #include <sys/bsdtypes.h>
+#include <sys/time.h>
+
+#undef __WINSOCK_H_SOURCED__
 
 #ifndef WINSOCK_API_LINKAGE
 #ifdef __W32API_USE_DLLIMPORT__
@@ -138,24 +142,6 @@ int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
 
 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
 
-#ifndef _TIMEVAL_DEFINED
-/* FIXME: These should be factored out; they are properly defined
- * in <sys/time.h>, whence they should be included.
- */
-#define _TIMEVAL_DEFINED
-struct timeval
-{ long           tv_sec;
-  long           tv_usec;
-};
-
-#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
-#define timercmp(tvp, uvp, cmp) \
-       (((tvp)->tv_sec != (uvp)->tv_sec) ? \
-       ((tvp)->tv_sec cmp (uvp)->tv_sec) : \
-       ((tvp)->tv_usec cmp (uvp)->tv_usec))
-#define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
-#endif /* _TIMEVAL_DEFINED */
-
 struct hostent
 { char          *h_name;
   char         **h_aliases;