Install msysDVLPR-1.0.0-alpha-1
[msysgit.git] / include / sys / types.h
blob81a11c70e2b9ec3522ea5ba44004a3334d59ce38
1 /* unified sys/types.h:
2 start with sef's sysvi386 version.
3 merge go32 version -- a few ifdefs.
4 h8300hms, h8300xray, and sysvnecv70 disagree on the following types:
6 typedef int gid_t;
7 typedef int uid_t;
8 typedef int dev_t;
9 typedef int ino_t;
10 typedef int mode_t;
11 typedef int caddr_t;
13 however, these aren't "reasonable" values, the sysvi386 ones make far
14 more sense, and should work sufficiently well (in particular, h8300
15 doesn't have a stat, and the necv70 doesn't matter.) -- eichin
18 #ifndef _SYS_TYPES_H
19 #define _SYS_TYPES_H
21 #if defined (_WIN32) || defined (__CYGWIN__) || defined (__MSYS__)
22 #define __MS_types__
23 #endif
25 #ifdef __i386__
26 #if defined (GO32) || defined (__MSDOS__)
27 #define __MS_types__
28 #endif
29 #endif
31 # include <stddef.h>
32 # include <machine/types.h>
34 /* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
35 changes, we assume sizeof short and long never change and have all types
36 used to define struct stat use them and not int where possible.
37 Where not possible, _ST_INTxx are used. It would be preferable to not have
38 such assumptions, but until the extra fluff is necessary, it's avoided.
39 No 64 bit targets use stat yet. What to do about them is postponed
40 until necessary. */
41 #ifdef __GNUC__
42 #define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
43 #else
44 #define _ST_INT32
45 #endif
47 # ifndef _POSIX_SOURCE
49 # define physadr physadr_t
50 # define quad quad_t
52 #ifndef _BSDTYPES_DEFINED
53 /* also defined in mingw/gmon.h and in w32api/winsock[2].h */
54 typedef unsigned char u_char;
55 typedef unsigned short u_short;
56 typedef unsigned int u_int;
57 typedef unsigned long u_long;
58 #define _BSDTYPES_DEFINED
59 #endif
61 typedef unsigned short ushort; /* System V compatibility */
62 typedef unsigned int uint; /* System V compatibility */
63 # endif /*!_POSIX_SOURCE */
65 #ifndef __clock_t_defined
66 typedef _CLOCK_T_ clock_t;
67 #define __clock_t_defined
68 #endif
70 #ifndef __time_t_defined
71 typedef _TIME_T_ time_t;
72 #define __time_t_defined
74 /* Time Value Specification Structures, P1003.1b-1993, p. 261 */
76 struct timespec {
77 time_t tv_sec; /* Seconds */
78 long tv_nsec; /* Nanoseconds */
81 struct itimerspec {
82 struct timespec it_interval; /* Timer period */
83 struct timespec it_value; /* Timer expiration */
85 #endif
87 typedef long daddr_t;
88 typedef char * caddr_t;
90 #ifdef __MS_types__
91 typedef unsigned long ino_t;
92 #else
93 #ifdef __sparc__
94 typedef unsigned long ino_t;
95 #else
96 typedef unsigned short ino_t;
97 #endif
98 #endif
100 #ifdef __MS_types__
101 typedef unsigned long vm_offset_t;
102 typedef unsigned long vm_size_t;
104 #define __BIT_TYPES_DEFINED__
106 typedef char int8_t;
107 typedef unsigned char u_int8_t;
108 typedef short int16_t;
109 typedef unsigned short u_int16_t;
110 typedef int int32_t;
111 typedef unsigned int u_int32_t;
112 typedef long long int64_t;
113 typedef unsigned long long u_int64_t;
114 typedef int32_t register_t;
115 #endif /* __MS_types__ */
118 * All these should be machine specific - right now they are all broken.
119 * However, for all of Cygnus' embedded targets, we want them to all be
120 * the same. Otherwise things like sizeof (struct stat) might depend on
121 * how the file was compiled (e.g. -mint16 vs -mint32, etc.).
124 #if defined(__rtems__)
125 /* device numbers are 32-bit major and and 32-bit minor */
126 typedef unsigned long long dev_t;
127 #else
128 typedef short dev_t;
129 #endif
131 typedef long off_t;
133 typedef unsigned short uid_t;
134 typedef unsigned short gid_t;
135 typedef int pid_t;
136 typedef long key_t;
137 typedef long ssize_t;
139 #ifdef __MS_types__
140 typedef char * addr_t;
141 typedef int mode_t;
142 #else
143 #if defined (__sparc__) && !defined (__sparc_v9__)
144 #ifdef __svr4__
145 typedef unsigned long mode_t;
146 #else
147 typedef unsigned short mode_t;
148 #endif
149 #else
150 typedef unsigned int mode_t _ST_INT32;
151 #endif
152 #endif /* ! __MS_types__ */
154 typedef unsigned short nlink_t;
156 /* We don't define fd_set and friends if we are compiling POSIX
157 source, or if we have included (or may include as indicated
158 by __USE_W32_SOCKETS) the W32api winsock[2].h header which
159 defines Windows versions of them. Note that a program which
160 includes the W32api winsock[2].h header must know what it is doing;
161 it must not call the cygwin32 or msys select function.
163 # if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS))
164 # define _SYS_TYPES_FD_SET
165 # define NBBY 8 /* number of bits in a byte */
167 * Select uses bit masks of file descriptors in longs.
168 * These macros manipulate such bit fields (the filesystem macros use chars).
169 * FD_SETSIZE may be defined by the user, but the default here
170 * should be >= NOFILE (param.h).
172 # ifndef FD_SETSIZE
173 # define FD_SETSIZE 64
174 # endif
176 typedef long fd_mask;
177 # define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
178 # ifndef howmany
179 # define howmany(x,y) (((x)+((y)-1))/(y))
180 # endif
182 /* We use a macro for fd_set so that including Sockets.h afterwards
183 can work. */
184 typedef struct _types_fd_set {
185 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
186 } _types_fd_set;
188 #define fd_set _types_fd_set
190 # define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
191 # define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
192 # define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
193 # define FD_ZERO(p) (__extension__ (void)({ \
194 size_t __i; \
195 char *__tmp = (char *)p; \
196 for (__i = 0; __i < sizeof (*(p)); ++__i) \
197 *__tmp++ = 0; \
200 # endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) */
202 #undef __MS_types__
203 #undef _ST_INT32
205 /* The following are actually standard POSIX 1003.1b-1993 threads, mutexes,
206 condition variables, and keys. But since RTEMS is currently the only
207 newlib user of these, the ifdef is just on RTEMS. */
209 #if defined(__rtems__) || defined(__CYGWIN__) || defined(__MSYS__)
211 #ifndef __clockid_t_defined
212 typedef _CLOCKID_T_ clockid_t;
213 #define __clockid_t_defined
214 #endif
216 #ifndef __timer_t_defined
217 typedef _TIMER_T_ timer_t;
218 #define __timer_t_defined
219 #endif
221 #include <sys/features.h>
224 /* Cygwin nor msys will probably never have full posix compliance due to little
225 * things like an inability to set the stackaddress. Cygwin is also using void *
226 * pointers rather than structs to ensure maximum binary compatability with
227 * previous releases.
228 * This means that we don't use the types defined here, but rather in
229 * <cygwin/types.h>
231 #if defined(_POSIX_THREADS) && !defined(__CYGWIN__) && !defined(__MSYS__)
233 #include <sys/sched.h>
236 * 2.5 Primitive System Data Types, P1003.1c/D10, p. 19.
239 typedef __uint32_t pthread_t; /* identify a thread */
241 /* P1003.1c/D10, p. 118-119 */
242 #define PTHREAD_SCOPE_PROCESS 0
243 #define PTHREAD_SCOPE_SYSTEM 1
245 /* P1003.1c/D10, p. 111 */
246 #define PTHREAD_INHERIT_SCHED 1 /* scheduling policy and associated */
247 /* attributes are inherited from */
248 /* the calling thread. */
249 #define PTHREAD_EXPLICIT_SCHED 2 /* set from provided attribute object */
251 /* P1003.1c/D10, p. 141 */
252 #define PTHREAD_CREATE_DETACHED 0
253 #define PTHREAD_CREATE_JOINABLE 1
255 typedef struct {
256 int is_initialized;
257 void *stackaddr;
258 int stacksize;
259 int contentionscope;
260 int inheritsched;
261 int schedpolicy;
262 struct sched_param schedparam;
264 /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute. */
265 #if defined(_POSIX_THREAD_CPUTIME)
266 int cputime_clock_allowed; /* see time.h */
267 #endif
268 int detachstate;
270 } pthread_attr_t;
272 #if defined(_POSIX_THREAD_PROCESS_SHARED)
273 /* NOTE: P1003.1c/D10, p. 81 defines following values for process_shared. */
275 #define PTHREAD_PROCESS_PRIVATE 0 /* visible within only the creating process */
276 #define PTHREAD_PROCESS_SHARED 1 /* visible too all processes with access to */
277 /* the memory where the resource is */
278 /* located */
279 #endif
281 #if defined(_POSIX_THREAD_PRIO_PROTECT)
282 /* Mutexes */
284 /* Values for blocking protocol. */
286 #define PTHREAD_PRIO_NONE 0
287 #define PTHREAD_PRIO_INHERIT 1
288 #define PTHREAD_PRIO_PROTECT 2
289 #endif
291 typedef __uint32_t pthread_mutex_t; /* identify a mutex */
293 typedef struct {
294 int is_initialized;
295 #if defined(_POSIX_THREAD_PROCESS_SHARED)
296 int process_shared; /* allow mutex to be shared amongst processes */
297 #endif
298 #if defined(_POSIX_THREAD_PRIO_PROTECT)
299 int prio_ceiling;
300 int protocol;
301 #endif
302 int recursive;
303 } pthread_mutexattr_t;
305 /* Condition Variables */
307 typedef __uint32_t pthread_cond_t; /* identify a condition variable */
309 typedef struct {
310 int is_initialized;
311 #if defined(_POSIX_THREAD_PROCESS_SHARED)
312 int process_shared; /* allow this to be shared amongst processes */
313 #endif
314 } pthread_condattr_t; /* a condition attribute object */
316 /* Keys */
318 typedef __uint32_t pthread_key_t; /* thread-specific data keys */
320 typedef struct {
321 int is_initialized; /* is this structure initialized? */
322 int init_executed; /* has the initialization routine been run? */
323 } pthread_once_t; /* dynamic package initialization */
324 #else
325 #if defined (__CYGWIN__) || defined (__MSYS__)
326 #include <cygwin/types.h>
327 #endif
328 #endif /* defined(_POSIX_THREADS) */
330 #endif /* defined(__rtems__) */
332 #endif /* _SYS_TYPES_H */