5 * Standard header file declaring MinGW's POSIX compatibility features.
9 * Written by Rob Savoye <rob@cygnus.com>
10 * Modified by Earnie Boyd <earnie@users.sourceforge.net>
11 * Danny Smith <dannysmith@users.sourceforge.net>
12 * Ramiro Polla <ramiro@lisha.ufsc.br>
13 * Gregory McGarry <gregorymcgarry@users.sourceforge.net>
14 * Keith Marshall <keithmarshall@users.sourceforge.net>
15 * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2015,
19 * Permission is hereby granted, free of charge, to any person obtaining a
20 * copy of this software and associated documentation files (the "Software"),
21 * to deal in the Software without restriction, including without limitation
22 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23 * and/or sell copies of the Software, and to permit persons to whom the
24 * Software is furnished to do so, subject to the following conditions:
26 * The above copyright notice, this permission notice, and the following
27 * disclaimer shall be included in all copies or substantial portions of
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
36 * DEALINGS IN THE SOFTWARE.
40 #pragma GCC system_header
42 /* All MinGW headers MUST include _mingw.h before anything else,
43 * to ensure proper initialization of feature test macros.
47 /* unistd.h maps (roughly) to io.h
48 * Other headers included by unistd.h may be selectively processed;
49 * __UNISTD_H_SOURCED__ enables such selective processing.
51 #define __UNISTD_H_SOURCED__ 1
57 /* These are defined in stdio.h. POSIX also requires that they
58 * are to be consistently defined here; don't guard against prior
59 * definitions, as this might conceal inconsistencies.
67 * POSIX process/thread suspension functions; all are supported by a
68 * common MinGW API in libmingwex.a, providing for suspension periods
69 * ranging from mean values of ~7.5 milliseconds, (see comments below),
70 * extending up to a maximum of ~136 years.
72 * Note that, whereas POSIX supports early wake-up of any suspended
73 * process/thread, in response to a signal, this implementation makes
74 * no attempt to emulate this signalling behaviour, (since signals are
75 * not well supported by Windows); thus, unless impeded by an invalid
76 * argument, this implementation always returns an indication as if
77 * the sleeping period ran to completion.
79 _EXTERN_C __cdecl __MINGW_NOTHROW
80 int __mingw_sleep( unsigned long, unsigned long );
82 /* Structure timespec is mandated by POSIX, for specification of
83 * intervals with the greatest precision supported by the OS kernel.
84 * Although this allows for specification to nanosecond precision, do
85 * not be deluded into any false expectation that such short intervals
86 * can be realized on Windows; on Win9x derivatives, the metronome used
87 * by the process scheduler has a period of ~55 milliseconds, while for
88 * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
89 * the shortest intervals which can be realistically timed will range
90 * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
91 * with period values normally distributed around means of ~27.5 ms
92 * and ~7.5 ms, for the two system types respectively.
94 #define _FAKE_TIME_H_SOURCED 1
95 #define __need_struct_timespec
96 #include <parts/time.h>
100 /* The nanosleep() function provides the most general purpose API for
101 * process/thread suspension; it provides for specification of periods
102 * ranging from ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x),
103 * extending up to ~136 years, (effectively eternity).
105 __cdecl __MINGW_NOTHROW
106 int nanosleep( const struct timespec *, struct timespec * );
108 #ifndef __NO_INLINE__
109 __CRT_INLINE __LIBIMPL__(( FUNCTION = nanosleep ))
110 int nanosleep( const struct timespec *period, struct timespec *residual )
112 if( residual != (void *)(0) )
113 residual->tv_sec = (__time64_t)(residual->tv_nsec = 0);
114 return __mingw_sleep((unsigned)(period->tv_sec), (period->tv_sec < 0LL)
115 ? (unsigned)(-1) : (unsigned)(period->tv_nsec));
119 /* The usleep() function, and its associated useconds_t type specifier
120 * were made obsolete in POSIX.1-2008; declared here, only for backward
121 * compatibility, its continued use is not recommended. (It is limited
122 * to specification of suspension periods ranging from ~7.5 ms mean up
123 * to a maximum of 999,999 microseconds only).
125 typedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED;
126 int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
128 #ifndef __NO_INLINE__
129 __CRT_INLINE __LIBIMPL__(( FUNCTION = usleep ))
130 int usleep( useconds_t period ){ return __mingw_sleep( 0, 1000 * period ); }
133 /* The sleep() function is, perhaps, the most commonly used of all the
134 * process/thread suspension APIs; it provides support for specification
135 * of suspension periods ranging from 1 second to ~136 years. (However,
136 * POSIX recommends limiting the maximum period to 65535 seconds, to
137 * maintain portability to platforms with only 16-bit ints).
139 unsigned __cdecl __MINGW_NOTHROW sleep( unsigned );
141 #ifndef __NO_INLINE__
142 __CRT_INLINE __LIBIMPL__(( FUNCTION = sleep ))
143 unsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }
147 /* POSIX ftruncate() function.
149 * Microsoft's _chsize() function is incorrectly described, on MSDN,
150 * as a preferred replacement for the POSIX chsize() function. There
151 * never was any such POSIX function; the actual POSIX equivalent is
152 * the ftruncate() function.
154 int __cdecl ftruncate( int, off_t );
156 #ifndef __NO_INLINE__
157 __CRT_INLINE __JMPSTUB__(( FUNCTION = ftruncate, REMAPPED = _chsize ))
158 int ftruncate( int __fd, off_t __length ){ return _chsize( __fd, __length ); }
163 #endif /* _POSIX_C_SOURCE */
165 #undef __UNISTD_H_SOURCED__
166 #endif /* ! _UNISTD_H: $RCSfile$: end of file */