FreeBSD/Linux Kernel Cross Reference
sys/sys/types.h
1 /* $NetBSD: types.h,v 1.62 2003/08/07 16:34:21 agc 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 caddr_t
135 typedef __caddr_t caddr_t; /* core address */
136 #define caddr_t __caddr_t
137 #endif
138
139 #ifdef __daddr_t
140 typedef __daddr_t daddr_t; /* disk address */
141 #undef __daddr_t
142 #else
143 typedef int64_t daddr_t; /* disk address */
144 #endif
145
146 typedef uint32_t dev_t; /* device number */
147 typedef uint32_t fixpt_t; /* fixed point number */
148
149 #ifndef gid_t
150 typedef __gid_t gid_t; /* group id */
151 #define gid_t __gid_t
152 #endif
153
154 typedef uint32_t id_t; /* group id, process id or user id */
155 typedef uint32_t ino_t; /* inode number */
156 typedef long key_t; /* IPC key (for Sys V IPC) */
157
158 #ifndef mode_t
159 typedef __mode_t mode_t; /* permissions */
160 #define mode_t __mode_t
161 #endif
162
163 typedef uint32_t nlink_t; /* link count */
164
165 #ifndef off_t
166 typedef __off_t off_t; /* file offset */
167 #define off_t __off_t
168 #endif
169
170 #ifndef pid_t
171 typedef __pid_t pid_t; /* process id */
172 #define pid_t __pid_t
173 #endif
174 typedef int32_t lwpid_t; /* LWP id */
175 typedef quad_t rlim_t; /* resource limit */
176 typedef int32_t segsz_t; /* segment size */
177 typedef int32_t swblk_t; /* swap offset */
178
179 #ifndef uid_t
180 typedef __uid_t uid_t; /* user id */
181 #define uid_t __uid_t
182 #endif
183
184 typedef int32_t dtime_t; /* on-disk time_t */
185
186 #if defined(_KERNEL)
187 typedef int boolean_t;
188 #ifndef TRUE
189 #define TRUE 1
190 #endif
191 #ifndef FALSE
192 #define FALSE 0
193 #endif
194 #endif
195
196 #if defined(_KERNEL) || defined(_LIBC)
197 /*
198 * semctl(2)'s argument structure. This is here for the benefit of
199 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2.
200 * The SUSv2 semctl(2) takes variable arguments.
201 */
202 union __semun {
203 int val; /* value for SETVAL */
204 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
205 unsigned short *array; /* array for GETALL & SETALL */
206 };
207 /* For the same reason as above */
208 #include <sys/stdint.h>
209 typedef intptr_t semid_t;
210 #endif /* _KERNEL || _LIBC */
211
212 /*
213 * These belong in unistd.h, but are placed here too to ensure that
214 * long arguments will be promoted to off_t if the program fails to
215 * include that header or explicitly cast them to off_t.
216 */
217 #if defined(_NETBSD_SOURCE)
218 #ifndef __OFF_T_SYSCALLS_DECLARED
219 #define __OFF_T_SYSCALLS_DECLARED
220 #ifndef _KERNEL
221 #include <sys/cdefs.h>
222 __BEGIN_DECLS
223 off_t lseek __P((int, off_t, int));
224 int ftruncate __P((int, off_t));
225 int truncate __P((const char *, off_t));
226 __END_DECLS
227 #endif /* !_KERNEL */
228 #endif /* __OFF_T_SYSCALLS_DECLARED */
229 #endif /* defined(_NETBSD_SOURCE) */
230
231 #if defined(_NETBSD_SOURCE)
232 /* Major, minor numbers, dev_t's. */
233 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
234 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
235 (((x) & 0x000000ff) >> 0)))
236 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
237 (((y) << 12) & 0xfff00000) | \
238 (((y) << 0) & 0x000000ff)))
239 #endif
240
241 #ifdef _BSD_CLOCK_T_
242 typedef _BSD_CLOCK_T_ clock_t;
243 #undef _BSD_CLOCK_T_
244 #endif
245
246 #ifdef _BSD_SIZE_T_
247 typedef _BSD_SIZE_T_ size_t;
248 #define _SIZE_T
249 #undef _BSD_SIZE_T_
250 #endif
251
252 #ifdef _BSD_SSIZE_T_
253 typedef _BSD_SSIZE_T_ ssize_t;
254 #undef _BSD_SSIZE_T_
255 #endif
256
257 #ifdef _BSD_TIME_T_
258 typedef _BSD_TIME_T_ time_t;
259 #undef _BSD_TIME_T_
260 #endif
261
262 #ifdef _BSD_CLOCKID_T_
263 typedef _BSD_CLOCKID_T_ clockid_t;
264 #undef _BSD_CLOCKID_T_
265 #endif
266
267 #ifdef _BSD_TIMER_T_
268 typedef _BSD_TIMER_T_ timer_t;
269 #undef _BSD_TIMER_T_
270 #endif
271
272 #ifdef _BSD_SUSECONDS_T_
273 typedef _BSD_SUSECONDS_T_ suseconds_t;
274 #undef _BSD_SUSECONDS_T_
275 #endif
276
277 #ifdef _BSD_USECONDS_T_
278 typedef _BSD_USECONDS_T_ useconds_t;
279 #undef _BSD_USECONDS_T_
280 #endif
281
282 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
283 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
284
285 /*
286 * Implementation dependent defines, hidden from user space. X/Open does not
287 * specify them.
288 */
289 #define __NBBY 8 /* number of bits in a byte */
290 typedef int32_t __fd_mask;
291 #define __NFDBITS (sizeof(__fd_mask) * __NBBY) /* bits per mask */
292
293 #ifndef howmany
294 #define __howmany(x, y) (((x) + ((y) - 1)) / (y))
295 #else
296 #define __howmany(x, y) howmany(x, y)
297 #endif
298
299 /*
300 * Select uses bit masks of file descriptors in longs. These macros
301 * manipulate such bit fields (the filesystem macros use chars).
302 * FD_SETSIZE may be defined by the user, but the default here should
303 * be enough for most uses.
304 */
305 #ifndef FD_SETSIZE
306 #define FD_SETSIZE 256
307 #endif
308
309 typedef struct fd_set {
310 __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
311 } fd_set;
312
313 #define FD_SET(n, p) \
314 ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))
315 #define FD_CLR(n, p) \
316 ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))
317 #define FD_ISSET(n, p) \
318 ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))
319 #define FD_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
320
321 /*
322 * Expose our internals if we are not required to hide them.
323 */
324 #if defined(_NETBSD_SOURCE)
325
326 #define NBBY __NBBY
327 #define fd_mask __fd_mask
328 #define NFDBITS __NFDBITS
329 #ifndef howmany
330 #define howmany(a, b) __howmany(a, b)
331 #endif
332
333 #define FD_COPY(f, t) (void)memcpy((t), (f), sizeof(*(f)))
334
335 #endif
336
337 #if defined(__STDC__) && defined(_KERNEL)
338 /*
339 * Forward structure declarations for function prototypes. We include the
340 * common structures that cross subsystem boundaries here; others are mostly
341 * used in the same place that the structure is defined.
342 */
343 struct lwp;
344 struct user;
345 struct __ucontext;
346 struct proc;
347 struct pgrp;
348 struct ucred;
349 struct rusage;
350 struct file;
351 struct buf;
352 struct tty;
353 struct uio;
354 #endif
355
356 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
357
358 #if !defined(_KERNEL) && !defined(_STANDALONE)
359 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
360 defined(_NETBSD_SOURCE)
361 #include <pthread_types.h>
362 #endif
363 #endif
364
365 #endif /* !_SYS_TYPES_H_ */
Cache object: 13f7ebeecf65f22374f5709cddee693e
|