1 /**	$MirOS: src/sys/sys/types.h,v 1.8 2007/05/18 00:47:58 tg Exp $ */
2 /*	$OpenBSD: types.h,v 1.26 2004/07/13 21:04:29 millert Exp $	*/
3 /*	$NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $	*/
4 
5 /*-
6  * Copyright (c) 1982, 1986, 1991, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  * (c) UNIX System Laboratories, Inc.
9  * All or some portions of this file are derived from material licensed
10  * to the University of California by American Telephone and Telegraph
11  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12  * the permission of UNIX System Laboratories, Inc.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)types.h	8.4 (Berkeley) 1/21/94
39  */
40 
41 #ifndef _SYS_TYPES_H_
42 #define	_SYS_TYPES_H_
43 
44 /* Machine type dependent parameters. */
45 #include <machine/types.h>
46 
47 #include <machine/ansi.h>
48 #include <machine/endian.h>
49 
50 #ifdef __NEED_NETBSD_COMPAT
51 typedef int8_t		__int8_t;
52 typedef int16_t		__int16_t;
53 typedef int32_t		__int32_t;
54 typedef int64_t		__int64_t;
55 typedef uint8_t		__uint8_t;
56 typedef uint16_t	__uint16_t;
57 typedef uint32_t	__uint32_t;
58 typedef uint64_t	__uint64_t;
59 typedef intptr_t	__intptr_t;
60 typedef uintptr_t	__uintptr_t;
61 #endif
62 
63 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
64 typedef	unsigned char	u_char;
65 typedef	unsigned short	u_short;
66 typedef	unsigned int	u_int;
67 typedef	unsigned long	u_long;
68 
69 typedef unsigned char	unchar;		/* Sys V compatibility */
70 typedef	unsigned short	ushort;		/* Sys V compatibility */
71 typedef	unsigned int	uint;		/* Sys V compatibility */
72 typedef unsigned long	ulong;		/* Sys V compatibility */
73 
74 typedef	unsigned long	cpuid_t;
75 #endif
76 
77 typedef	u_int64_t	u_quad_t;	/* quads */
78 typedef	int64_t		quad_t;
79 typedef	quad_t *	qaddr_t;
80 
81 typedef	char *		caddr_t;	/* core address */
82 typedef	int32_t		daddr_t;	/* disk address */
83 typedef	int32_t		dev_t;		/* device number */
84 typedef	u_int32_t	fixpt_t;	/* fixed point number */
85 typedef	u_int32_t	gid_t;		/* group id */
86 typedef	u_int32_t	id_t;		/* may contain pid, uid or gid */
87 typedef	u_int32_t	ino_t;		/* inode number */
88 typedef	long		key_t;		/* IPC key (for Sys V IPC) */
89 typedef	u_int32_t	mode_t;		/* permissions */
90 typedef	u_int32_t	nlink_t;	/* link count */
91 typedef	int32_t		pid_t;		/* process id */
92 typedef u_quad_t	rlim_t;		/* resource limit */
93 typedef	int32_t		segsz_t;	/* segment size */
94 typedef	int32_t		swblk_t;	/* swap offset */
95 typedef	u_int32_t	uid_t;		/* user id */
96 typedef	u_int32_t	useconds_t;	/* microseconds */
97 typedef	int32_t		suseconds_t;	/* microseconds (signed) */
98 
99 /*
100  * XPG4.2 states that inclusion of <netinet/in.h> must pull these
101  * in and that inclusion of <sys/socket.h> must pull in sa_family_t.
102  * We put these here because there are other headers that require
103  * these types and <sys/socket.h> and <netinet/in.h> will indirectly
104  * include <sys/types.h>.  Thus we are compliant without too many hoops.
105  */
106 typedef u_int32_t	in_addr_t;	/* base type for internet address */
107 typedef u_int16_t	in_port_t;	/* IP port type */
108 typedef u_int8_t	sa_family_t;	/* sockaddr address family type */
109 typedef u_int32_t	socklen_t;	/* length type for network syscalls */
110 
111 #ifdef	_BSD_CLOCK_T_
112 typedef	_BSD_CLOCK_T_	clock_t;
113 #undef	_BSD_CLOCK_T_
114 #endif
115 
116 #if !defined(_GCC_SIZE_T)
117 #define	_GCC_SIZE_T
118 typedef	__SIZE_TYPE__	size_t;
119 #endif
120 
121 /* e-eeeevil kludge, but apparently works */
122 #define unsigned	signed
123 typedef	__SIZE_TYPE__	ssize_t;
124 #undef unsigned
125 
126 #ifdef	_BSD_TIME_T_
127 typedef	_BSD_TIME_T_	time_t;
128 #undef	_BSD_TIME_T_
129 #endif
130 
131 #ifdef	_BSD_CLOCKID_T_
132 typedef	_BSD_CLOCKID_T_	clockid_t;
133 #undef	_BSD_CLOCKID_T_
134 #endif
135 
136 #ifdef	_BSD_TIMER_T_
137 typedef	_BSD_TIMER_T_	timer_t;
138 #undef	_BSD_TIMER_T_
139 #endif
140 
141 #ifdef	_BSD_OFF_T_
142 typedef	_BSD_OFF_T_	off_t;
143 #undef	_BSD_OFF_T_
144 #endif
145 
146 /*
147  * These belong in unistd.h, but are placed here too to ensure that
148  * long arguments will be promoted to off_t if the program fails to
149  * include that header or explicitly cast them to off_t.
150  */
151 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
152 #ifndef _KERNEL
153 #include <sys/cdefs.h>
154 __BEGIN_DECLS
155 off_t	 lseek(int, off_t, int);
156 int	 ftruncate(int, off_t);
157 int	 truncate(const char *, off_t);
158 __END_DECLS
159 #endif /* !_KERNEL */
160 #endif /* !defined(_POSIX_SOURCE) ... */
161 
162 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
163 /* Major, minor numbers, dev_t's. */
164 #define	major(x)	((int32_t)(((u_int32_t)(x) >> 8) & 0xff))
165 #define	minor(x)	((int32_t)((x) & 0xff) | (((x) & 0xffff0000) >> 8))
166 #define	makedev(x,y)	((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) & 0xffff00) << 8)))
167 #endif
168 
169 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
170 #define	NBBY	8		/* number of bits in a byte */
171 
172 /*
173  * Select uses bit masks of file descriptors in longs.  These macros
174  * manipulate such bit fields (the filesystem macros use chars).
175  * FD_SETSIZE may be defined by the user, but the default here should
176  * be enough for most uses.
177  */
178 #ifndef	FD_SETSIZE
179 #define	FD_SETSIZE	1024
180 #endif
181 
182 typedef int32_t	fd_mask;
183 #define NFDBITS	(sizeof(fd_mask) * NBBY)	/* bits per mask */
184 
185 #ifndef howmany
186 #define	howmany(x, y)	(((x) + ((y) - 1)) / (y))
187 #endif
188 
189 typedef	struct fd_set {
190 	fd_mask	fds_bits[howmany(FD_SETSIZE, NFDBITS)];
191 } fd_set;
192 
193 #define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
194 #define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
195 #define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
196 #define	FD_COPY(f, t)	memcpy(t, f, sizeof(*(f)))
197 #define	FD_ZERO(p)	memset(p, 0, sizeof(*(p)))
198 
199 #if defined(__STDC__) && defined(_KERNEL)
200 /*
201  * Forward structure declarations for function prototypes.  We include the
202  * common structures that cross subsystem boundaries here; others are mostly
203  * used in the same place that the structure is defined.
204  */
205 struct	proc;
206 struct	pgrp;
207 struct	ucred;
208 struct	rusage;
209 struct	file;
210 struct	buf;
211 struct	tty;
212 struct	uio;
213 #endif
214 
215 #endif /* !defined(_POSIX_SOURCE) ... */
216 #endif /* !_SYS_TYPES_H_ */
217