OSDN Git Service

* libc/include/sys/features.h: Add definition of all supported
[pf3gnuchains/pf3gnuchains4x.git] / newlib / libc / include / sys / types.h
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:
5
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;
12
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
16  */
17
18 #ifndef _SYS_TYPES_H
19
20 #include <_ansi.h>
21
22 #ifndef __INTTYPES_DEFINED__
23 #define __INTTYPES_DEFINED__
24
25 #include <machine/_types.h>
26
27 #if defined(__rtems__)
28 /*
29  *  The following section is RTEMS specific and is needed to more
30  *  closely match the types defined in the BSD sys/types.h.
31  *  This is needed to let the RTEMS/BSD TCP/IP stack compile.
32  */
33
34 /* deprecated */
35 #if ___int8_t_defined
36 typedef __uint8_t       u_int8_t;
37 #endif
38 #if ___int16_t_defined
39 typedef __uint16_t      u_int16_t;
40 #endif 
41 #if ___int32_t_defined
42 typedef __uint32_t      u_int32_t;
43 #endif
44
45 #if ___int64_t_defined
46 typedef __uint64_t      u_int64_t;
47
48 /* deprecated */
49 typedef __uint64_t      u_quad_t;
50 typedef __int64_t       quad_t;
51 typedef quad_t *        qaddr_t;
52 #endif
53
54 #endif
55
56 #endif /* ! __INTTYPES_DEFINED */
57
58 #ifndef __need_inttypes
59
60 #define _SYS_TYPES_H
61 #include <sys/_types.h>
62
63 #ifdef __i386__
64 #if defined (GO32) || defined (__MSDOS__)
65 #define __MS_types__
66 #endif
67 #endif
68
69 # include <stddef.h>
70 # include <machine/types.h>
71
72 /* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
73    changes, we assume sizeof short and long never change and have all types
74    used to define struct stat use them and not int where possible.
75    Where not possible, _ST_INTxx are used.  It would be preferable to not have
76    such assumptions, but until the extra fluff is necessary, it's avoided.
77    No 64 bit targets use stat yet.  What to do about them is postponed
78    until necessary.  */
79 #ifdef __GNUC__
80 #define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
81 #else
82 #define _ST_INT32
83 #endif
84
85 # ifndef        _POSIX_SOURCE
86
87 #  define       physadr         physadr_t
88 #  define       quad            quad_t
89
90 #ifndef _BSDTYPES_DEFINED
91 /* also defined in mingw/gmon.h and in w32api/winsock[2].h */
92 typedef unsigned char   u_char;
93 typedef unsigned short  u_short;
94 typedef unsigned int    u_int;
95 typedef unsigned long   u_long;
96 #define _BSDTYPES_DEFINED
97 #endif
98
99 typedef unsigned short  ushort;         /* System V compatibility */
100 typedef unsigned int    uint;           /* System V compatibility */
101 # endif /*!_POSIX_SOURCE */
102
103 #ifndef __clock_t_defined
104 typedef _CLOCK_T_ clock_t;
105 #define __clock_t_defined
106 #endif
107
108 #ifndef __time_t_defined
109 typedef _TIME_T_ time_t;
110 #define __time_t_defined
111
112 /* Time Value Specification Structures, P1003.1b-1993, p. 261 */
113
114 struct timespec {
115   time_t  tv_sec;   /* Seconds */
116   long    tv_nsec;  /* Nanoseconds */
117 };
118
119 struct itimerspec {
120   struct timespec  it_interval;  /* Timer period */
121   struct timespec  it_value;     /* Timer expiration */
122 };
123 #endif
124
125 typedef long    daddr_t;
126 typedef char *  caddr_t;
127
128 #ifndef __CYGWIN__
129 #if defined(__MS_types__) || defined(__rtems__) || \
130     defined(__sparc__) || defined(__SPU__)
131 typedef unsigned long   ino_t;
132 #else
133 typedef unsigned short  ino_t;
134 #endif
135 #endif /*__CYGWIN__*/
136
137 #ifdef __MS_types__
138 typedef unsigned long vm_offset_t;
139 typedef unsigned long vm_size_t;
140
141 #define __BIT_TYPES_DEFINED__
142
143 typedef signed char int8_t;
144 typedef unsigned char u_int8_t;
145 typedef short int16_t;
146 typedef unsigned short u_int16_t;
147 typedef int int32_t;
148 typedef unsigned int u_int32_t;
149 typedef long long int64_t;
150 typedef unsigned long long u_int64_t;
151 typedef int32_t register_t;
152 #endif /* __MS_types__ */
153
154 /*
155  * All these should be machine specific - right now they are all broken.
156  * However, for all of Cygnus' embedded targets, we want them to all be
157  * the same.  Otherwise things like sizeof (struct stat) might depend on
158  * how the file was compiled (e.g. -mint16 vs -mint32, etc.).
159  */
160
161 #if defined(__rtems__)
162 /* device numbers are 32-bit major and and 32-bit minor */
163 typedef unsigned long long dev_t;
164 #else
165 #ifndef __CYGWIN__
166 typedef short   dev_t;
167 #endif
168 #endif
169
170 #ifndef __CYGWIN__      /* which defines these types in it's own types.h. */
171 typedef long            off_t;
172
173 typedef unsigned short  uid_t;
174 typedef unsigned short  gid_t;
175 #endif
176
177 typedef int pid_t;
178 #ifndef __CYGWIN__
179 typedef long key_t;
180 #endif
181 typedef _ssize_t ssize_t;
182
183 #ifndef __CYGWIN__
184 #ifdef __MS_types__
185 typedef char *  addr_t;
186 typedef int mode_t;
187 #else
188 #if defined (__sparc__) && !defined (__sparc_v9__)
189 #ifdef __svr4__
190 typedef unsigned long mode_t;
191 #else
192 typedef unsigned short mode_t;
193 #endif
194 #else
195 typedef unsigned int mode_t _ST_INT32;
196 #endif
197 #endif /* ! __MS_types__ */
198 #endif /*__CYGWIN__*/
199
200 typedef unsigned short nlink_t;
201
202 /* We don't define fd_set and friends if we are compiling POSIX
203    source, or if we have included (or may include as indicated
204    by __USE_W32_SOCKETS) the W32api winsock[2].h header which
205    defines Windows versions of them.   Note that a program which
206    includes the W32api winsock[2].h header must know what it is doing;
207    it must not call the cygwin32 select function.
208 */
209 # if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) 
210 #  define _SYS_TYPES_FD_SET
211 #  define       NBBY    8               /* number of bits in a byte */
212 /*
213  * Select uses bit masks of file descriptors in longs.
214  * These macros manipulate such bit fields (the filesystem macros use chars).
215  * FD_SETSIZE may be defined by the user, but the default here
216  * should be >= NOFILE (param.h).
217  */
218 #  ifndef       FD_SETSIZE
219 #       define  FD_SETSIZE      64
220 #  endif
221
222 typedef long    fd_mask;
223 #  define       NFDBITS (sizeof (fd_mask) * NBBY)       /* bits per mask */
224 #  ifndef       howmany
225 #       define  howmany(x,y)    (((x)+((y)-1))/(y))
226 #  endif
227
228 /* We use a macro for fd_set so that including Sockets.h afterwards
229    can work.  */
230 typedef struct _types_fd_set {
231         fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
232 } _types_fd_set;
233
234 #define fd_set _types_fd_set
235
236 #  define       FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
237 #  define       FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
238 #  define       FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
239 #  define       FD_ZERO(p)      (__extension__ (void)({ \
240      size_t __i; \
241      char *__tmp = (char *)p; \
242      for (__i = 0; __i < sizeof (*(p)); ++__i) \
243        *__tmp++ = 0; \
244 }))
245
246 # endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) */
247
248 #undef __MS_types__
249 #undef _ST_INT32
250
251
252 #ifndef __clockid_t_defined
253 typedef _CLOCKID_T_ clockid_t;
254 #define __clockid_t_defined
255 #endif
256
257 #ifndef __timer_t_defined
258 typedef _TIMER_T_ timer_t;
259 #define __timer_t_defined
260 #endif
261
262 typedef unsigned long useconds_t;
263 typedef long suseconds_t;
264
265 #include <sys/features.h>
266
267
268 /* Cygwin will probably never have full posix compliance due to little things
269  * like an inability to set the stackaddress. Cygwin is also using void *  
270  * pointers rather than structs to ensure maximum binary compatability with
271  * previous releases.
272  * This means that we don't use the types defined here, but rather in
273  * <cygwin/types.h>
274  */
275 #if defined(_POSIX_THREADS) && !defined(__CYGWIN__)
276
277 #include <sys/sched.h>
278
279 /*
280  *  2.5 Primitive System Data Types,  P1003.1c/D10, p. 19.
281  */
282
283 typedef __uint32_t pthread_t;            /* identify a thread */
284
285 /* P1003.1c/D10, p. 118-119 */
286 #define PTHREAD_SCOPE_PROCESS 0
287 #define PTHREAD_SCOPE_SYSTEM  1
288
289 /* P1003.1c/D10, p. 111 */
290 #define PTHREAD_INHERIT_SCHED  1      /* scheduling policy and associated */
291                                       /*   attributes are inherited from */
292                                       /*   the calling thread. */
293 #define PTHREAD_EXPLICIT_SCHED 2      /* set from provided attribute object */
294
295 /* P1003.1c/D10, p. 141 */
296 #define PTHREAD_CREATE_DETACHED 0
297 #define PTHREAD_CREATE_JOINABLE  1
298
299 typedef struct {
300   int is_initialized;
301   void *stackaddr;
302   int stacksize;
303   int contentionscope;
304   int inheritsched;
305   int schedpolicy;
306   struct sched_param schedparam;
307
308   /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute.  */
309 #if defined(_POSIX_THREAD_CPUTIME)
310   int  cputime_clock_allowed;  /* see time.h */
311 #endif
312   int  detachstate;
313
314 } pthread_attr_t;
315
316 #if defined(_POSIX_THREAD_PROCESS_SHARED)
317 /* NOTE: P1003.1c/D10, p. 81 defines following values for process_shared.  */
318
319 #define PTHREAD_PROCESS_PRIVATE 0 /* visible within only the creating process */
320 #define PTHREAD_PROCESS_SHARED  1 /* visible too all processes with access to */
321                                   /*   the memory where the resource is */
322                                   /*   located */
323 #endif
324
325 #if defined(_POSIX_THREAD_PRIO_PROTECT)
326 /* Mutexes */
327
328 /* Values for blocking protocol. */
329
330 #define PTHREAD_PRIO_NONE    0
331 #define PTHREAD_PRIO_INHERIT 1
332 #define PTHREAD_PRIO_PROTECT 2
333 #endif
334
335 typedef __uint32_t pthread_mutex_t;      /* identify a mutex */
336
337 typedef struct {
338   int   is_initialized;
339 #if defined(_POSIX_THREAD_PROCESS_SHARED)
340   int   process_shared;  /* allow mutex to be shared amongst processes */
341 #endif
342 #if defined(_POSIX_THREAD_PRIO_PROTECT)
343   int   prio_ceiling;
344   int   protocol;
345 #endif
346   int   recursive;
347 } pthread_mutexattr_t;
348
349 /* Condition Variables */
350
351 typedef __uint32_t pthread_cond_t;       /* identify a condition variable */
352
353 typedef struct {
354   int   is_initialized;
355 #if defined(_POSIX_THREAD_PROCESS_SHARED)
356   int   process_shared;       /* allow this to be shared amongst processes */
357 #endif
358 } pthread_condattr_t;         /* a condition attribute object */
359
360 /* Keys */
361
362 typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
363
364 typedef struct {
365   int   is_initialized;  /* is this structure initialized? */
366   int   init_executed;   /* has the initialization routine been run? */
367 } pthread_once_t;       /* dynamic package initialization */
368 #else
369 #if defined (__CYGWIN__)
370 #include <cygwin/types.h>
371 #endif
372 #endif /* defined(_POSIX_THREADS) */
373
374 /* POSIX Barrier Types */
375
376 #if defined(_POSIX_BARRIERS)
377 typedef __uint32_t pthread_barrier_t;        /* POSIX Barrier Object */
378 typedef struct {
379   int   is_initialized;  /* is this structure initialized? */
380 #if defined(_POSIX_THREAD_PROCESS_SHARED)
381   int   process_shared;       /* allow this to be shared amongst processes */
382 #endif
383 } pthread_barrierattr_t;
384 #endif /* defined(_POSIX_BARRIERS) */
385
386 /* POSIX Spin Lock Types */
387
388 #if defined(_POSIX_SPIN_LOCKS)
389 typedef __uint32_t pthread_spinlock_t;        /* POSIX Spin Lock Object */
390 #endif /* defined(_POSIX_SPIN_LOCKS) */
391
392 /* POSIX Reader/Writer Lock Types */
393
394 #if !defined (__CYGWIN__)
395 #if defined(_POSIX_READER_WRITER_LOCKS)
396 typedef __uint32_t pthread_rwlock_t;         /* POSIX RWLock Object */
397 typedef struct {
398   int   is_initialized;       /* is this structure initialized? */
399 #if defined(_POSIX_THREAD_PROCESS_SHARED)
400   int   process_shared;       /* allow this to be shared amongst processes */
401 #endif
402 } pthread_rwlockattr_t;
403 #endif /* defined(_POSIX_READER_WRITER_LOCKS) */
404 #endif /* __CYGWIN__ */
405
406 #endif  /* !__need_inttypes */
407
408 #undef __need_inttypes
409
410 #endif  /* _SYS_TYPES_H */