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, MinGW.org Project.
18 * Permission is hereby granted, free of charge, to any person obtaining a
19 * copy of this software and associated documentation files (the "Software"),
20 * to deal in the Software without restriction, including without limitation
21 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
22 * and/or sell copies of the Software, and to permit persons to whom the
23 * Software is furnished to do so, subject to the following conditions:
25 * The above copyright notice, this permission notice, and the following
26 * disclaimer shall be included in all copies or substantial portions of
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
35 * DEALINGS IN THE SOFTWARE.
39 #pragma GCC system_header
41 /* All MinGW headers MUST include _mingw.h before anything else,
42 * to ensure proper initialization of feature test macros.
46 /* unistd.h maps (roughly) to io.h
47 * Other headers included by unistd.h may be selectively processed;
48 * __UNISTD_H_SOURCED__ enables such selective processing.
50 #define __UNISTD_H_SOURCED__ 1
56 /* These are also defined in stdio.h. */
71 * POSIX process/thread suspension functions; all are supported by a
72 * common MinGW API in libmingwex.a, providing for suspension periods
73 * ranging from mean values of ~7.5 milliseconds, (see comments below),
74 * extending up to a maximum of ~136 years.
76 * Note that, whereas POSIX supports early wake-up of any suspended
77 * process/thread, in response to a signal, this implementation makes
78 * no attempt to emulate this signalling behaviour, (since signals are
79 * not well supported by Windows); thus, unless impeded by an invalid
80 * argument, this implementation always returns an indication as if
81 * the sleeping period ran to completion.
83 _EXTERN_C _cdecl __MINGW_NOTHROW
84 int __mingw_sleep( unsigned long, unsigned long );
86 /* Structure timespec is mandated by POSIX, for specification of
87 * intervals with the greatest precision supported by the OS kernel.
88 * Although this allows for specification to nanosecond precision, do
89 * not be deluded into any false expectation that such short intervals
90 * can be realized on Windows; on Win9x derivatives, the metronome used
91 * by the process scheduler has a period of ~55 milliseconds, while for
92 * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
93 * the shortest intervals which can be realistically timed will range
94 * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
95 * with period values normally distributed around means of ~27.5 ms
96 * and ~7.5 ms, for the two system types respectively.
98 #define _FAKE_TIME_H_SOURCED 1
99 #define __need_struct_timespec 1
100 #include <parts/time.h>
104 /* The nanosleep() function provides the most general purpose API for
105 * process/thread suspension; it provides for specification of periods
106 * ranging from ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x),
107 * extending up to ~136 years, (effectively eternity).
109 _cdecl __MINGW_NOTHROW
110 int nanosleep( const struct timespec *, struct timespec * );
112 #ifndef __NO_INLINE__
113 __CRT_INLINE __LIBIMPL__(( FUNCTION = nanosleep ))
114 int nanosleep( const struct timespec *period, struct timespec *residual )
116 if( residual != (void *)(0) )
117 residual->tv_sec = (long long)(residual->tv_nsec = 0);
118 return __mingw_sleep((unsigned)(period->tv_sec), (period->tv_sec < 0LL)
119 ? (unsigned)(-1) : (unsigned)(period->tv_nsec));
123 /* The usleep() function, and its associated useconds_t type specifier
124 * were made obsolete in POSIX.1-2008; declared here, only for backward
125 * compatibility, its continued use is not recommended. (It is limited
126 * to specification of suspension periods ranging from ~7.5 ms mean up
127 * to a maximum of 999,999 microseconds only).
129 typedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED;
130 int _cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
132 #ifndef __NO_INLINE__
133 __CRT_INLINE __LIBIMPL__(( FUNCTION = usleep ))
134 int usleep( useconds_t period ){ return __mingw_sleep( 0, 1000 * period ); }
137 /* The sleep() function is, perhaps, the most commonly used of all the
138 * process/thread suspension APIs; it provides support for specification
139 * of suspension periods ranging from 1 second to ~136 years. (However,
140 * POSIX recommends limiting the maximum period to 65535 seconds, to
141 * maintain portability to platforms with only 16-bit ints).
143 unsigned _cdecl __MINGW_NOTHROW sleep( unsigned );
145 #ifndef __NO_INLINE__
146 __CRT_INLINE __LIBIMPL__(( FUNCTION = sleep ))
147 unsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }
151 /* POSIX ftruncate() function.
153 * Microsoft's _chsize() function is incorrectly described, on MSDN,
154 * as a preferred replacement for the POSIX chsize() function. There
155 * never was any such POSIX function; the actual POSIX equivalent is
156 * the ftruncate() function.
158 int _cdecl ftruncate( int, off_t );
160 #ifndef __NO_INLINE__
161 __CRT_INLINE __JMPSTUB__(( FUNCTION = ftruncate, REMAPPED = _chsize ))
162 int ftruncate( int __fd, off_t __length ){ return _chsize( __fd, __length ); }
167 #endif /* _POSIX_C_SOURCE */
169 #undef __UNISTD_H_SOURCED__
170 #endif /* ! _UNISTD_H: $RCSfile$: end of file */