xref: /titanic_54/usr/src/boot/lib/libstand/stand.h (revision 4a5d661a82b942b6538acd26209d959ce98b593a)
1*4a5d661aSToomas Soome /*
2*4a5d661aSToomas Soome  * Copyright (c) 1998 Michael Smith.
3*4a5d661aSToomas Soome  * All rights reserved.
4*4a5d661aSToomas Soome  *
5*4a5d661aSToomas Soome  * Redistribution and use in source and binary forms, with or without
6*4a5d661aSToomas Soome  * modification, are permitted provided that the following conditions
7*4a5d661aSToomas Soome  * are met:
8*4a5d661aSToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*4a5d661aSToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12*4a5d661aSToomas Soome  *    documentation and/or other materials provided with the distribution.
13*4a5d661aSToomas Soome  *
14*4a5d661aSToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*4a5d661aSToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*4a5d661aSToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*4a5d661aSToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*4a5d661aSToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*4a5d661aSToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*4a5d661aSToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*4a5d661aSToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*4a5d661aSToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*4a5d661aSToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*4a5d661aSToomas Soome  * SUCH DAMAGE.
25*4a5d661aSToomas Soome  *
26*4a5d661aSToomas Soome  * $FreeBSD$
27*4a5d661aSToomas Soome  * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
28*4a5d661aSToomas Soome  */
29*4a5d661aSToomas Soome 
30*4a5d661aSToomas Soome /*-
31*4a5d661aSToomas Soome  * Copyright (c) 1993
32*4a5d661aSToomas Soome  *	The Regents of the University of California.  All rights reserved.
33*4a5d661aSToomas Soome  *
34*4a5d661aSToomas Soome  * Redistribution and use in source and binary forms, with or without
35*4a5d661aSToomas Soome  * modification, are permitted provided that the following conditions
36*4a5d661aSToomas Soome  * are met:
37*4a5d661aSToomas Soome  * 1. Redistributions of source code must retain the above copyright
38*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer.
39*4a5d661aSToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
40*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer in the
41*4a5d661aSToomas Soome  *    documentation and/or other materials provided with the distribution.
42*4a5d661aSToomas Soome  * 4. Neither the name of the University nor the names of its contributors
43*4a5d661aSToomas Soome  *    may be used to endorse or promote products derived from this software
44*4a5d661aSToomas Soome  *    without specific prior written permission.
45*4a5d661aSToomas Soome  *
46*4a5d661aSToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47*4a5d661aSToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48*4a5d661aSToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49*4a5d661aSToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50*4a5d661aSToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51*4a5d661aSToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52*4a5d661aSToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53*4a5d661aSToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54*4a5d661aSToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55*4a5d661aSToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56*4a5d661aSToomas Soome  * SUCH DAMAGE.
57*4a5d661aSToomas Soome  *
58*4a5d661aSToomas Soome  *	@(#)stand.h	8.1 (Berkeley) 6/11/93
59*4a5d661aSToomas Soome  */
60*4a5d661aSToomas Soome 
61*4a5d661aSToomas Soome #ifndef	STAND_H
62*4a5d661aSToomas Soome #define	STAND_H
63*4a5d661aSToomas Soome 
64*4a5d661aSToomas Soome #include <sys/types.h>
65*4a5d661aSToomas Soome #include <sys/cdefs.h>
66*4a5d661aSToomas Soome #include <sys/stat.h>
67*4a5d661aSToomas Soome #include <sys/dirent.h>
68*4a5d661aSToomas Soome 
69*4a5d661aSToomas Soome /* this header intentionally exports NULL from <string.h> */
70*4a5d661aSToomas Soome #include <string.h>
71*4a5d661aSToomas Soome 
72*4a5d661aSToomas Soome #define CHK(fmt, args...)	printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
73*4a5d661aSToomas Soome #define PCHK(fmt, args...)	{printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
74*4a5d661aSToomas Soome 
75*4a5d661aSToomas Soome /* Avoid unwanted userlandish components */
76*4a5d661aSToomas Soome #define _KERNEL
77*4a5d661aSToomas Soome #include <sys/errno.h>
78*4a5d661aSToomas Soome #undef _KERNEL
79*4a5d661aSToomas Soome 
80*4a5d661aSToomas Soome /* special stand error codes */
81*4a5d661aSToomas Soome #define	EADAPT	(ELAST+1)	/* bad adaptor */
82*4a5d661aSToomas Soome #define	ECTLR	(ELAST+2)	/* bad controller */
83*4a5d661aSToomas Soome #define	EUNIT	(ELAST+3)	/* bad unit */
84*4a5d661aSToomas Soome #define ESLICE	(ELAST+4)	/* bad slice */
85*4a5d661aSToomas Soome #define	EPART	(ELAST+5)	/* bad partition */
86*4a5d661aSToomas Soome #define	ERDLAB	(ELAST+6)	/* can't read disk label */
87*4a5d661aSToomas Soome #define	EUNLAB	(ELAST+7)	/* unlabeled disk */
88*4a5d661aSToomas Soome #define	EOFFSET	(ELAST+8)	/* relative seek not supported */
89*4a5d661aSToomas Soome #define	ESALAST	(ELAST+8)	/* */
90*4a5d661aSToomas Soome 
91*4a5d661aSToomas Soome struct open_file;
92*4a5d661aSToomas Soome 
93*4a5d661aSToomas Soome /*
94*4a5d661aSToomas Soome  * This structure is used to define file system operations in a file system
95*4a5d661aSToomas Soome  * independent way.
96*4a5d661aSToomas Soome  *
97*4a5d661aSToomas Soome  * XXX note that filesystem providers should export a pointer to their fs_ops
98*4a5d661aSToomas Soome  *     struct, so that consumers can reference this and thus include the
99*4a5d661aSToomas Soome  *     filesystems that they require.
100*4a5d661aSToomas Soome  */
101*4a5d661aSToomas Soome struct fs_ops {
102*4a5d661aSToomas Soome     const char	*fs_name;
103*4a5d661aSToomas Soome     int		(*fo_open)(const char *path, struct open_file *f);
104*4a5d661aSToomas Soome     int		(*fo_close)(struct open_file *f);
105*4a5d661aSToomas Soome     int		(*fo_read)(struct open_file *f, void *buf,
106*4a5d661aSToomas Soome 			   size_t size, size_t *resid);
107*4a5d661aSToomas Soome     int		(*fo_write)(struct open_file *f, void *buf,
108*4a5d661aSToomas Soome 			    size_t size, size_t *resid);
109*4a5d661aSToomas Soome     off_t	(*fo_seek)(struct open_file *f, off_t offset, int where);
110*4a5d661aSToomas Soome     int		(*fo_stat)(struct open_file *f, struct stat *sb);
111*4a5d661aSToomas Soome     int		(*fo_readdir)(struct open_file *f, struct dirent *d);
112*4a5d661aSToomas Soome };
113*4a5d661aSToomas Soome 
114*4a5d661aSToomas Soome /*
115*4a5d661aSToomas Soome  * libstand-supplied filesystems
116*4a5d661aSToomas Soome  */
117*4a5d661aSToomas Soome extern struct fs_ops ufs_fsops;
118*4a5d661aSToomas Soome extern struct fs_ops tftp_fsops;
119*4a5d661aSToomas Soome extern struct fs_ops nfs_fsops;
120*4a5d661aSToomas Soome extern struct fs_ops cd9660_fsops;
121*4a5d661aSToomas Soome extern struct fs_ops nandfs_fsops;
122*4a5d661aSToomas Soome extern struct fs_ops gzipfs_fsops;
123*4a5d661aSToomas Soome extern struct fs_ops bzipfs_fsops;
124*4a5d661aSToomas Soome extern struct fs_ops dosfs_fsops;
125*4a5d661aSToomas Soome extern struct fs_ops ext2fs_fsops;
126*4a5d661aSToomas Soome extern struct fs_ops splitfs_fsops;
127*4a5d661aSToomas Soome extern struct fs_ops pkgfs_fsops;
128*4a5d661aSToomas Soome 
129*4a5d661aSToomas Soome /* where values for lseek(2) */
130*4a5d661aSToomas Soome #define	SEEK_SET	0	/* set file offset to offset */
131*4a5d661aSToomas Soome #define	SEEK_CUR	1	/* set file offset to current plus offset */
132*4a5d661aSToomas Soome #define	SEEK_END	2	/* set file offset to EOF plus offset */
133*4a5d661aSToomas Soome 
134*4a5d661aSToomas Soome /*
135*4a5d661aSToomas Soome  * Device switch
136*4a5d661aSToomas Soome  */
137*4a5d661aSToomas Soome struct devsw {
138*4a5d661aSToomas Soome     const char	dv_name[8];
139*4a5d661aSToomas Soome     int		dv_type;		/* opaque type constant, arch-dependant */
140*4a5d661aSToomas Soome     int		(*dv_init)(void);	/* early probe call */
141*4a5d661aSToomas Soome     int		(*dv_strategy)(void *devdata, int rw, daddr_t blk,
142*4a5d661aSToomas Soome 			size_t offset, size_t size, char *buf, size_t *rsize);
143*4a5d661aSToomas Soome     int		(*dv_open)(struct open_file *f, ...);
144*4a5d661aSToomas Soome     int		(*dv_close)(struct open_file *f);
145*4a5d661aSToomas Soome     int		(*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
146*4a5d661aSToomas Soome     int		(*dv_print)(int verbose);	/* print device information */
147*4a5d661aSToomas Soome     void	(*dv_cleanup)(void);
148*4a5d661aSToomas Soome };
149*4a5d661aSToomas Soome 
150*4a5d661aSToomas Soome /*
151*4a5d661aSToomas Soome  * libstand-supplied device switch
152*4a5d661aSToomas Soome  */
153*4a5d661aSToomas Soome extern struct devsw netdev;
154*4a5d661aSToomas Soome 
155*4a5d661aSToomas Soome extern int errno;
156*4a5d661aSToomas Soome 
157*4a5d661aSToomas Soome /*
158*4a5d661aSToomas Soome  * Generic device specifier; architecture-dependent
159*4a5d661aSToomas Soome  * versions may be larger, but should be allowed to
160*4a5d661aSToomas Soome  * overlap.
161*4a5d661aSToomas Soome  */
162*4a5d661aSToomas Soome struct devdesc
163*4a5d661aSToomas Soome {
164*4a5d661aSToomas Soome     struct devsw	*d_dev;
165*4a5d661aSToomas Soome     int			d_type;
166*4a5d661aSToomas Soome #define	DEVT_NONE	0
167*4a5d661aSToomas Soome #define	DEVT_DISK	1
168*4a5d661aSToomas Soome #define	DEVT_NET	2
169*4a5d661aSToomas Soome #define	DEVT_CD		3
170*4a5d661aSToomas Soome #define	DEVT_ZFS	4
171*4a5d661aSToomas Soome     int			d_unit;
172*4a5d661aSToomas Soome     void		*d_opendata;
173*4a5d661aSToomas Soome };
174*4a5d661aSToomas Soome 
175*4a5d661aSToomas Soome struct open_file {
176*4a5d661aSToomas Soome     int			f_flags;	/* see F_* below */
177*4a5d661aSToomas Soome     struct devsw	*f_dev;		/* pointer to device operations */
178*4a5d661aSToomas Soome     void		*f_devdata;	/* device specific data */
179*4a5d661aSToomas Soome     struct fs_ops	*f_ops;		/* pointer to file system operations */
180*4a5d661aSToomas Soome     void		*f_fsdata;	/* file system specific data */
181*4a5d661aSToomas Soome     off_t		f_offset;	/* current file offset */
182*4a5d661aSToomas Soome     char		*f_rabuf;	/* readahead buffer pointer */
183*4a5d661aSToomas Soome     size_t		f_ralen;	/* valid data in readahead buffer */
184*4a5d661aSToomas Soome     off_t		f_raoffset;	/* consumer offset in readahead buffer */
185*4a5d661aSToomas Soome #define SOPEN_RASIZE	512
186*4a5d661aSToomas Soome };
187*4a5d661aSToomas Soome 
188*4a5d661aSToomas Soome #define	SOPEN_MAX	64
189*4a5d661aSToomas Soome extern struct open_file files[];
190*4a5d661aSToomas Soome 
191*4a5d661aSToomas Soome /* f_flags values */
192*4a5d661aSToomas Soome #define	F_READ		0x0001	/* file opened for reading */
193*4a5d661aSToomas Soome #define	F_WRITE		0x0002	/* file opened for writing */
194*4a5d661aSToomas Soome #define	F_RAW		0x0004	/* raw device open - no file system */
195*4a5d661aSToomas Soome #define	F_NODEV		0x0008	/* network open - no device */
196*4a5d661aSToomas Soome #define	F_GZIP		0x0010  /* file is compressed by gzip */
197*4a5d661aSToomas Soome #define	F_BZIP		0x0020	/* file is compressed by bzip */
198*4a5d661aSToomas Soome 
199*4a5d661aSToomas Soome #define isascii(c)	(((c) & ~0x7F) == 0)
200*4a5d661aSToomas Soome 
201*4a5d661aSToomas Soome static __inline int isupper(int c)
202*4a5d661aSToomas Soome {
203*4a5d661aSToomas Soome     return c >= 'A' && c <= 'Z';
204*4a5d661aSToomas Soome }
205*4a5d661aSToomas Soome 
206*4a5d661aSToomas Soome static __inline int islower(int c)
207*4a5d661aSToomas Soome {
208*4a5d661aSToomas Soome     return c >= 'a' && c <= 'z';
209*4a5d661aSToomas Soome }
210*4a5d661aSToomas Soome 
211*4a5d661aSToomas Soome static __inline int isspace(int c)
212*4a5d661aSToomas Soome {
213*4a5d661aSToomas Soome     return c == ' ' || (c >= 0x9 && c <= 0xd);
214*4a5d661aSToomas Soome }
215*4a5d661aSToomas Soome 
216*4a5d661aSToomas Soome static __inline int isdigit(int c)
217*4a5d661aSToomas Soome {
218*4a5d661aSToomas Soome     return c >= '0' && c <= '9';
219*4a5d661aSToomas Soome }
220*4a5d661aSToomas Soome 
221*4a5d661aSToomas Soome static __inline int isxdigit(int c)
222*4a5d661aSToomas Soome {
223*4a5d661aSToomas Soome     return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
224*4a5d661aSToomas Soome }
225*4a5d661aSToomas Soome 
226*4a5d661aSToomas Soome static __inline int isalpha(int c)
227*4a5d661aSToomas Soome {
228*4a5d661aSToomas Soome     return isupper(c) || islower(c);
229*4a5d661aSToomas Soome }
230*4a5d661aSToomas Soome 
231*4a5d661aSToomas Soome static __inline int isalnum(int c)
232*4a5d661aSToomas Soome {
233*4a5d661aSToomas Soome     return isalpha(c) || isdigit(c);
234*4a5d661aSToomas Soome }
235*4a5d661aSToomas Soome 
236*4a5d661aSToomas Soome static __inline int toupper(int c)
237*4a5d661aSToomas Soome {
238*4a5d661aSToomas Soome     return islower(c) ? c - 'a' + 'A' : c;
239*4a5d661aSToomas Soome }
240*4a5d661aSToomas Soome 
241*4a5d661aSToomas Soome static __inline int tolower(int c)
242*4a5d661aSToomas Soome {
243*4a5d661aSToomas Soome     return isupper(c) ? c - 'A' + 'a' : c;
244*4a5d661aSToomas Soome }
245*4a5d661aSToomas Soome 
246*4a5d661aSToomas Soome /* sbrk emulation */
247*4a5d661aSToomas Soome extern void	setheap(void *base, void *top);
248*4a5d661aSToomas Soome extern char	*sbrk(int incr);
249*4a5d661aSToomas Soome 
250*4a5d661aSToomas Soome /* Matt Dillon's zalloc/zmalloc */
251*4a5d661aSToomas Soome extern void	*malloc(size_t bytes);
252*4a5d661aSToomas Soome extern void	free(void *ptr);
253*4a5d661aSToomas Soome /*#define free(p)	{CHK("free %p", p); free(p);} */ /* use for catching guard violations */
254*4a5d661aSToomas Soome extern void	*calloc(size_t n1, size_t n2);
255*4a5d661aSToomas Soome extern void	*realloc(void *ptr, size_t size);
256*4a5d661aSToomas Soome extern void	*reallocf(void *ptr, size_t size);
257*4a5d661aSToomas Soome extern void	mallocstats(void);
258*4a5d661aSToomas Soome 
259*4a5d661aSToomas Soome extern int	printf(const char *fmt, ...) __printflike(1, 2);
260*4a5d661aSToomas Soome extern void	vprintf(const char *fmt, __va_list);
261*4a5d661aSToomas Soome extern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
262*4a5d661aSToomas Soome extern int	snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
263*4a5d661aSToomas Soome extern void	vsprintf(char *buf, const char *cfmt, __va_list);
264*4a5d661aSToomas Soome extern void	vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
265*4a5d661aSToomas Soome 
266*4a5d661aSToomas Soome extern void	twiddle(u_int callerdiv);
267*4a5d661aSToomas Soome extern void	twiddle_divisor(u_int globaldiv);
268*4a5d661aSToomas Soome 
269*4a5d661aSToomas Soome extern void	ngets(char *, int);
270*4a5d661aSToomas Soome #define gets(x)	ngets((x), 0)
271*4a5d661aSToomas Soome extern int	fgetstr(char *buf, int size, int fd);
272*4a5d661aSToomas Soome 
273*4a5d661aSToomas Soome extern int	open(const char *, int);
274*4a5d661aSToomas Soome #define	O_RDONLY	0x0
275*4a5d661aSToomas Soome #define O_WRONLY	0x1
276*4a5d661aSToomas Soome #define O_RDWR		0x2
277*4a5d661aSToomas Soome extern int	close(int);
278*4a5d661aSToomas Soome extern void	closeall(void);
279*4a5d661aSToomas Soome extern ssize_t	read(int, void *, size_t);
280*4a5d661aSToomas Soome extern ssize_t	write(int, void *, size_t);
281*4a5d661aSToomas Soome extern struct	dirent *readdirfd(int);
282*4a5d661aSToomas Soome 
283*4a5d661aSToomas Soome extern void	srandom(u_long seed);
284*4a5d661aSToomas Soome extern u_long	random(void);
285*4a5d661aSToomas Soome 
286*4a5d661aSToomas Soome /* imports from stdlib, locally modified */
287*4a5d661aSToomas Soome extern long	strtol(const char *, char **, int);
288*4a5d661aSToomas Soome extern unsigned long	strtoul(const char *, char **, int);
289*4a5d661aSToomas Soome extern char	*optarg;			/* getopt(3) external variables */
290*4a5d661aSToomas Soome extern int	optind, opterr, optopt, optreset;
291*4a5d661aSToomas Soome extern int	getopt(int, char * const [], const char *);
292*4a5d661aSToomas Soome 
293*4a5d661aSToomas Soome /* pager.c */
294*4a5d661aSToomas Soome extern void	pager_open(void);
295*4a5d661aSToomas Soome extern void	pager_close(void);
296*4a5d661aSToomas Soome extern int	pager_output(const char *lines);
297*4a5d661aSToomas Soome extern int	pager_file(const char *fname);
298*4a5d661aSToomas Soome 
299*4a5d661aSToomas Soome /* No signal state to preserve */
300*4a5d661aSToomas Soome #define setjmp	_setjmp
301*4a5d661aSToomas Soome #define longjmp	_longjmp
302*4a5d661aSToomas Soome 
303*4a5d661aSToomas Soome /* environment.c */
304*4a5d661aSToomas Soome #define EV_DYNAMIC	(1<<0)		/* value was dynamically allocated, free if changed/unset */
305*4a5d661aSToomas Soome #define EV_VOLATILE	(1<<1)		/* value is volatile, make a copy of it */
306*4a5d661aSToomas Soome #define EV_NOHOOK	(1<<2)		/* don't call hook when setting */
307*4a5d661aSToomas Soome 
308*4a5d661aSToomas Soome struct env_var;
309*4a5d661aSToomas Soome typedef char	*(ev_format_t)(struct env_var *ev);
310*4a5d661aSToomas Soome typedef int	(ev_sethook_t)(struct env_var *ev, int flags,
311*4a5d661aSToomas Soome 		    const void *value);
312*4a5d661aSToomas Soome typedef int	(ev_unsethook_t)(struct env_var *ev);
313*4a5d661aSToomas Soome 
314*4a5d661aSToomas Soome struct env_var
315*4a5d661aSToomas Soome {
316*4a5d661aSToomas Soome     char		*ev_name;
317*4a5d661aSToomas Soome     int			ev_flags;
318*4a5d661aSToomas Soome     void		*ev_value;
319*4a5d661aSToomas Soome     ev_sethook_t	*ev_sethook;
320*4a5d661aSToomas Soome     ev_unsethook_t	*ev_unsethook;
321*4a5d661aSToomas Soome     struct env_var	*ev_next, *ev_prev;
322*4a5d661aSToomas Soome };
323*4a5d661aSToomas Soome extern struct env_var	*environ;
324*4a5d661aSToomas Soome 
325*4a5d661aSToomas Soome extern struct env_var	*env_getenv(const char *name);
326*4a5d661aSToomas Soome extern int		env_setenv(const char *name, int flags,
327*4a5d661aSToomas Soome 				   const void *value, ev_sethook_t sethook,
328*4a5d661aSToomas Soome 				   ev_unsethook_t unsethook);
329*4a5d661aSToomas Soome extern char		*getenv(const char *name);
330*4a5d661aSToomas Soome extern int		setenv(const char *name, const char *value,
331*4a5d661aSToomas Soome 			       int overwrite);
332*4a5d661aSToomas Soome extern int		putenv(const char *string);
333*4a5d661aSToomas Soome extern int		unsetenv(const char *name);
334*4a5d661aSToomas Soome 
335*4a5d661aSToomas Soome extern ev_sethook_t	env_noset;		/* refuse set operation */
336*4a5d661aSToomas Soome extern ev_unsethook_t	env_nounset;		/* refuse unset operation */
337*4a5d661aSToomas Soome 
338*4a5d661aSToomas Soome /* BCD conversions (undocumented) */
339*4a5d661aSToomas Soome extern u_char const	bcd2bin_data[];
340*4a5d661aSToomas Soome extern u_char const	bin2bcd_data[];
341*4a5d661aSToomas Soome extern char const	hex2ascii_data[];
342*4a5d661aSToomas Soome 
343*4a5d661aSToomas Soome #define	bcd2bin(bcd)	(bcd2bin_data[bcd])
344*4a5d661aSToomas Soome #define	bin2bcd(bin)	(bin2bcd_data[bin])
345*4a5d661aSToomas Soome #define	hex2ascii(hex)	(hex2ascii_data[hex])
346*4a5d661aSToomas Soome 
347*4a5d661aSToomas Soome /* min/max (undocumented) */
348*4a5d661aSToomas Soome static __inline int imax(int a, int b) { return (a > b ? a : b); }
349*4a5d661aSToomas Soome static __inline int imin(int a, int b) { return (a < b ? a : b); }
350*4a5d661aSToomas Soome static __inline long lmax(long a, long b) { return (a > b ? a : b); }
351*4a5d661aSToomas Soome static __inline long lmin(long a, long b) { return (a < b ? a : b); }
352*4a5d661aSToomas Soome static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
353*4a5d661aSToomas Soome static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
354*4a5d661aSToomas Soome static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
355*4a5d661aSToomas Soome static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
356*4a5d661aSToomas Soome static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
357*4a5d661aSToomas Soome static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
358*4a5d661aSToomas Soome 
359*4a5d661aSToomas Soome /* swaps (undocumented, useful?) */
360*4a5d661aSToomas Soome #ifdef __i386__
361*4a5d661aSToomas Soome extern u_int32_t	bswap32(u_int32_t x);
362*4a5d661aSToomas Soome extern u_int64_t	bswap64(u_int64_t x);
363*4a5d661aSToomas Soome #endif
364*4a5d661aSToomas Soome 
365*4a5d661aSToomas Soome /* null functions for device/filesystem switches (undocumented) */
366*4a5d661aSToomas Soome extern int	nodev(void);
367*4a5d661aSToomas Soome extern int	noioctl(struct open_file *, u_long, void *);
368*4a5d661aSToomas Soome extern void	nullsys(void);
369*4a5d661aSToomas Soome 
370*4a5d661aSToomas Soome extern int	null_open(const char *path, struct open_file *f);
371*4a5d661aSToomas Soome extern int	null_close(struct open_file *f);
372*4a5d661aSToomas Soome extern int	null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
373*4a5d661aSToomas Soome extern int	null_write(struct open_file *f, void *buf, size_t size, size_t *resid);
374*4a5d661aSToomas Soome extern off_t	null_seek(struct open_file *f, off_t offset, int where);
375*4a5d661aSToomas Soome extern int	null_stat(struct open_file *f, struct stat *sb);
376*4a5d661aSToomas Soome extern int	null_readdir(struct open_file *f, struct dirent *d);
377*4a5d661aSToomas Soome 
378*4a5d661aSToomas Soome 
379*4a5d661aSToomas Soome /*
380*4a5d661aSToomas Soome  * Machine dependent functions and data, must be provided or stubbed by
381*4a5d661aSToomas Soome  * the consumer
382*4a5d661aSToomas Soome  */
383*4a5d661aSToomas Soome extern int		getchar(void);
384*4a5d661aSToomas Soome extern int		ischar(void);
385*4a5d661aSToomas Soome extern void		putchar(int);
386*4a5d661aSToomas Soome extern int		devopen(struct open_file *, const char *, const char **);
387*4a5d661aSToomas Soome extern int		devclose(struct open_file *f);
388*4a5d661aSToomas Soome extern void		panic(const char *, ...) __dead2 __printflike(1, 2);
389*4a5d661aSToomas Soome extern struct fs_ops	*file_system[];
390*4a5d661aSToomas Soome extern struct fs_ops	*exclusive_file_system;
391*4a5d661aSToomas Soome extern struct devsw	*devsw[];
392*4a5d661aSToomas Soome 
393*4a5d661aSToomas Soome /*
394*4a5d661aSToomas Soome  * Expose byteorder(3) functions.
395*4a5d661aSToomas Soome  */
396*4a5d661aSToomas Soome #ifndef _BYTEORDER_PROTOTYPED
397*4a5d661aSToomas Soome #define	_BYTEORDER_PROTOTYPED
398*4a5d661aSToomas Soome extern uint32_t		htonl(uint32_t);
399*4a5d661aSToomas Soome extern uint16_t		htons(uint16_t);
400*4a5d661aSToomas Soome extern uint32_t		ntohl(uint32_t);
401*4a5d661aSToomas Soome extern uint16_t		ntohs(uint16_t);
402*4a5d661aSToomas Soome #endif
403*4a5d661aSToomas Soome 
404*4a5d661aSToomas Soome #ifndef _BYTEORDER_FUNC_DEFINED
405*4a5d661aSToomas Soome #define	_BYTEORDER_FUNC_DEFINED
406*4a5d661aSToomas Soome #define	htonl(x)	__htonl(x)
407*4a5d661aSToomas Soome #define	htons(x)	__htons(x)
408*4a5d661aSToomas Soome #define	ntohl(x)	__ntohl(x)
409*4a5d661aSToomas Soome #define	ntohs(x)	__ntohs(x)
410*4a5d661aSToomas Soome #endif
411*4a5d661aSToomas Soome 
412*4a5d661aSToomas Soome void *Malloc(size_t, const char *, int);
413*4a5d661aSToomas Soome void *Calloc(size_t, size_t, const char *, int);
414*4a5d661aSToomas Soome void *Realloc(void *, size_t, const char *, int);
415*4a5d661aSToomas Soome void Free(void *, const char *, int);
416*4a5d661aSToomas Soome 
417*4a5d661aSToomas Soome #if 1
418*4a5d661aSToomas Soome #define malloc(x)	Malloc(x, __FILE__, __LINE__)
419*4a5d661aSToomas Soome #define calloc(x, y)	Calloc(x, y, __FILE__, __LINE__)
420*4a5d661aSToomas Soome #define free(x)		Free(x, __FILE__, __LINE__)
421*4a5d661aSToomas Soome #define realloc(x, y)	Realloc(x, y, __FILE__, __LINE__)
422*4a5d661aSToomas Soome #else
423*4a5d661aSToomas Soome #define malloc(x)	Malloc(x, NULL, 0)
424*4a5d661aSToomas Soome #define calloc(x, y)	Calloc(x, y, NULL, 0)
425*4a5d661aSToomas Soome #define free(x)		Free(x, NULL, 0)
426*4a5d661aSToomas Soome #define realloc(x, y)	Realloc(x, y, NULL, 0)
427*4a5d661aSToomas Soome #endif
428*4a5d661aSToomas Soome 
429*4a5d661aSToomas Soome #endif	/* STAND_H */
430