+2015-05-18 Keith Marshall <keithmarshall@users.sourceforge.net>
+
+ Refactor to avoid possible time_t conflicts across headers.
+
+ * include/parts/time.h (struct timespec): Make it more descriptive of,
+ and better able to accommodate, potential ambiguity relating to...
+ (time_t, __time32_t, __time64_t): ...these typedefs; define them here,
+ whence they may be identically imported into each of...
+ * include/sys/types.h include/time.h include/wchar.h: these; delete
+ duplicate typedefs, and import accordingly.
+
+ * include/sys/types.h: Add licence; general comment additions.
+ (_TYPES_H_): Rename multiple inclusion guard macro...
+ (_SYS_TYPES_H): ...to this.
+
+ * include/time.h: Add licence; general comment/layout adjustments.
+ (_BEGIN_C_DECLS, _END_C_DECLS): Use to wrap extern "C" declarations.
+ (_TIME_T_DEFINED, _TIME32_T_DEFINED, _TIME64_T_DEFINED)
+ (_CLOCK_T_DEFINED): Superfluous guard macros; delete them.
+ (_TIME_H_): Rename multiple inclusion guard macro...
+ (_TIME_H): ...to this.
+
+ * include/unistd.h (nanosleep): Adjust to accommodate redefinition...
+ (struct timespec): ...of this.
+
+ * include/wchar.h: Add licence; general comment/layout adjustments.
+ (_BEGIN_C_DECLS, _END_C_DECLS): Use to wrap extern "C" declarations.
+ [GCC] (system_header): Add pragma, identifying header as such.
+ (_WCHAR_H_): Rename multiple inclusion guard macro...
+ (_WCHAR_H): ...to this.
+
2015-05-09 Keith Marshall <keithmarshall@users.sourceforge.net>
Remove obsolete varargs.h header file.
* $Id$
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2014, MinGW.org Project.
+ * Copyright (C) 2014, 2015, MinGW.org Project.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
# 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
*/
struct timespec
{
- /* Period is sum of tv_sec + tv_nsec; use fundamental integer types
- * to avoid 32-bit vs. 64-bit time_t ambiguity.
+ /* Period is sum of tv_sec + tv_nsec; use explicitly sized types
+ * to avoid 32-bit vs. 64-bit time_t ambiguity...
*/
- long long tv_sec; /* seconds */
- long tv_nsec; /* nanoseconds */
+ union
+ { /* ...within this anonymous union, allowing tv_sec to accommodate
+ * seconds expressed in either of Microsoft's (ambiguously sized)
+ * time_t representations.
+ */
+ time_t tv_sec; /* ambiguously 32 or 64 bits */
+ __time32_t __tv32_sec; /* unambiguously 32 bits */
+ __time64_t __tv64_sec; /* unambiguously 64 bits */
+ };
+ __int32 tv_nsec; /* nanoseconds */
};
# define __struct_timespec_defined 1
#endif
/*
- * types.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
+ * sys/types.h
*
- * The definition of constants, data types and global variables.
+ * Definitions of (primarily POSIX) system data types.
+ *
+ * $Id$
+ *
+ * Written by Rob Savoye <rob@cygnus.com>
+ * Copyright (C) 1997-1999, 2001, 2003, 2004, 2008, 2011, 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.
*
*/
-
-#ifndef _TYPES_H_
-#define _TYPES_H_
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+#pragma GCC system_header
/* All the headers include this file. */
#include <_mingw.h>
-#define __need_wchar_t
+#ifndef RC_INVOKED
+
#define __need_size_t
#define __need_ptrdiff_t
-#ifndef RC_INVOKED
+#define __need_wchar_t
#include <stddef.h>
-#endif /* Not RC_INVOKED */
-
-#ifndef RC_INVOKED
-#ifndef _TIME32_T_DEFINED
-typedef __int32 __time32_t;
-#define _TIME32_T_DEFINED
-#endif
+#define __need_time_t
+#define _FAKE_TIME_H_SOURCED 1
+#include <parts/time.h>
-#ifndef _TIME64_T_DEFINED
-typedef __int64 __time64_t;
-#define _TIME64_T_DEFINED
-#endif
-
-#ifndef _TIME_T_DEFINED
-/* FIXME __STRICT_ANSI__ ! */
-#if __MSVCRT_VERSION__ >= 0x0800
-#ifndef _USE_32BIT_TIME_T
-typedef __time64_t time_t;
-#else
-typedef __time32_t time_t;
-#endif /* !_USE_32BIT_TIME_T */
-#else
-typedef __time32_t time_t;
-#endif /* __MSVCRT_VERSION__ >= 0x0800 */
-#define _TIME_T_DEFINED
-#endif
#ifndef _OFF_T_
#define _OFF_T_
#endif
#if _POSIX_C_SOURCE
+/* useconds_t is an obsolete POSIX data type; we continue to define
+ * it here, for backward compatibility, but we flag it as deprecated,
+ * due to its obsolete status.
+ */
typedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED;
#endif
-#endif /* Not RC_INVOKED */
-
-#endif /* Not _TYPES_H_ */
+#endif /* ! RC_INVOKED */
+#endif /* ! _SYS_TYPES_H: $RCSfile$: end of file */
/*
* time.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
*
- * Date and time functions and types.
+ * Type definitions and function declarations relating to date and time.
+ *
+ * $Id$
+ *
+ * Written by Rob Savoye <rob@cygnus.com>
+ * Copyright (C) 1997-2007, 2011, 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.
*
*/
-
-#ifndef _TIME_H_
-#define _TIME_H_
+#ifndef _TIME_H
+#define _TIME_H
/* All the headers include this file. */
#include <_mingw.h>
-#define __need_wchar_t
-#define __need_size_t
-#define __need_NULL
-#ifndef RC_INVOKED
-#include <stddef.h>
-#endif /* Not RC_INVOKED */
-
-/*
- * Number of clock ticks per second. A clock tick is the unit by which
+/* Number of clock ticks per second. A clock tick is the unit by which
* processor time is measured and is returned by 'clock'.
*/
-#define CLOCKS_PER_SEC ((clock_t)1000)
-#define CLK_TCK CLOCKS_PER_SEC
-
+#define CLOCKS_PER_SEC ((clock_t)(1000))
+#define CLK_TCK CLOCKS_PER_SEC
#ifndef RC_INVOKED
-
/*
- * A type for storing the current time and date. This is the number of
- * seconds since midnight Jan 1, 1970.
- * NOTE: This is also defined in non-ISO sys/types.h.
+ * 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 file.
+ * Declarations for such elements must be selected prior to inclusion:
*/
-#ifndef _TIME32_T_DEFINED
-typedef __int32 __time32_t;
-#define _TIME32_T_DEFINED
-#endif
-
-#ifndef __STRICT_ANSI__
-/* A 64-bit time_t to get to Y3K */
-#ifndef _TIME64_T_DEFINED
-typedef __int64 __time64_t;
-#define _TIME64_T_DEFINED
-#endif
-#endif
-
-#ifndef _TIME_T_DEFINED
-/* FIXME __STRICT_ANSI__ ! */
-#if __MSVCRT_VERSION__ >= 0x0800
-#ifndef _USE_32BIT_TIME_T
-typedef __time64_t time_t;
-#else
-typedef __time32_t time_t;
-#endif /* !_USE_32BIT_TIME_T */
-#else
-typedef __time32_t time_t;
-#endif /* __MSVCRT_VERSION__ >= 0x0800 */
-#define _TIME_T_DEFINED
-#endif
+#define __need_time_t
+#define __need_struct_timespec
+#include <parts/time.h>
+/* time.h is also required to duplicate the following type definitions,
+ * which are nominally defined in stddef.h
+ */
+#define __need_NULL
+#define __need_wchar_t
+#define __need_size_t
+#include <stddef.h>
-/*
- * A type for measuring processor time (in clock ticks).
+/* A type for measuring processor time in clock ticks; (no need to
+ * guard this, since it isn't defined elsewhere).
*/
-#ifndef _CLOCK_T_DEFINED
-typedef long clock_t;
-#define _CLOCK_T_DEFINED
-#endif
+typedef long clock_t;
#ifndef _TM_DEFINED
/*
#define _TM_DEFINED
#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
+_BEGIN_C_DECLS
_CRTIMP clock_t __cdecl __MINGW_NOTHROW clock (void);
#if __MSVCRT_VERSION__ < 0x0800
#endif /* !_USE_32BIT_TIME_T */
#endif /* __MSVCRT_VERSION__ >= 0x0800 */
-
-/*
- * _daylight: non zero if daylight savings time is used.
+/* _daylight: non zero if daylight savings time is used.
* _timezone: difference in seconds between GMT and local time.
* _tzname: standard/daylight savings time zone names (an array with two
* elements).
#define _timezone _timezone_dll
#endif /* __DECLSPEC_SUPPORTED */
-
-#endif /* not __MSVCRT__ */
-
-#endif /* Not __STRICT_ANSI__ */
+#endif /* ! __MSVCRT__ */
+#endif /* ! __STRICT_ANSI__ */
#ifndef _NO_OLDNAMES
-
#ifdef __MSVCRT__
-/* These go in the oldnames import library for MSVCRT. */
+/* These go in the oldnames import library for MSVCRT.
+ */
__MINGW_IMPORT int daylight;
__MINGW_IMPORT long timezone;
__MINGW_IMPORT char *tzname[2];
-#else /* not __MSVCRT__ */
-
-/* CRTDLL is royally messed up when it comes to these macros.
- TODO: import and alias these via oldnames import library instead
- of macros. */
-
+#else /* ! __MSVCRT__ */
+/*
+ * CRTDLL is royally messed up when it comes to these macros.
+ * TODO: import and alias these via oldnames import library instead
+ * of macros.
+ */
#define daylight _daylight
-/* NOTE: timezone not defined as 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. */
+/*
+ * 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.
+ */
__MINGW_IMPORT char *tzname[2];
-#endif /* not __MSVCRT__ */
-
-#endif /* Not _NO_OLDNAMES */
+#endif /* ! __MSVCRT__ */
+#endif /* ! _NO_OLDNAMES */
#ifndef _WTIME_DEFINED
/* wide function prototypes, also declared in wchar.h */
#define _WTIME_DEFINED
#endif /* _WTIME_DEFINED */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* Not RC_INVOKED */
-
-#endif /* Not _TIME_H_ */
+_END_C_DECLS
+#endif /* ! RC_INVOKED */
+#endif /* ! _TIME_H: $RCSfile$: end of file */
* Ramiro Polla <ramiro@lisha.ufsc.br>
* Gregory McGarry <gregorymcgarry@users.sourceforge.net>
* Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014, MinGW.org Project.
+ * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2015,
+ * MinGW.org Project.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* with period values normally distributed around means of ~27.5 ms
* and ~7.5 ms, for the two system types respectively.
*/
-#define _FAKE_TIME_H_SOURCED 1
-#define __need_struct_timespec 1
+#define _FAKE_TIME_H_SOURCED 1
+#define __need_struct_timespec
#include <parts/time.h>
_BEGIN_C_DECLS
int nanosleep( const struct timespec *period, struct timespec *residual )
{
if( residual != (void *)(0) )
- residual->tv_sec = (long long)(residual->tv_nsec = 0);
- return __mingw_sleep((unsigned)(period->tv_sec), (period->tv_sec < 0LL)
+ residual->__tv64_sec = (__time64_t)(residual->tv_nsec = 0);
+ return __mingw_sleep((unsigned)(period->__tv64_sec), (period->__tv64_sec < 0LL)
? (unsigned)(-1) : (unsigned)(period->tv_nsec));
}
#endif
/*
* wchar.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
*
- * Defines of all functions for supporting wide characters. Actually it
- * just includes all those headers, which is not a good thing to do from a
- * processing time point of view, but it does mean that everything will be
- * in sync.
+ * Declarations relating to support for wide characters; many are simply
+ * inherited by (sub-optimal) inclusion of other header files.
+ *
+ * $Id$
+ *
+ * Written by Rob Savoye <rob@cygnus.com>
+ * Copyright (C) 1997, 1999-2009, 2011, 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.
*
*/
-
-#ifndef _WCHAR_H_
-#define _WCHAR_H_
+#ifndef _WCHAR_H
+#define _WCHAR_H
+#pragma GCC system_header
/* All the headers include this file. */
#include <_mingw.h>
-#ifndef RC_INVOKED
-
-#define __need_size_t
-#define __need_wint_t
-#define __need_wchar_t
-#define __need_NULL
-#include <stddef.h>
-
-#ifndef __VALIST
-#if defined __GNUC__ && __GNUC__ >= 3
-#define __need___va_list
-#include <stdarg.h>
-#define __VALIST __builtin_va_list
-#else
-#define __VALIST char*
-#endif
-#endif
-
-#endif /* Not RC_INVOKED */
-
-/*
- * MSDN says that isw* char classifications are in wchar.h and wctype.h.
+/* MSDN says that isw* char classifications are in wchar.h and wctype.h.
* Although the wctype names are ANSI, their exposure in this header is
- * not.
+ * not; nevertheless, we replicate them here, for MSDN conformity.
*/
#include <wctype.h>
-#ifndef __STRICT_ANSI__
-/* This is necessary to support the the non-ANSI wchar declarations
- here. */
-#include <sys/types.h>
+#ifndef __STRICT_ANSI__
+/* This is also necessary, to support the non-ANSI wchar.h declarations
+ * which MSDN identifies as being provided here.
+ */
+# include <sys/types.h>
#endif /* __STRICT_ANSI__ */
#define WCHAR_MIN 0
#define WCHAR_MAX 0xffff
-#ifndef WEOF
-#define WEOF (wchar_t)(0xFFFF)
-#endif
+# define WEOF (wchar_t)(0xffff)
#ifndef RC_INVOKED
-#ifdef __cplusplus
-extern "C" {
+#define __need_size_t
+#define __need_wint_t
+#define __need_wchar_t
+#define __need_NULL
+#include <stddef.h>
+
+#ifndef __VALIST
+# if defined __GNUC__ && __GNUC__ >= 3
+# define __need___va_list
+# include <stdarg.h>
+# define __VALIST __builtin_va_list
+# else
+# define __VALIST char*
+# endif
#endif
+_BEGIN_C_DECLS
+
#ifndef _FILE_DEFINED /* Also in stdio.h */
#define _FILE_DEFINED
typedef struct _iobuf
} FILE;
#endif /* Not _FILE_DEFINED */
-#ifndef _TIME_T_DEFINED /* Also in time.h */
-typedef long time_t;
-#define _TIME_T_DEFINED
-#endif
+#define __need_time_t
+#define _FAKE_TIME_H_SOURCED 1
+#include <parts/time.h>
#ifndef _TM_DEFINED /* Also in time.h */
struct tm {
#define _WPROCESS_DEFINED
#endif
-#endif /* not __STRICT_ANSI__ */
-
-#ifdef __cplusplus
-} /* end of extern "C" */
-#endif
-
-#endif /* Not RC_INVOKED */
+#endif /* ! __STRICT_ANSI__ */
-#endif /* not _WCHAR_H_ */
+_END_C_DECLS
+#endif /* ! RC_INVOKED */
+#endif /* ! _WCHAR_H */