xref: /freebsd/stand/libsa/stand.h (revision 97cbd5e722389a575e820c4e03f38053308f08ea)
1ca987d46SWarner Losh /*
2ca987d46SWarner Losh  * Copyright (c) 1998 Michael Smith.
3ca987d46SWarner Losh  * All rights reserved.
4ca987d46SWarner Losh  *
5ca987d46SWarner Losh  * Redistribution and use in source and binary forms, with or without
6ca987d46SWarner Losh  * modification, are permitted provided that the following conditions
7ca987d46SWarner Losh  * are met:
8ca987d46SWarner Losh  * 1. Redistributions of source code must retain the above copyright
9ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer.
10ca987d46SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
11ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
12ca987d46SWarner Losh  *    documentation and/or other materials provided with the distribution.
13ca987d46SWarner Losh  *
14ca987d46SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15ca987d46SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16ca987d46SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17ca987d46SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18ca987d46SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19ca987d46SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20ca987d46SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21ca987d46SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22ca987d46SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23ca987d46SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24ca987d46SWarner Losh  * SUCH DAMAGE.
25ca987d46SWarner Losh  *
26ca987d46SWarner Losh  * $FreeBSD$
27ca987d46SWarner Losh  * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
28ca987d46SWarner Losh  */
29ca987d46SWarner Losh 
30ca987d46SWarner Losh /*-
31ca987d46SWarner Losh  * Copyright (c) 1993
32ca987d46SWarner Losh  *	The Regents of the University of California.  All rights reserved.
33ca987d46SWarner Losh  *
34ca987d46SWarner Losh  * Redistribution and use in source and binary forms, with or without
35ca987d46SWarner Losh  * modification, are permitted provided that the following conditions
36ca987d46SWarner Losh  * are met:
37ca987d46SWarner Losh  * 1. Redistributions of source code must retain the above copyright
38ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer.
39ca987d46SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
40ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
41ca987d46SWarner Losh  *    documentation and/or other materials provided with the distribution.
42ca987d46SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
43ca987d46SWarner Losh  *    may be used to endorse or promote products derived from this software
44ca987d46SWarner Losh  *    without specific prior written permission.
45ca987d46SWarner Losh  *
46ca987d46SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47ca987d46SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48ca987d46SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49ca987d46SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50ca987d46SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51ca987d46SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52ca987d46SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53ca987d46SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54ca987d46SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55ca987d46SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56ca987d46SWarner Losh  * SUCH DAMAGE.
57ca987d46SWarner Losh  *
58ca987d46SWarner Losh  *	@(#)stand.h	8.1 (Berkeley) 6/11/93
59ca987d46SWarner Losh  */
60ca987d46SWarner Losh 
61ca987d46SWarner Losh #ifndef	STAND_H
62ca987d46SWarner Losh #define	STAND_H
63ca987d46SWarner Losh 
64ca987d46SWarner Losh #include <sys/types.h>
65ca987d46SWarner Losh #include <sys/cdefs.h>
66ca987d46SWarner Losh #include <sys/stat.h>
67ca987d46SWarner Losh #include <sys/dirent.h>
68*97cbd5e7SToomas Soome #include <sys/queue.h>
69ca987d46SWarner Losh 
70ca987d46SWarner Losh /* this header intentionally exports NULL from <string.h> */
71ca987d46SWarner Losh #include <string.h>
72c7b46ba4SWarner Losh #define strcoll(a, b)	strcmp((a), (b))
73ca987d46SWarner Losh 
74ca987d46SWarner Losh #define CHK(fmt, args...)	printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
75ca987d46SWarner Losh #define PCHK(fmt, args...)	{printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
76ca987d46SWarner Losh 
77ca987d46SWarner Losh #include <sys/errno.h>
78ca987d46SWarner Losh 
79ca987d46SWarner Losh /* special stand error codes */
80ca987d46SWarner Losh #define	EADAPT	(ELAST+1)	/* bad adaptor */
81ca987d46SWarner Losh #define	ECTLR	(ELAST+2)	/* bad controller */
82ca987d46SWarner Losh #define	EUNIT	(ELAST+3)	/* bad unit */
83ca987d46SWarner Losh #define ESLICE	(ELAST+4)	/* bad slice */
84ca987d46SWarner Losh #define	EPART	(ELAST+5)	/* bad partition */
85ca987d46SWarner Losh #define	ERDLAB	(ELAST+6)	/* can't read disk label */
86ca987d46SWarner Losh #define	EUNLAB	(ELAST+7)	/* unlabeled disk */
87ca987d46SWarner Losh #define	EOFFSET	(ELAST+8)	/* relative seek not supported */
88ca987d46SWarner Losh #define	ESALAST	(ELAST+8)	/* */
89ca987d46SWarner Losh 
9049cb0130SWarner Losh /* Partial signal emulation for sig_atomic_t */
9149cb0130SWarner Losh #include <machine/signal.h>
9249cb0130SWarner Losh 
93ca987d46SWarner Losh struct open_file;
94ca987d46SWarner Losh 
95ca987d46SWarner Losh /*
96ca987d46SWarner Losh  * This structure is used to define file system operations in a file system
97ca987d46SWarner Losh  * independent way.
98ca987d46SWarner Losh  *
99ca987d46SWarner Losh  * XXX note that filesystem providers should export a pointer to their fs_ops
100ca987d46SWarner Losh  *     struct, so that consumers can reference this and thus include the
101ca987d46SWarner Losh  *     filesystems that they require.
102ca987d46SWarner Losh  */
103ca987d46SWarner Losh struct fs_ops {
104ca987d46SWarner Losh     const char	*fs_name;
105ca987d46SWarner Losh     int		(*fo_open)(const char *path, struct open_file *f);
106ca987d46SWarner Losh     int		(*fo_close)(struct open_file *f);
107ca987d46SWarner Losh     int		(*fo_read)(struct open_file *f, void *buf,
108ca987d46SWarner Losh 			   size_t size, size_t *resid);
1092e7e6fbcSConrad Meyer     int		(*fo_write)(struct open_file *f, const void *buf,
110ca987d46SWarner Losh 			    size_t size, size_t *resid);
111ca987d46SWarner Losh     off_t	(*fo_seek)(struct open_file *f, off_t offset, int where);
112ca987d46SWarner Losh     int		(*fo_stat)(struct open_file *f, struct stat *sb);
113ca987d46SWarner Losh     int		(*fo_readdir)(struct open_file *f, struct dirent *d);
114ca987d46SWarner Losh };
115ca987d46SWarner Losh 
116ca987d46SWarner Losh /*
117ca987d46SWarner Losh  * libstand-supplied filesystems
118ca987d46SWarner Losh  */
119ca987d46SWarner Losh extern struct fs_ops ufs_fsops;
120ca987d46SWarner Losh extern struct fs_ops tftp_fsops;
121ca987d46SWarner Losh extern struct fs_ops nfs_fsops;
122ca987d46SWarner Losh extern struct fs_ops cd9660_fsops;
123ca987d46SWarner Losh extern struct fs_ops gzipfs_fsops;
124ca987d46SWarner Losh extern struct fs_ops bzipfs_fsops;
125ca987d46SWarner Losh extern struct fs_ops dosfs_fsops;
126ca987d46SWarner Losh extern struct fs_ops ext2fs_fsops;
127ca987d46SWarner Losh extern struct fs_ops splitfs_fsops;
128ca987d46SWarner Losh extern struct fs_ops pkgfs_fsops;
129da4961c7SRebecca Cran extern struct fs_ops efihttp_fsops;
130ca987d46SWarner Losh 
131ca987d46SWarner Losh /* where values for lseek(2) */
132ca987d46SWarner Losh #define	SEEK_SET	0	/* set file offset to offset */
133ca987d46SWarner Losh #define	SEEK_CUR	1	/* set file offset to current plus offset */
134ca987d46SWarner Losh #define	SEEK_END	2	/* set file offset to EOF plus offset */
135ca987d46SWarner Losh 
136ca987d46SWarner Losh /*
137ca987d46SWarner Losh  * Device switch
138ca987d46SWarner Losh  */
139ca987d46SWarner Losh struct devsw {
140ca987d46SWarner Losh     const char	dv_name[8];
141ca987d46SWarner Losh     int		dv_type;		/* opaque type constant, arch-dependant */
142b3a2aad1SWarner Losh #define DEVT_NONE	0
143b3a2aad1SWarner Losh #define DEVT_DISK	1
144b3a2aad1SWarner Losh #define DEVT_NET	2
145b3a2aad1SWarner Losh #define DEVT_CD		3
146b3a2aad1SWarner Losh #define DEVT_ZFS	4
147b3a2aad1SWarner Losh #define DEVT_FD		5
148ca987d46SWarner Losh     int		(*dv_init)(void);	/* early probe call */
149ca987d46SWarner Losh     int		(*dv_strategy)(void *devdata, int rw, daddr_t blk,
150ca987d46SWarner Losh 			size_t size, char *buf, size_t *rsize);
151ca987d46SWarner Losh     int		(*dv_open)(struct open_file *f, ...);
152ca987d46SWarner Losh     int		(*dv_close)(struct open_file *f);
153ca987d46SWarner Losh     int		(*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
154ca987d46SWarner Losh     int		(*dv_print)(int verbose);	/* print device information */
155ca987d46SWarner Losh     void	(*dv_cleanup)(void);
156ca987d46SWarner Losh };
157ca987d46SWarner Losh 
158ca987d46SWarner Losh /*
159ca987d46SWarner Losh  * libstand-supplied device switch
160ca987d46SWarner Losh  */
161ca987d46SWarner Losh extern struct devsw netdev;
162ca987d46SWarner Losh 
163ca987d46SWarner Losh extern int errno;
164ca987d46SWarner Losh 
165ca987d46SWarner Losh /*
166ca987d46SWarner Losh  * Generic device specifier; architecture-dependent
167ca987d46SWarner Losh  * versions may be larger, but should be allowed to
168ca987d46SWarner Losh  * overlap.
169ca987d46SWarner Losh  */
170b3a2aad1SWarner Losh struct devdesc {
171ca987d46SWarner Losh     struct devsw	*d_dev;
172ca987d46SWarner Losh     int			d_unit;
173ca987d46SWarner Losh     void		*d_opendata;
174ca987d46SWarner Losh };
175ca987d46SWarner Losh 
176ca987d46SWarner Losh struct open_file {
177ca987d46SWarner Losh     int			f_flags;	/* see F_* below */
178ca987d46SWarner Losh     struct devsw	*f_dev;		/* pointer to device operations */
179ca987d46SWarner Losh     void		*f_devdata;	/* device specific data */
180ca987d46SWarner Losh     struct fs_ops	*f_ops;		/* pointer to file system operations */
181ca987d46SWarner Losh     void		*f_fsdata;	/* file system specific data */
182ca987d46SWarner Losh     off_t		f_offset;	/* current file offset */
183ca987d46SWarner Losh     char		*f_rabuf;	/* readahead buffer pointer */
184ca987d46SWarner Losh     size_t		f_ralen;	/* valid data in readahead buffer */
185ca987d46SWarner Losh     off_t		f_raoffset;	/* consumer offset in readahead buffer */
186*97cbd5e7SToomas Soome     int			f_id;		/* file number */
187*97cbd5e7SToomas Soome     TAILQ_ENTRY(open_file) f_link;	/* next entry */
188ca987d46SWarner Losh #define SOPEN_RASIZE	512
189ca987d46SWarner Losh };
190ca987d46SWarner Losh 
191*97cbd5e7SToomas Soome typedef TAILQ_HEAD(file_list, open_file) file_list_t;
192*97cbd5e7SToomas Soome extern file_list_t files;
193*97cbd5e7SToomas Soome extern struct open_file *fd2open_file(int);
194ca987d46SWarner Losh 
195ca987d46SWarner Losh /* f_flags values */
196ca987d46SWarner Losh #define	F_READ		0x0001	/* file opened for reading */
197ca987d46SWarner Losh #define	F_WRITE		0x0002	/* file opened for writing */
198ca987d46SWarner Losh #define	F_RAW		0x0004	/* raw device open - no file system */
199ca987d46SWarner Losh #define F_NODEV		0x0008	/* network open - no device */
200ca987d46SWarner Losh #define	F_MASK		0xFFFF
201ca987d46SWarner Losh /* Mode modifier for strategy() */
202ca987d46SWarner Losh #define	F_NORA		(0x01 << 16)	/* Disable Read-Ahead */
203ca987d46SWarner Losh 
204ca987d46SWarner Losh #define isascii(c)	(((c) & ~0x7F) == 0)
205ca987d46SWarner Losh 
206ca987d46SWarner Losh static __inline int isupper(int c)
207ca987d46SWarner Losh {
208ca987d46SWarner Losh     return c >= 'A' && c <= 'Z';
209ca987d46SWarner Losh }
210ca987d46SWarner Losh 
211ca987d46SWarner Losh static __inline int islower(int c)
212ca987d46SWarner Losh {
213ca987d46SWarner Losh     return c >= 'a' && c <= 'z';
214ca987d46SWarner Losh }
215ca987d46SWarner Losh 
216ca987d46SWarner Losh static __inline int isspace(int c)
217ca987d46SWarner Losh {
218ca987d46SWarner Losh     return c == ' ' || (c >= 0x9 && c <= 0xd);
219ca987d46SWarner Losh }
220ca987d46SWarner Losh 
221ca987d46SWarner Losh static __inline int isdigit(int c)
222ca987d46SWarner Losh {
223ca987d46SWarner Losh     return c >= '0' && c <= '9';
224ca987d46SWarner Losh }
225ca987d46SWarner Losh 
226ca987d46SWarner Losh static __inline int isxdigit(int c)
227ca987d46SWarner Losh {
228ca987d46SWarner Losh     return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
229ca987d46SWarner Losh }
230ca987d46SWarner Losh 
231ca987d46SWarner Losh static __inline int isalpha(int c)
232ca987d46SWarner Losh {
233ca987d46SWarner Losh     return isupper(c) || islower(c);
234ca987d46SWarner Losh }
235ca987d46SWarner Losh 
236ca987d46SWarner Losh static __inline int isalnum(int c)
237ca987d46SWarner Losh {
238ca987d46SWarner Losh     return isalpha(c) || isdigit(c);
239ca987d46SWarner Losh }
240ca987d46SWarner Losh 
2416856cf68SWarner Losh static __inline int iscntrl(int c)
2426856cf68SWarner Losh {
2436856cf68SWarner Losh 	return (c >= 0 && c < ' ') || c == 127;
2446856cf68SWarner Losh }
2456856cf68SWarner Losh 
2466856cf68SWarner Losh static __inline int isgraph(int c)
2476856cf68SWarner Losh {
2486856cf68SWarner Losh 	return c >= '!' && c <= '~';
2496856cf68SWarner Losh }
2506856cf68SWarner Losh 
2516856cf68SWarner Losh static __inline int ispunct(int c)
2526856cf68SWarner Losh {
2536856cf68SWarner Losh 	return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
2546856cf68SWarner Losh 	    (c >= '[' && c <= '`') || (c >= '{' && c <= '~');
2556856cf68SWarner Losh }
2566856cf68SWarner Losh 
257ca987d46SWarner Losh static __inline int toupper(int c)
258ca987d46SWarner Losh {
259ca987d46SWarner Losh     return islower(c) ? c - 'a' + 'A' : c;
260ca987d46SWarner Losh }
261ca987d46SWarner Losh 
262ca987d46SWarner Losh static __inline int tolower(int c)
263ca987d46SWarner Losh {
264ca987d46SWarner Losh     return isupper(c) ? c - 'A' + 'a' : c;
265ca987d46SWarner Losh }
266ca987d46SWarner Losh 
267ca987d46SWarner Losh /* sbrk emulation */
268ca987d46SWarner Losh extern void	setheap(void *base, void *top);
269ca987d46SWarner Losh extern char	*sbrk(int incr);
270ca987d46SWarner Losh 
271ca987d46SWarner Losh extern int	printf(const char *fmt, ...) __printflike(1, 2);
2725e84b578SToomas Soome extern int	asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
273ca987d46SWarner Losh extern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
274ca987d46SWarner Losh extern int	snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
2753e9c7874SIan Lepore extern int	vprintf(const char *fmt, __va_list);
2763e9c7874SIan Lepore extern int	vsprintf(char *buf, const char *cfmt, __va_list);
2773e9c7874SIan Lepore extern int	vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
278ca987d46SWarner Losh 
279ca987d46SWarner Losh extern void	twiddle(u_int callerdiv);
280ca987d46SWarner Losh extern void	twiddle_divisor(u_int globaldiv);
281ca987d46SWarner Losh 
282ca987d46SWarner Losh extern void	ngets(char *, int);
283ca987d46SWarner Losh #define gets(x)	ngets((x), 0)
284ca987d46SWarner Losh extern int	fgetstr(char *buf, int size, int fd);
285ca987d46SWarner Losh 
286ca987d46SWarner Losh extern int	open(const char *, int);
287ca987d46SWarner Losh #define	O_RDONLY	0x0
288ca987d46SWarner Losh #define O_WRONLY	0x1
289ca987d46SWarner Losh #define O_RDWR		0x2
2902ef9ff7dSSimon J. Gerraty #define O_ACCMODE	0x3
29182c85a42SKyle Evans /* NOT IMPLEMENTED */
29282c85a42SKyle Evans #define	O_CREAT		0x0200		/* create if nonexistent */
29382c85a42SKyle Evans #define	O_TRUNC		0x0400		/* truncate to zero length */
294ca987d46SWarner Losh extern int	close(int);
295ca987d46SWarner Losh extern void	closeall(void);
296ca987d46SWarner Losh extern ssize_t	read(int, void *, size_t);
297061577c5SConrad Meyer extern ssize_t	write(int, const void *, size_t);
298ca987d46SWarner Losh extern struct	dirent *readdirfd(int);
299ca987d46SWarner Losh 
300dcaa2d76SWarner Losh extern void	srandom(unsigned int);
301e294a126SWarner Losh extern long	random(void);
302ca987d46SWarner Losh 
303ca987d46SWarner Losh /* imports from stdlib, locally modified */
304ca987d46SWarner Losh extern char	*optarg;			/* getopt(3) external variables */
305ca987d46SWarner Losh extern int	optind, opterr, optopt, optreset;
306ca987d46SWarner Losh extern int	getopt(int, char * const [], const char *);
307ca987d46SWarner Losh 
308ca987d46SWarner Losh /* pager.c */
309ca987d46SWarner Losh extern void	pager_open(void);
310ca987d46SWarner Losh extern void	pager_close(void);
311ca987d46SWarner Losh extern int	pager_output(const char *lines);
312ca987d46SWarner Losh extern int	pager_file(const char *fname);
313ca987d46SWarner Losh 
314ca987d46SWarner Losh /* No signal state to preserve */
315ca987d46SWarner Losh #define setjmp	_setjmp
316ca987d46SWarner Losh #define longjmp	_longjmp
317ca987d46SWarner Losh 
318ca987d46SWarner Losh /* environment.c */
319ca987d46SWarner Losh #define EV_DYNAMIC	(1<<0)		/* value was dynamically allocated, free if changed/unset */
320ca987d46SWarner Losh #define EV_VOLATILE	(1<<1)		/* value is volatile, make a copy of it */
321ca987d46SWarner Losh #define EV_NOHOOK	(1<<2)		/* don't call hook when setting */
322ca987d46SWarner Losh 
323ca987d46SWarner Losh struct env_var;
324ca987d46SWarner Losh typedef char	*(ev_format_t)(struct env_var *ev);
325ca987d46SWarner Losh typedef int	(ev_sethook_t)(struct env_var *ev, int flags,
326ca987d46SWarner Losh 		    const void *value);
327ca987d46SWarner Losh typedef int	(ev_unsethook_t)(struct env_var *ev);
328ca987d46SWarner Losh 
329ca987d46SWarner Losh struct env_var
330ca987d46SWarner Losh {
331ca987d46SWarner Losh     char		*ev_name;
332ca987d46SWarner Losh     int			ev_flags;
333ca987d46SWarner Losh     void		*ev_value;
334ca987d46SWarner Losh     ev_sethook_t	*ev_sethook;
335ca987d46SWarner Losh     ev_unsethook_t	*ev_unsethook;
336ca987d46SWarner Losh     struct env_var	*ev_next, *ev_prev;
337ca987d46SWarner Losh };
338ca987d46SWarner Losh extern struct env_var	*environ;
339ca987d46SWarner Losh 
340ca987d46SWarner Losh extern struct env_var	*env_getenv(const char *name);
341ca987d46SWarner Losh extern int		env_setenv(const char *name, int flags,
342ca987d46SWarner Losh 				   const void *value, ev_sethook_t sethook,
343ca987d46SWarner Losh 				   ev_unsethook_t unsethook);
344588f0a1eSToomas Soome extern void		env_discard(struct env_var *);
345ca987d46SWarner Losh extern char		*getenv(const char *name);
346ca987d46SWarner Losh extern int		setenv(const char *name, const char *value,
347ca987d46SWarner Losh 			       int overwrite);
348e8e6a5f9SWarner Losh extern int		putenv(char *string);
349ca987d46SWarner Losh extern int		unsetenv(const char *name);
350ca987d46SWarner Losh 
351ca987d46SWarner Losh extern ev_sethook_t	env_noset;		/* refuse set operation */
352ca987d46SWarner Losh extern ev_unsethook_t	env_nounset;		/* refuse unset operation */
353ca987d46SWarner Losh 
3542b0268cfSWarner Losh /* stdlib.h routines */
35524dfa658SWarner Losh extern int		abs(int a);
35630883627SWarner Losh extern void		abort(void) __dead2;
3573a8a081bSWarner Losh extern long		strtol(const char * __restrict, char ** __restrict, int);
3583a8a081bSWarner Losh extern long long	strtoll(const char * __restrict, char ** __restrict, int);
3593a8a081bSWarner Losh extern unsigned long	strtoul(const char * __restrict, char ** __restrict, int);
3603a8a081bSWarner Losh extern unsigned long long strtoull(const char * __restrict, char ** __restrict, int);
3612b0268cfSWarner Losh 
362ca987d46SWarner Losh /* BCD conversions (undocumented) */
363ca987d46SWarner Losh extern u_char const	bcd2bin_data[];
364ca987d46SWarner Losh extern u_char const	bin2bcd_data[];
365ca987d46SWarner Losh extern char const	hex2ascii_data[];
366ca987d46SWarner Losh 
367ca987d46SWarner Losh #define	bcd2bin(bcd)	(bcd2bin_data[bcd])
368ca987d46SWarner Losh #define	bin2bcd(bin)	(bin2bcd_data[bin])
369ca987d46SWarner Losh #define	hex2ascii(hex)	(hex2ascii_data[hex])
370b6f4732cSIan Lepore #define	validbcd(bcd)	(bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0))
371ca987d46SWarner Losh 
372ca987d46SWarner Losh /* min/max (undocumented) */
373ca987d46SWarner Losh static __inline int imax(int a, int b) { return (a > b ? a : b); }
374ca987d46SWarner Losh static __inline int imin(int a, int b) { return (a < b ? a : b); }
375ca987d46SWarner Losh static __inline long lmax(long a, long b) { return (a > b ? a : b); }
376ca987d46SWarner Losh static __inline long lmin(long a, long b) { return (a < b ? a : b); }
377ca987d46SWarner Losh static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
378ca987d46SWarner Losh static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
379ca987d46SWarner Losh static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
380ca987d46SWarner Losh static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
381ca987d46SWarner Losh static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
382ca987d46SWarner Losh static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
383ca987d46SWarner Losh 
384ca987d46SWarner Losh /* null functions for device/filesystem switches (undocumented) */
385ca987d46SWarner Losh extern int	nodev(void);
386ca987d46SWarner Losh extern int	noioctl(struct open_file *, u_long, void *);
387ca987d46SWarner Losh extern void	nullsys(void);
388ca987d46SWarner Losh 
389ca987d46SWarner Losh extern int	null_open(const char *path, struct open_file *f);
390ca987d46SWarner Losh extern int	null_close(struct open_file *f);
391ca987d46SWarner Losh extern int	null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
3922e7e6fbcSConrad Meyer extern int	null_write(struct open_file *f, const void *buf, size_t size, size_t *resid);
393ca987d46SWarner Losh extern off_t	null_seek(struct open_file *f, off_t offset, int where);
394ca987d46SWarner Losh extern int	null_stat(struct open_file *f, struct stat *sb);
395ca987d46SWarner Losh extern int	null_readdir(struct open_file *f, struct dirent *d);
396ca987d46SWarner Losh 
397ca987d46SWarner Losh 
398ca987d46SWarner Losh /*
399ca987d46SWarner Losh  * Machine dependent functions and data, must be provided or stubbed by
400ca987d46SWarner Losh  * the consumer
401ca987d46SWarner Losh  */
40286bb84d5SWarner Losh extern void		exit(int) __dead2;
403ca987d46SWarner Losh extern int		getchar(void);
404ca987d46SWarner Losh extern int		ischar(void);
405ca987d46SWarner Losh extern void		putchar(int);
406ca987d46SWarner Losh extern int		devopen(struct open_file *, const char *, const char **);
407ca987d46SWarner Losh extern int		devclose(struct open_file *f);
408ca987d46SWarner Losh extern void		panic(const char *, ...) __dead2 __printflike(1, 2);
40986bb84d5SWarner Losh extern void		panic_action(void) __weak_symbol __dead2;
41031d05586SWarner Losh extern time_t		getsecs(void);
411ca987d46SWarner Losh extern struct fs_ops	*file_system[];
412ca987d46SWarner Losh extern struct fs_ops	*exclusive_file_system;
413ca987d46SWarner Losh extern struct devsw	*devsw[];
414ca987d46SWarner Losh 
415ca987d46SWarner Losh /*
416b9c5b432SWarner Losh  * Time routines
417b9c5b432SWarner Losh  */
418b9c5b432SWarner Losh time_t time(time_t *);
419b9c5b432SWarner Losh 
420b9c5b432SWarner Losh /*
421ca987d46SWarner Losh  * Expose byteorder(3) functions.
422ca987d46SWarner Losh  */
423ca987d46SWarner Losh #ifndef _BYTEORDER_PROTOTYPED
424ca987d46SWarner Losh #define	_BYTEORDER_PROTOTYPED
425ca987d46SWarner Losh extern uint32_t		htonl(uint32_t);
426ca987d46SWarner Losh extern uint16_t		htons(uint16_t);
427ca987d46SWarner Losh extern uint32_t		ntohl(uint32_t);
428ca987d46SWarner Losh extern uint16_t		ntohs(uint16_t);
429ca987d46SWarner Losh #endif
430ca987d46SWarner Losh 
431ca987d46SWarner Losh #ifndef _BYTEORDER_FUNC_DEFINED
432ca987d46SWarner Losh #define	_BYTEORDER_FUNC_DEFINED
433ca987d46SWarner Losh #define	htonl(x)	__htonl(x)
434ca987d46SWarner Losh #define	htons(x)	__htons(x)
435ca987d46SWarner Losh #define	ntohl(x)	__ntohl(x)
436ca987d46SWarner Losh #define	ntohs(x)	__ntohs(x)
437ca987d46SWarner Losh #endif
438ca987d46SWarner Losh 
439ca987d46SWarner Losh void *Malloc(size_t, const char *, int);
44011db1a16SToomas Soome void *Memalign(size_t, size_t, const char *, int);
441ca987d46SWarner Losh void *Calloc(size_t, size_t, const char *, int);
442ca987d46SWarner Losh void *Realloc(void *, size_t, const char *, int);
44311db1a16SToomas Soome void *Reallocf(void *, size_t, const char *, int);
444ca987d46SWarner Losh void Free(void *, const char *, int);
44562ea4c11SToomas Soome extern void	mallocstats(void);
446ca987d46SWarner Losh 
447e9b148a3SSimon J. Gerraty const char *x86_hypervisor(void);
448e9b148a3SSimon J. Gerraty 
449c907ec9eSToomas Soome #ifdef USER_MALLOC
450c907ec9eSToomas Soome extern void *malloc(size_t);
451c907ec9eSToomas Soome extern void *memalign(size_t, size_t);
452c907ec9eSToomas Soome extern void *calloc(size_t, size_t);
453c907ec9eSToomas Soome extern void free(void *);
454c907ec9eSToomas Soome extern void *realloc(void *, size_t);
455c907ec9eSToomas Soome extern void *reallocf(void *, size_t);
4565292d0a7SToomas Soome #elif defined(DEBUG_MALLOC)
457ca987d46SWarner Losh #define malloc(x)	Malloc(x, __FILE__, __LINE__)
45811db1a16SToomas Soome #define memalign(x, y)	Memalign(x, y, __FILE__, __LINE__)
459ca987d46SWarner Losh #define calloc(x, y)	Calloc(x, y, __FILE__, __LINE__)
460ca987d46SWarner Losh #define free(x)		Free(x, __FILE__, __LINE__)
461ca987d46SWarner Losh #define realloc(x, y)	Realloc(x, y, __FILE__, __LINE__)
46262ea4c11SToomas Soome #define reallocf(x, y)	Reallocf(x, y, __FILE__, __LINE__)
463ca987d46SWarner Losh #else
464ca987d46SWarner Losh #define malloc(x)	Malloc(x, NULL, 0)
46511db1a16SToomas Soome #define memalign(x, y)	Memalign(x, y, NULL, 0)
466ca987d46SWarner Losh #define calloc(x, y)	Calloc(x, y, NULL, 0)
467ca987d46SWarner Losh #define free(x)		Free(x, NULL, 0)
468ca987d46SWarner Losh #define realloc(x, y)	Realloc(x, y, NULL, 0)
46962ea4c11SToomas Soome #define reallocf(x, y)	Reallocf(x, y, NULL, 0)
470ca987d46SWarner Losh #endif
471ca987d46SWarner Losh 
472ed2a6576SWarner Losh /*
473ed2a6576SWarner Losh  * va <-> pa routines. MD code must supply.
474ed2a6576SWarner Losh  */
475ed2a6576SWarner Losh caddr_t ptov(uintptr_t);
476ed2a6576SWarner Losh 
477ed19b7c5SSimon J. Gerraty /* hexdump.c */
478ed19b7c5SSimon J. Gerraty void	hexdump(caddr_t region, size_t len);
479ed19b7c5SSimon J. Gerraty 
480e193d3baSColin Percival /* tslog.c */
481e193d3baSColin Percival #define TSRAW(a, b, c) tslog(a, b, c)
482e193d3baSColin Percival #define TSENTER() TSRAW("ENTER", __func__, NULL)
483e193d3baSColin Percival #define TSEXIT() TSRAW("EXIT", __func__, NULL)
484e193d3baSColin Percival #define TSLINE() TSRAW("EVENT", __FILE__, __XSTRING(__LINE__))
485e193d3baSColin Percival void tslog(const char *, const char *, const char *);
486e193d3baSColin Percival void tslog_setbuf(void * buf, size_t len);
487e193d3baSColin Percival void tslog_getbuf(void ** buf, size_t * len);
488e193d3baSColin Percival 
489ca987d46SWarner Losh #endif	/* STAND_H */
490