xref: /original-bsd/sys/sys/types.h (revision deff14a8)
1 /*-
2  * Copyright (c) 1982, 1986, 1991, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)types.h	8.5 (Berkeley) 07/10/94
13  */
14 
15 #ifndef _SYS_TYPES_H_
16 #define	_SYS_TYPES_H_
17 
18 /* Machine type dependent parameters. */
19 #include <machine/ansi.h>
20 #include <machine/types.h>
21 
22 #ifndef _POSIX_SOURCE
23 typedef	unsigned char	u_char;
24 typedef	unsigned short	u_short;
25 typedef	unsigned int	u_int;
26 typedef	unsigned long	u_long;
27 typedef	unsigned short	ushort;		/* Sys V compatibility */
28 typedef	unsigned int	uint;		/* Sys V compatibility */
29 #endif
30 
31 typedef	u_int64_t	u_quad_t;	/* quads */
32 typedef	int64_t		quad_t;
33 typedef	quad_t *	qaddr_t;
34 
35 typedef	char *		caddr_t;	/* core address */
36 typedef	int32_t		daddr_t;	/* disk address */
37 typedef	u_int32_t	dev_t;		/* device number */
38 typedef u_int32_t	fixpt_t;	/* fixed point number */
39 typedef	u_int32_t	gid_t;		/* group id */
40 typedef	u_int32_t	ino_t;		/* inode number */
41 typedef	u_int16_t	mode_t;		/* permissions */
42 typedef	u_int16_t	nlink_t;	/* link count */
43 typedef	quad_t		off_t;		/* file offset */
44 typedef	int32_t		pid_t;		/* process id */
45 typedef	int32_t		segsz_t;	/* segment size */
46 typedef	int32_t		swblk_t;	/* swap offset */
47 typedef	u_int32_t	uid_t;		/* user id */
48 
49 /*
50  * This belongs in unistd.h, but is placed here to ensure that programs
51  * casting the second parameter of lseek to off_t will get the correct
52  * version of lseek.
53  */
54 #ifndef KERNEL
55 #include <sys/cdefs.h>
56 __BEGIN_DECLS
57 off_t	 lseek __P((int, off_t, int));
58 __END_DECLS
59 #endif
60 
61 #ifndef _POSIX_SOURCE
62 							/* major number */
63 #define	major(x)	((int32_t)(((u_int32_t)(x) >> 8) & 0xff))
64 #define	minor(x)	((int32_t)((x) & 0xff))		/* minor number */
65 #define	makedev(x,y)	((dev_t)(((x) << 8) | (y)))	/* create dev_t */
66 #endif
67 
68 #include <machine/endian.h>
69 
70 #ifdef	_BSD_CLOCK_T_
71 typedef	_BSD_CLOCK_T_	clock_t;
72 #undef	_BSD_CLOCK_T_
73 #endif
74 
75 #ifdef	_BSD_SIZE_T_
76 typedef	_BSD_SIZE_T_	size_t;
77 #undef	_BSD_SIZE_T_
78 #endif
79 
80 #ifdef	_BSD_SSIZE_T_
81 typedef	_BSD_SSIZE_T_	ssize_t;
82 #undef	_BSD_SSIZE_T_
83 #endif
84 
85 #ifdef	_BSD_TIME_T_
86 typedef	_BSD_TIME_T_	time_t;
87 #undef	_BSD_TIME_T_
88 #endif
89 
90 #ifndef _POSIX_SOURCE
91 #define	NBBY	8		/* number of bits in a byte */
92 
93 /*
94  * Select uses bit masks of file descriptors in longs.  These macros
95  * manipulate such bit fields (the filesystem macros use chars).
96  * FD_SETSIZE may be defined by the user, but the default here should
97  * be enough for most uses.
98  */
99 #ifndef	FD_SETSIZE
100 #define	FD_SETSIZE	256
101 #endif
102 
103 typedef int32_t	fd_mask;
104 #define NFDBITS	(sizeof(fd_mask) * NBBY)	/* bits per mask */
105 
106 #ifndef howmany
107 #define	howmany(x, y)	(((x) + ((y) - 1)) / (y))
108 #endif
109 
110 typedef	struct fd_set {
111 	fd_mask	fds_bits[howmany(FD_SETSIZE, NFDBITS)];
112 } fd_set;
113 
114 #define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
115 #define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
116 #define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
117 #define	FD_COPY(f, t)	bcopy(f, t, sizeof(*(f)))
118 #define	FD_ZERO(p)	bzero(p, sizeof(*(p)))
119 
120 #if defined(__STDC__) && defined(KERNEL)
121 /*
122  * Forward structure declarations for function prototypes.  We include the
123  * common structures that cross subsystem boundaries here; others are mostly
124  * used in the same place that the structure is defined.
125  */
126 struct	proc;
127 struct	pgrp;
128 struct	ucred;
129 struct	rusage;
130 struct	file;
131 struct	buf;
132 struct	tty;
133 struct	uio;
134 #endif
135 
136 #endif /* !_POSIX_SOURCE */
137 #endif /* !_SYS_TYPES_H_ */
138