From 0fe24734253ddb48495cd0bd04d1beb1fd23345a Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Fri, 15 Sep 2017 21:35:48 +0100 Subject: [PATCH] Factor duplicate content out of winsock headers. --- mingwrt/ChangeLog | 13 +++++ mingwrt/include/sys/time.h | 143 +++++++++++++++++++++++++++++++++------------ w32api/ChangeLog | 10 ++++ w32api/include/winsock.h | 21 +------ w32api/include/winsock2.h | 22 ++----- 5 files changed, 135 insertions(+), 74 deletions(-) diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 4e7500d..9886e4c 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,16 @@ +2017-09-15 Keith Marshall + + Factor 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 Factor BSD non-standard type definitions into common header. diff --git a/mingwrt/include/sys/time.h b/mingwrt/include/sys/time.h index e11a2ba..c2d9839 100644 --- a/mingwrt/include/sys/time.h +++ b/mingwrt/include/sys/time.h @@ -1,47 +1,114 @@ -#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 + * 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 will also expose all of ? + * (If not , we do need <_mingw.h> instead). + */ #include -#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 + * is included in its own right, and when it is included selectively + * on behalf of , 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 must be able to + * expose timerclear, timerisset, and timercmp, regardless of the + * order in which and 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 */ diff --git a/w32api/ChangeLog b/w32api/ChangeLog index 02dd0f0..5e2adf4 100644 --- a/w32api/ChangeLog +++ b/w32api/ChangeLog @@ -1,3 +1,13 @@ +2017-09-15 Keith Marshall + + Factor duplicate content out of winsock headers. + + * include/winsock.h include/winsock2.h [_TIMEVAL_DEFINED]: Delete + conditional block, and all its content; include 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 Source BSD non-standard type definitions from mingwrt header. diff --git a/w32api/include/winsock.h b/w32api/include/winsock.h index d2511ec..715d736 100644 --- a/w32api/include/winsock.h +++ b/w32api/include/winsock.h @@ -45,9 +45,11 @@ #pragma GCC system_header #define _GNU_H_WINDOWS32_SOCKETS +#define __WINSOCK_H_SOURCED__ 1 #include #include +#include _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 , 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 +#undef __WINSOCK_H_SOURCED__ #endif /* _WINSOCK_H: $RCSfile$: end of file */ diff --git a/w32api/include/winsock2.h b/w32api/include/winsock2.h index dc908f0..2ff4f42 100644 --- a/w32api/include/winsock2.h +++ b/w32api/include/winsock2.h @@ -44,9 +44,13 @@ #pragma GCC system_header #define _GNU_H_WINDOWS32_SOCKETS +#define __WINSOCK_H_SOURCED__ 1 #include #include +#include + +#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 , 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; -- 2.11.0