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