FreeBSD/Linux Kernel Cross Reference
sys/sys/types.h
1 /* $NetBSD: types.h,v 1.66.2.1 2005/05/28 13:36:29 tron Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)types.h 8.4 (Berkeley) 1/21/94
37 */
38
39 #ifndef _SYS_TYPES_H_
40 #define _SYS_TYPES_H_
41
42 #include <sys/featuretest.h>
43
44 /* Machine type dependent parameters. */
45 #include <machine/types.h>
46
47 #include <machine/ansi.h>
48 #include <machine/int_types.h>
49
50
51 #include <sys/ansi.h>
52
53 #ifndef int8_t
54 typedef __int8_t int8_t;
55 #define int8_t __int8_t
56 #endif
57
58 #ifndef uint8_t
59 typedef __uint8_t uint8_t;
60 #define uint8_t __uint8_t
61 #endif
62
63 #ifndef int16_t
64 typedef __int16_t int16_t;
65 #define int16_t __int16_t
66 #endif
67
68 #ifndef uint16_t
69 typedef __uint16_t uint16_t;
70 #define uint16_t __uint16_t
71 #endif
72
73 #ifndef int32_t
74 typedef __int32_t int32_t;
75 #define int32_t __int32_t
76 #endif
77
78 #ifndef uint32_t
79 typedef __uint32_t uint32_t;
80 #define uint32_t __uint32_t
81 #endif
82
83 #ifndef int64_t
84 typedef __int64_t int64_t;
85 #define int64_t __int64_t
86 #endif
87
88 #ifndef uint64_t
89 typedef __uint64_t uint64_t;
90 #define uint64_t __uint64_t
91 #endif
92
93 typedef uint8_t u_int8_t;
94 typedef uint16_t u_int16_t;
95 typedef uint32_t u_int32_t;
96 typedef uint64_t u_int64_t;
97
98 #include <machine/endian.h>
99
100 #if defined(_NETBSD_SOURCE)
101 typedef unsigned char u_char;
102 typedef unsigned short u_short;
103 typedef unsigned int u_int;
104 typedef unsigned long u_long;
105
106 typedef unsigned char unchar; /* Sys V compatibility */
107 typedef unsigned short ushort; /* Sys V compatibility */
108 typedef unsigned int uint; /* Sys V compatibility */
109 typedef unsigned long ulong; /* Sys V compatibility */
110
111 typedef u_long cpuid_t;
112 #endif
113
114 typedef uint64_t u_quad_t; /* quads */
115 typedef int64_t quad_t;
116 typedef quad_t * qaddr_t;
117
118 /*
119 * The types longlong_t and u_longlong_t exist for use with the
120 * Sun-derived XDR routines involving these types, and their usage
121 * in other contexts is discouraged. Further note that these types
122 * may not be equivalent to "long long" and "unsigned long long",
123 * they are only guaranteed to be signed and unsigned 64-bit types
124 * respectively. Portable programs that need 64-bit types should use
125 * the C99 types int64_t and uint64_t instead.
126 */
127
128 typedef int64_t longlong_t; /* for XDR */
129 typedef uint64_t u_longlong_t; /* for XDR */
130
131 typedef int64_t blkcnt_t; /* fs block count */
132 typedef uint32_t blksize_t; /* fs optimal block size */
133
134 #ifndef fsblkcnt_t
135 typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */
136 #define fsblkcnt_t __fsblkcnt_t
137 #endif
138
139 #ifndef fsfilcnt_t
140 typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */
141 #define fsfilcnt_t __fsfilcnt_t
142 #endif
143
144 #ifndef caddr_t
145 typedef __caddr_t caddr_t; /* core address */
146 #define caddr_t __caddr_t
147 #endif
148
149 #ifdef __daddr_t
150 typedef __daddr_t daddr_t; /* disk address */
151 #undef __daddr_t
152 #else
153 typedef int64_t daddr_t; /* disk address */
154 #endif
155
156 typedef uint32_t dev_t; /* device number */
157 typedef uint32_t fixpt_t; /* fixed point number */
158
159 #ifndef gid_t
160 typedef __gid_t gid_t; /* group id */
161 #define gid_t __gid_t
162 #endif
163
164 typedef uint32_t id_t; /* group id, process id or user id */
165 typedef uint32_t ino_t; /* inode number */
166 typedef long key_t; /* IPC key (for Sys V IPC) */
167
168 #ifndef mode_t
169 typedef __mode_t mode_t; /* permissions */
170 #define mode_t __mode_t
171 #endif
172
173 typedef uint32_t nlink_t; /* link count */
174
175 #ifndef off_t
176 typedef __off_t off_t; /* file offset */
177 #define off_t __off_t
178 #endif
179
180 #ifndef pid_t
181 typedef __pid_t pid_t; /* process id */
182 #define pid_t __pid_t
183 #endif
184 typedef int32_t lwpid_t; /* LWP id */
185 typedef quad_t rlim_t; /* resource limit */
186 typedef int32_t segsz_t; /* segment size */
187 typedef int32_t swblk_t; /* swap offset */
188
189 #ifndef uid_t
190 typedef __uid_t uid_t; /* user id */
191 #define uid_t __uid_t
192 #endif
193
194 typedef int32_t dtime_t; /* on-disk time_t */
195
196 #if defined(_KERNEL)
197 typedef int boolean_t;
198 #ifndef TRUE
199 #define TRUE 1
200 #endif
201 #ifndef FALSE
202 #define FALSE 0
203 #endif
204 #endif
205
206 #if defined(_KERNEL) || defined(_LIBC)
207 /*
208 * semctl(2)'s argument structure. This is here for the benefit of
209 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2.
210 * The SUSv2 semctl(2) takes variable arguments.
211 */
212 union __semun {
213 int val; /* value for SETVAL */
214 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
215 unsigned short *array; /* array for GETALL & SETALL */
216 };
217 /* For the same reason as above */
218 #include <sys/stdint.h>
219 typedef intptr_t semid_t;
220 #endif /* _KERNEL || _LIBC */
221
222 /*
223 * These belong in unistd.h, but are placed here too to ensure that
224 * long arguments will be promoted to off_t if the program fails to
225 * include that header or explicitly cast them to off_t.
226 */
227 #if defined(_NETBSD_SOURCE)
228 #ifndef __OFF_T_SYSCALLS_DECLARED
229 #define __OFF_T_SYSCALLS_DECLARED
230 #ifndef _KERNEL
231 #include <sys/cdefs.h>
232 __BEGIN_DECLS
233 off_t lseek(int, off_t, int);
234 int ftruncate(int, off_t);
235 int truncate(const char *, off_t);
236 __END_DECLS
237 #endif /* !_KERNEL */
238 #endif /* __OFF_T_SYSCALLS_DECLARED */
239 #endif /* defined(_NETBSD_SOURCE) */
240
241 #if defined(_NETBSD_SOURCE)
242 /* Major, minor numbers, dev_t's. */
243 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
244 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
245 (((x) & 0x000000ff) >> 0)))
246 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
247 (((y) << 12) & 0xfff00000) | \
248 (((y) << 0) & 0x000000ff)))
249 #endif
250
251 #ifdef _BSD_CLOCK_T_
252 typedef _BSD_CLOCK_T_ clock_t;
253 #undef _BSD_CLOCK_T_
254 #endif
255
256 #ifdef _BSD_SIZE_T_
257 typedef _BSD_SIZE_T_ size_t;
258 #define _SIZE_T
259 #undef _BSD_SIZE_T_
260 #endif
261
262 #ifdef _BSD_SSIZE_T_
263 typedef _BSD_SSIZE_T_ ssize_t;
264 #undef _BSD_SSIZE_T_
265 #endif
266
267 #ifdef _BSD_TIME_T_
268 typedef _BSD_TIME_T_ time_t;
269 #undef _BSD_TIME_T_
270 #endif
271
272 #ifdef _BSD_CLOCKID_T_
273 typedef _BSD_CLOCKID_T_ clockid_t;
274 #undef _BSD_CLOCKID_T_
275 #endif
276
277 #ifdef _BSD_TIMER_T_
278 typedef _BSD_TIMER_T_ timer_t;
279 #undef _BSD_TIMER_T_
280 #endif
281
282 #ifdef _BSD_SUSECONDS_T_
283 typedef _BSD_SUSECONDS_T_ suseconds_t;
284 #undef _BSD_SUSECONDS_T_
285 #endif
286
287 #ifdef _BSD_USECONDS_T_
288 typedef _BSD_USECONDS_T_ useconds_t;
289 #undef _BSD_USECONDS_T_
290 #endif
291
292 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
293 (_POSIX_C_SOURCE - 0) >= 200112L || \
294 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
295
296 /*
297 * Implementation dependent defines, hidden from user space. X/Open does not
298 * specify them.
299 */
300 #define __NBBY 8 /* number of bits in a byte */
301 typedef int32_t __fd_mask;
302
303 /* bits per mask */
304 #define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)
305
306 #ifndef howmany
307 #define __howmany(x, y) (((x) + ((y) - 1)) / (y))
308 #else
309 #define __howmany(x, y) howmany(x, y)
310 #endif
311
312 /*
313 * Select uses bit masks of file descriptors in longs. These macros
314 * manipulate such bit fields (the filesystem macros use chars).
315 * FD_SETSIZE may be defined by the user, but the default here should
316 * be enough for most uses.
317 */
318 #ifndef FD_SETSIZE
319 #define FD_SETSIZE 256
320 #endif
321
322 typedef struct fd_set {
323 __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
324 } fd_set;
325
326 #define FD_SET(n, p) \
327 ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))
328 #define FD_CLR(n, p) \
329 ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))
330 #define FD_ISSET(n, p) \
331 ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))
332 #if __GNUC_PREREQ__(2, 95)
333 #define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p)))
334 #else
335 #define FD_ZERO(p) do { \
336 fd_set *__fds = (p); \
337 unsigned int __i; \
338 for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
339 __fds->fds_bits[__i] = 0; \
340 } while (/* CONSTCOND */ 0)
341 #endif /* GCC 2.95 */
342
343 /*
344 * Expose our internals if we are not required to hide them.
345 */
346 #if defined(_NETBSD_SOURCE)
347
348 #define NBBY __NBBY
349 #define fd_mask __fd_mask
350 #define NFDBITS __NFDBITS
351 #ifndef howmany
352 #define howmany(a, b) __howmany(a, b)
353 #endif
354
355 #if __GNUC_PREREQ__(2, 95)
356 #define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f)))
357 #else
358 #define FD_COPY(f, t) do { \
359 fd_set *__f = (f), *__t = (t); \
360 unsigned int __i; \
361 for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
362 __t->fds_bits[__i] = __f->fds_bits[__i]; \
363 } while (/* CONSTCOND */ 0)
364 #endif /* GCC 2.95 */
365
366 #endif
367
368 #if defined(__STDC__) && defined(_KERNEL)
369 /*
370 * Forward structure declarations for function prototypes. We include the
371 * common structures that cross subsystem boundaries here; others are mostly
372 * used in the same place that the structure is defined.
373 */
374 struct lwp;
375 struct user;
376 struct __ucontext;
377 struct proc;
378 struct pgrp;
379 struct ucred;
380 struct rusage;
381 struct file;
382 struct buf;
383 struct tty;
384 struct uio;
385 #endif
386
387 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
388
389 #if !defined(_KERNEL) && !defined(_STANDALONE)
390 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
391 defined(_NETBSD_SOURCE)
392 #include <pthread_types.h>
393 #endif
394 #endif
395
396 #endif /* !_SYS_TYPES_H_ */
Cache object: 9cfc88f29b94fdf9d444eddfc2b23a6e
|