OSDN Git Service

4080ab5c430ea50ca84221e5c97b169b2a6c0338
[mingw/mingw-org-wsl.git] / mingwrt / include / unistd.h
1 /*
2  * unistd.h
3  *
4  * Standard header file declaring MinGW's POSIX compatibility features.
5  *
6  * $Id$
7  *
8  * Written by Rob Savoye <rob@cygnus.com>
9  * Modified by Earnie Boyd <earnie@users.sourceforge.net>
10  *   Danny Smith <dannysmith@users.sourceforge.net>
11  *   Ramiro Polla <ramiro@lisha.ufsc.br>
12  *   Gregory McGarry  <gregorymcgarry@users.sourceforge.net>
13  *   Keith Marshall  <keithmarshall@users.sourceforge.net>
14  * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2017,
15  *   MinGW.org Project.
16  *
17  *
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:
24  *
25  * The above copyright notice, this permission notice, and the following
26  * disclaimer shall be included in all copies or substantial portions of
27  * the Software.
28  *
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.
36  *
37  */
38 #ifndef _UNISTD_H
39 #define _UNISTD_H  1
40 #pragma GCC system_header
41
42 /* All MinGW headers MUST include _mingw.h before anything else,
43  * to ensure proper initialization of feature test macros.
44  */
45 #include <_mingw.h>
46
47 /* unistd.h maps (roughly) to Microsoft's <io.h>
48  * Other headers included by <unistd.h> may be selectively processed;
49  * __UNISTD_H_SOURCED__ enables such selective processing.
50  */
51 #define __UNISTD_H_SOURCED__ 1
52
53 /* Use "..." inclusion here, to ensure that we get our own headers, which
54  * are designed to interoperate with the __UNISTD_H_SOURCED__ filter.
55  */
56 #include "io.h"
57 #include "process.h"
58 #include "getopt.h"
59
60 /* These are defined in stdio.h.  POSIX also requires that they
61  * are to be consistently defined here; don't guard against prior
62  * definitions, as this might conceal inconsistencies.
63  */
64 #define SEEK_SET   0
65 #define SEEK_CUR   1
66 #define SEEK_END   2
67
68 #if _POSIX_C_SOURCE
69 /* POSIX process/thread suspension functions; all are supported by a
70  * common MinGW API in libmingwex.a, providing for suspension periods
71  * ranging from mean values of ~7.5 milliseconds, (see the comments in
72  * <time.h>), extending up to a maximum of ~136 years.
73  *
74  * Note that, whereas POSIX supports early wake-up of any suspended
75  * process/thread, in response to a signal, this implementation makes
76  * no attempt to emulate this signalling behaviour, (since signals are
77  * not well supported by Windows); thus, unless impeded by an invalid
78  * argument, this implementation always returns an indication as if
79  * the sleeping period ran to completion.
80  */
81 _BEGIN_C_DECLS
82
83 __cdecl __MINGW_NOTHROW
84 int __mingw_sleep( unsigned long, unsigned long );
85
86 /* The nanosleep() function provides the most general purpose API for
87  * process/thread suspension; it is declared in <time.h>, (where it is
88  * accompanied by an in-line implementation), rather than here, and it
89  * provides for specification of suspension periods in the range from
90  * ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x), extending
91  * up to ~136 years, (effectively eternity).
92  *
93  * The usleep() function, and its associated useconds_t type specifier
94  * were made obsolete in POSIX.1-2008; declared here, only for backward
95  * compatibility, its continued use is not recommended.  (It is limited
96  * to specification of suspension periods ranging from ~7.5 ms mean up
97  * to a maximum of 999,999 microseconds only).
98  */
99 typedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED;
100 int __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;
101
102 #ifndef __NO_INLINE__
103 __CRT_INLINE __LIBIMPL__(( FUNCTION = usleep ))
104 int usleep( useconds_t period ){ return __mingw_sleep( 0, 1000 * period ); }
105 #endif
106
107 /* The sleep() function is, perhaps, the most commonly used of all the
108  * process/thread suspension APIs; it provides support for specification
109  * of suspension periods ranging from 1 second to ~136 years.  (However,
110  * POSIX recommends limiting the maximum period to 65535 seconds, to
111  * maintain portability to platforms with only 16-bit ints).
112  */
113 unsigned __cdecl __MINGW_NOTHROW sleep( unsigned );
114
115 #ifndef __NO_INLINE__
116 __CRT_INLINE __LIBIMPL__(( FUNCTION = sleep ))
117 unsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }
118 #endif
119
120
121 /* POSIX ftruncate() function.
122  *
123  * Microsoft's _chsize() function is incorrectly described, on MSDN,
124  * as a preferred replacement for the POSIX chsize() function.  There
125  * never was any such POSIX function; the actual POSIX equivalent is
126  * the ftruncate() function.
127  */
128 int __cdecl ftruncate( int, off_t );
129
130 #ifndef __NO_INLINE__
131 __CRT_INLINE __JMPSTUB__(( FUNCTION = ftruncate, DLLENTRY = _chsize ))
132 int ftruncate( int __fd, off_t __length ){ return _chsize( __fd, __length ); }
133 #endif
134
135 _END_C_DECLS
136
137 #endif /* _POSIX_C_SOURCE */
138
139 #undef __UNISTD_H_SOURCED__
140 #endif /* !_UNISTD_H: $RCSfile$: end of file */