xref: /illumos-gate/usr/src/boot/lib/libstand/stand.h (revision 28de4f3c)
1199767f8SToomas Soome /*
2199767f8SToomas Soome  * Copyright (c) 1998 Michael Smith.
3199767f8SToomas Soome  * All rights reserved.
4199767f8SToomas Soome  *
5199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
6199767f8SToomas Soome  * modification, are permitted provided that the following conditions
7199767f8SToomas Soome  * are met:
8199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
13199767f8SToomas Soome  *
14199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24199767f8SToomas Soome  * SUCH DAMAGE.
25199767f8SToomas Soome  *
26199767f8SToomas Soome  * $FreeBSD$
27c142ce19SToomas Soome  * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
28199767f8SToomas Soome  */
29199767f8SToomas Soome 
30cf837ed8SToomas Soome /*
31199767f8SToomas Soome  * Copyright (c) 1993
32199767f8SToomas Soome  *	The Regents of the University of California.  All rights reserved.
33199767f8SToomas Soome  *
34199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
35199767f8SToomas Soome  * modification, are permitted provided that the following conditions
36199767f8SToomas Soome  * are met:
37199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
38199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
39199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
40199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
41199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
42199767f8SToomas Soome  * 4. Neither the name of the University nor the names of its contributors
43199767f8SToomas Soome  *    may be used to endorse or promote products derived from this software
44199767f8SToomas Soome  *    without specific prior written permission.
45199767f8SToomas Soome  *
46199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56199767f8SToomas Soome  * SUCH DAMAGE.
57199767f8SToomas Soome  *
58199767f8SToomas Soome  *	@(#)stand.h	8.1 (Berkeley) 6/11/93
59199767f8SToomas Soome  */
60199767f8SToomas Soome 
61199767f8SToomas Soome #ifndef	STAND_H
62199767f8SToomas Soome #define	STAND_H
63199767f8SToomas Soome 
64199767f8SToomas Soome #include <sys/types.h>
65199767f8SToomas Soome #include <sys/cdefs.h>
66199767f8SToomas Soome #include <sys/stat.h>
67199767f8SToomas Soome #include <sys/dirent.h>
68199767f8SToomas Soome 
69199767f8SToomas Soome /* this header intentionally exports NULL from <string.h> */
70199767f8SToomas Soome #include <string.h>
71199767f8SToomas Soome 
72573f5931SToomas Soome #define	CHK(fmt, args...)	\
73573f5931SToomas Soome 	printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args)
74573f5931SToomas Soome #define	PCHK(fmt, args...)	{\
75573f5931SToomas Soome 	printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args); getchar();\
76573f5931SToomas Soome }
77199767f8SToomas Soome 
78199767f8SToomas Soome /* Avoid unwanted userlandish components */
79573f5931SToomas Soome #define	_KERNEL
80199767f8SToomas Soome #include <sys/errno.h>
81199767f8SToomas Soome #undef _KERNEL
82199767f8SToomas Soome 
83199767f8SToomas Soome /* special stand error codes */
84199767f8SToomas Soome #define	EADAPT	(ELAST+1)	/* bad adaptor */
85199767f8SToomas Soome #define	ECTLR	(ELAST+2)	/* bad controller */
86199767f8SToomas Soome #define	EUNIT	(ELAST+3)	/* bad unit */
87573f5931SToomas Soome #define	ESLICE	(ELAST+4)	/* bad slice */
88199767f8SToomas Soome #define	EPART	(ELAST+5)	/* bad partition */
89199767f8SToomas Soome #define	ERDLAB	(ELAST+6)	/* can't read disk label */
90199767f8SToomas Soome #define	EUNLAB	(ELAST+7)	/* unlabeled disk */
91199767f8SToomas Soome #define	EOFFSET	(ELAST+8)	/* relative seek not supported */
92199767f8SToomas Soome #define	ESALAST	(ELAST+8)	/* */
93199767f8SToomas Soome 
94199767f8SToomas Soome struct open_file;
95199767f8SToomas Soome 
96199767f8SToomas Soome /*
97199767f8SToomas Soome  * This structure is used to define file system operations in a file system
98199767f8SToomas Soome  * independent way.
99199767f8SToomas Soome  *
100199767f8SToomas Soome  * XXX note that filesystem providers should export a pointer to their fs_ops
101199767f8SToomas Soome  *     struct, so that consumers can reference this and thus include the
102199767f8SToomas Soome  *     filesystems that they require.
103199767f8SToomas Soome  */
104199767f8SToomas Soome struct fs_ops {
105573f5931SToomas Soome 	const char *fs_name;
106573f5931SToomas Soome 	int (*fo_open)(const char *path, struct open_file *f);
107573f5931SToomas Soome 	int (*fo_close)(struct open_file *f);
108573f5931SToomas Soome 	int (*fo_read)(struct open_file *f, void *buf,
109573f5931SToomas Soome 	    size_t size, size_t *resid);
110573f5931SToomas Soome 	int (*fo_write)(struct open_file *f, const void *buf,
111573f5931SToomas Soome 	    size_t size, size_t *resid);
112573f5931SToomas Soome 	off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
113573f5931SToomas Soome 	int (*fo_stat)(struct open_file *f, struct stat *sb);
114573f5931SToomas Soome 	int (*fo_readdir)(struct open_file *f, struct dirent *d);
115199767f8SToomas Soome };
116199767f8SToomas Soome 
117199767f8SToomas Soome /*
118199767f8SToomas Soome  * libstand-supplied filesystems
119199767f8SToomas Soome  */
120199767f8SToomas Soome extern struct fs_ops ufs_fsops;
121199767f8SToomas Soome extern struct fs_ops tftp_fsops;
122199767f8SToomas Soome extern struct fs_ops nfs_fsops;
123199767f8SToomas Soome extern struct fs_ops cd9660_fsops;
124199767f8SToomas Soome extern struct fs_ops gzipfs_fsops;
125199767f8SToomas Soome extern struct fs_ops bzipfs_fsops;
126199767f8SToomas Soome extern struct fs_ops dosfs_fsops;
127199767f8SToomas Soome extern struct fs_ops ext2fs_fsops;
128199767f8SToomas Soome extern struct fs_ops splitfs_fsops;
129199767f8SToomas Soome extern struct fs_ops pkgfs_fsops;
130199767f8SToomas Soome 
131199767f8SToomas Soome /* where values for lseek(2) */
132199767f8SToomas Soome #define	SEEK_SET	0	/* set file offset to offset */
133199767f8SToomas Soome #define	SEEK_CUR	1	/* set file offset to current plus offset */
134199767f8SToomas Soome #define	SEEK_END	2	/* set file offset to EOF plus offset */
135199767f8SToomas Soome 
136c142ce19SToomas Soome /*
137199767f8SToomas Soome  * Device switch
138199767f8SToomas Soome  */
139199767f8SToomas Soome struct devsw {
140573f5931SToomas Soome 	const char dv_name[8];
141573f5931SToomas Soome 	int dv_type;		/* opaque type constant, arch-dependant */
1420a06a804SToomas Soome #define	DEVT_NONE	0
1430a06a804SToomas Soome #define	DEVT_DISK	1
1440a06a804SToomas Soome #define	DEVT_NET	2
1450a06a804SToomas Soome #define	DEVT_CD		3
1460a06a804SToomas Soome #define	DEVT_ZFS	4
1470a06a804SToomas Soome #define	DEVT_FD		5
148573f5931SToomas Soome 	int (*dv_init)(void);	/* early probe call */
149573f5931SToomas Soome 	int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
15038dea910SToomas Soome 			size_t size, char *buf, size_t *rsize);
151573f5931SToomas Soome 	int (*dv_open)(struct open_file *f, ...);
152573f5931SToomas Soome 	int (*dv_close)(struct open_file *f);
153573f5931SToomas Soome 	int (*dv_ioctl)(struct open_file *f, ulong_t cmd, void *data);
154573f5931SToomas Soome 	int (*dv_print)(int verbose);	/* print device information */
155573f5931SToomas Soome 	void (*dv_cleanup)(void);
156199767f8SToomas Soome };
157199767f8SToomas Soome 
158199767f8SToomas Soome /*
159199767f8SToomas Soome  * libstand-supplied device switch
160199767f8SToomas Soome  */
161199767f8SToomas Soome extern struct devsw netdev;
162199767f8SToomas Soome 
163199767f8SToomas Soome extern int errno;
164199767f8SToomas Soome 
165199767f8SToomas Soome /*
166199767f8SToomas Soome  * Generic device specifier; architecture-dependent
167199767f8SToomas Soome  * versions may be larger, but should be allowed to
168199767f8SToomas Soome  * overlap.
169199767f8SToomas Soome  */
1700a06a804SToomas Soome struct devdesc {
171573f5931SToomas Soome 	struct devsw	*d_dev;
172573f5931SToomas Soome 	int		d_unit;
173573f5931SToomas Soome 	void		*d_opendata;
174199767f8SToomas Soome };
175199767f8SToomas Soome 
176199767f8SToomas Soome struct open_file {
177573f5931SToomas Soome 	int		f_flags;	/* see F_* below */
178573f5931SToomas Soome 	struct devsw	*f_dev;		/* pointer to device operations */
179573f5931SToomas Soome 	void		*f_devdata;	/* device specific data */
180573f5931SToomas Soome 	struct fs_ops	*f_ops;		/* pointer to file system operations */
181573f5931SToomas Soome 	void		*f_fsdata;	/* file system specific data */
182573f5931SToomas Soome 	off_t		f_offset;	/* current file offset */
183573f5931SToomas Soome 	char		*f_rabuf;	/* readahead buffer pointer */
184573f5931SToomas Soome 	size_t		f_ralen;	/* valid data in readahead buffer */
185573f5931SToomas Soome 	off_t		f_raoffset; /* consumer offset in readahead buffer */
186573f5931SToomas Soome #define	SOPEN_RASIZE	512
187199767f8SToomas Soome };
188199767f8SToomas Soome 
189199767f8SToomas Soome #define	SOPEN_MAX	64
190199767f8SToomas Soome extern struct open_file files[];
191199767f8SToomas Soome 
192199767f8SToomas Soome /* f_flags values */
193199767f8SToomas Soome #define	F_READ		0x0001	/* file opened for reading */
194199767f8SToomas Soome #define	F_WRITE		0x0002	/* file opened for writing */
195199767f8SToomas Soome #define	F_RAW		0x0004	/* raw device open - no file system */
196199767f8SToomas Soome #define	F_NODEV		0x0008	/* network open - no device */
197199767f8SToomas Soome #define	F_GZIP		0x0010  /* file is compressed by gzip */
198199767f8SToomas Soome #define	F_BZIP		0x0020	/* file is compressed by bzip */
1993dab2501SToomas Soome #define	F_MASK		0xFFFF
2003dab2501SToomas Soome /* Mode modifier for strategy() */
2013dab2501SToomas Soome #define	F_NORA		(0x01 << 16)	/* Disable Read-Ahead */
202199767f8SToomas Soome 
203573f5931SToomas Soome #define	isascii(c)	(((c) & ~0x7F) == 0)
204199767f8SToomas Soome 
isupper(int c)205199767f8SToomas Soome static __inline int isupper(int c)
206199767f8SToomas Soome {
207573f5931SToomas Soome 	return (c >= 'A' && c <= 'Z');
208199767f8SToomas Soome }
209199767f8SToomas Soome 
islower(int c)210199767f8SToomas Soome static __inline int islower(int c)
211199767f8SToomas Soome {
212573f5931SToomas Soome 	return (c >= 'a' && c <= 'z');
213199767f8SToomas Soome }
214199767f8SToomas Soome 
isspace(int c)215199767f8SToomas Soome static __inline int isspace(int c)
216199767f8SToomas Soome {
217573f5931SToomas Soome 	return (c == ' ' || (c >= 0x9 && c <= 0xd));
218199767f8SToomas Soome }
219199767f8SToomas Soome 
isdigit(int c)220199767f8SToomas Soome static __inline int isdigit(int c)
221199767f8SToomas Soome {
222573f5931SToomas Soome 	return (c >= '0' && c <= '9');
223199767f8SToomas Soome }
224199767f8SToomas Soome 
isxdigit(int c)225199767f8SToomas Soome static __inline int isxdigit(int c)
226199767f8SToomas Soome {
227573f5931SToomas Soome 	return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
228199767f8SToomas Soome }
229199767f8SToomas Soome 
isalpha(int c)230199767f8SToomas Soome static __inline int isalpha(int c)
231199767f8SToomas Soome {
232573f5931SToomas Soome 	return (isupper(c) || islower(c));
233199767f8SToomas Soome }
234199767f8SToomas Soome 
isalnum(int c)235199767f8SToomas Soome static __inline int isalnum(int c)
236199767f8SToomas Soome {
237573f5931SToomas Soome 	return (isalpha(c) || isdigit(c));
238199767f8SToomas Soome }
239199767f8SToomas Soome 
iscntrl(int c)240be9c3adbSToomas Soome static __inline int iscntrl(int c)
241be9c3adbSToomas Soome {
242be9c3adbSToomas Soome 	return ((c >= 0 && c < ' ') || c == 127);
243be9c3adbSToomas Soome }
244be9c3adbSToomas Soome 
isgraph(int c)245be9c3adbSToomas Soome static __inline int isgraph(int c)
246be9c3adbSToomas Soome {
247be9c3adbSToomas Soome 	return (c >= '!' && c <= '~');
248be9c3adbSToomas Soome }
249be9c3adbSToomas Soome 
ispunct(int c)250be9c3adbSToomas Soome static __inline int ispunct(int c)
251be9c3adbSToomas Soome {
252be9c3adbSToomas Soome 	return ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
253be9c3adbSToomas Soome 	    (c >= '[' && c <= '`') || (c >= '{' && c <= '~'));
254be9c3adbSToomas Soome }
255be9c3adbSToomas Soome 
toupper(int c)256199767f8SToomas Soome static __inline int toupper(int c)
257199767f8SToomas Soome {
258573f5931SToomas Soome 	return (islower(c) ? c - 'a' + 'A' : c);
259199767f8SToomas Soome }
260199767f8SToomas Soome 
tolower(int c)261199767f8SToomas Soome static __inline int tolower(int c)
262199767f8SToomas Soome {
263573f5931SToomas Soome 	return (isupper(c) ? c - 'A' + 'a' : c);
264199767f8SToomas Soome }
265199767f8SToomas Soome 
266199767f8SToomas Soome /* sbrk emulation */
267199767f8SToomas Soome extern void	setheap(void *base, void *top);
268199767f8SToomas Soome extern char	*sbrk(int incr);
269199767f8SToomas Soome 
270199767f8SToomas Soome extern void	mallocstats(void);
271199767f8SToomas Soome 
272199767f8SToomas Soome extern int	printf(const char *fmt, ...) __printflike(1, 2);
273199767f8SToomas Soome extern void	vprintf(const char *fmt, __va_list);
2746ea3a31bSToomas Soome extern int	asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
275199767f8SToomas Soome extern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
276573f5931SToomas Soome extern int	snprintf(char *buf, size_t size, const char *cfmt, ...) \
277573f5931SToomas Soome 		__printflike(3, 4);
278199767f8SToomas Soome extern void	vsprintf(char *buf, const char *cfmt, __va_list);
279199767f8SToomas Soome extern void	vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
280199767f8SToomas Soome 
281573f5931SToomas Soome extern void	twiddle(uint_t callerdiv);
282573f5931SToomas Soome extern void	twiddle_divisor(uint_t globaldiv);
283199767f8SToomas Soome 
284199767f8SToomas Soome extern void	ngets(char *, int);
285573f5931SToomas Soome #define	gets(x)	ngets((x), 0)
286199767f8SToomas Soome extern int	fgetstr(char *buf, int size, int fd);
287199767f8SToomas Soome 
288199767f8SToomas Soome extern int	open(const char *, int);
289199767f8SToomas Soome #define	O_RDONLY	0x0
290573f5931SToomas Soome #define	O_WRONLY	0x1
291573f5931SToomas Soome #define	O_RDWR		0x2
292199767f8SToomas Soome extern int	close(int);
293199767f8SToomas Soome extern void	closeall(void);
294199767f8SToomas Soome extern ssize_t	read(int, void *, size_t);
295cf837ed8SToomas Soome extern ssize_t	write(int, const void *, size_t);
296199767f8SToomas Soome extern struct	dirent *readdirfd(int);
297199767f8SToomas Soome 
298573f5931SToomas Soome extern void	srandom(ulong_t seed);
299573f5931SToomas Soome extern ulong_t	random(void);
300c142ce19SToomas Soome 
301573f5931SToomas Soome extern char	*optarg;		/* getopt(3) external variables */
302199767f8SToomas Soome extern int	optind, opterr, optopt, optreset;
303199767f8SToomas Soome extern int	getopt(int, char * const [], const char *);
304199767f8SToomas Soome 
305199767f8SToomas Soome /* pager.c */
306199767f8SToomas Soome extern void	pager_open(void);
307199767f8SToomas Soome extern void	pager_close(void);
308199767f8SToomas Soome extern int	pager_output(const char *lines);
309199767f8SToomas Soome extern int	pager_file(const char *fname);
310199767f8SToomas Soome 
311199767f8SToomas Soome /* No signal state to preserve */
312573f5931SToomas Soome #define	setjmp	_setjmp
313573f5931SToomas Soome #define	longjmp	_longjmp
314199767f8SToomas Soome 
315199767f8SToomas Soome /* environment.c */
316573f5931SToomas Soome /* value was dynamically allocated, free if changed/unset */
317573f5931SToomas Soome #define	EV_DYNAMIC	(1<<0)
318573f5931SToomas Soome /* value is volatile, make a copy of it */
319573f5931SToomas Soome #define	EV_VOLATILE	(1<<1)
320573f5931SToomas Soome /* don't call hook when setting */
321573f5931SToomas Soome #define	EV_NOHOOK	(1<<2)
322199767f8SToomas Soome 
323199767f8SToomas Soome struct env_var;
324199767f8SToomas Soome typedef char	*(ev_format_t)(struct env_var *ev);
325199767f8SToomas Soome typedef int	(ev_sethook_t)(struct env_var *ev, int flags,
326199767f8SToomas Soome 		    const void *value);
327199767f8SToomas Soome typedef int	(ev_unsethook_t)(struct env_var *ev);
328199767f8SToomas Soome 
329199767f8SToomas Soome struct env_var
330199767f8SToomas Soome {
331199767f8SToomas Soome     char		*ev_name;
332199767f8SToomas Soome     int			ev_flags;
333199767f8SToomas Soome     void		*ev_value;
334199767f8SToomas Soome     ev_sethook_t	*ev_sethook;
335199767f8SToomas Soome     ev_unsethook_t	*ev_unsethook;
336199767f8SToomas Soome     struct env_var	*ev_next, *ev_prev;
337199767f8SToomas Soome };
338199767f8SToomas Soome extern struct env_var	*environ;
339199767f8SToomas Soome 
340199767f8SToomas Soome extern struct env_var	*env_getenv(const char *name);
341199767f8SToomas Soome extern int		env_setenv(const char *name, int flags,
342573f5931SToomas Soome 				const void *value, ev_sethook_t sethook,
343573f5931SToomas Soome 				ev_unsethook_t unsethook);
3445fae793bSToomas Soome extern void		env_discard(struct env_var *);
345199767f8SToomas Soome extern char		*getenv(const char *name);
346199767f8SToomas Soome extern int		setenv(const char *name, const char *value,
347573f5931SToomas Soome 				int overwrite);
348199767f8SToomas Soome extern int		putenv(const char *string);
349199767f8SToomas Soome extern int		unsetenv(const char *name);
350199767f8SToomas Soome 
351199767f8SToomas Soome extern ev_sethook_t	env_noset;		/* refuse set operation */
352199767f8SToomas Soome extern ev_unsethook_t	env_nounset;		/* refuse unset operation */
353199767f8SToomas Soome 
354*28de4f3cSToomas Soome /* stdlib.h routines */
355*28de4f3cSToomas Soome extern long strtol(const char *__restrict, char **__restrict, int);
356*28de4f3cSToomas Soome extern long long strtoll(const char *__restrict, char **__restrict, int);
357*28de4f3cSToomas Soome extern unsigned long strtoul(const char *__restrict, char **__restrict, int);
358*28de4f3cSToomas Soome extern unsigned long long strtoull(const char *__restrict, char **__restrict,
359*28de4f3cSToomas Soome     int);
360*28de4f3cSToomas Soome 
361199767f8SToomas Soome /* BCD conversions (undocumented) */
362573f5931SToomas Soome extern uchar_t const	bcd2bin_data[];
363573f5931SToomas Soome extern uchar_t const	bin2bcd_data[];
364199767f8SToomas Soome extern char const	hex2ascii_data[];
365199767f8SToomas Soome 
366199767f8SToomas Soome #define	bcd2bin(bcd)	(bcd2bin_data[bcd])
367199767f8SToomas Soome #define	bin2bcd(bin)	(bin2bcd_data[bin])
368199767f8SToomas Soome #define	hex2ascii(hex)	(hex2ascii_data[hex])
369199767f8SToomas Soome 
370199767f8SToomas Soome /* min/max (undocumented) */
imax(int a,int b)371199767f8SToomas Soome static __inline int imax(int a, int b) { return (a > b ? a : b); }
imin(int a,int b)372199767f8SToomas Soome static __inline int imin(int a, int b) { return (a < b ? a : b); }
lmax(long a,long b)373199767f8SToomas Soome static __inline long lmax(long a, long b) { return (a > b ? a : b); }
lmin(long a,long b)374199767f8SToomas Soome static __inline long lmin(long a, long b) { return (a < b ? a : b); }
max(uint_t a,uint_t b)375573f5931SToomas Soome static __inline uint_t max(uint_t a, uint_t b) { return (a > b ? a : b); }
min(uint_t a,uint_t b)376573f5931SToomas Soome static __inline uint_t min(uint_t a, uint_t b) { return (a < b ? a : b); }
qmax(quad_t a,quad_t b)377199767f8SToomas Soome static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
qmin(quad_t a,quad_t b)378199767f8SToomas Soome static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
ulmax(ulong_t a,ulong_t b)379573f5931SToomas Soome static __inline ulong_t ulmax(ulong_t a, ulong_t b) { return (a > b ? a : b); }
ulmin(ulong_t a,ulong_t b)380573f5931SToomas Soome static __inline ulong_t ulmin(ulong_t a, ulong_t b) { return (a < b ? a : b); }
381199767f8SToomas Soome 
382199767f8SToomas Soome /* null functions for device/filesystem switches (undocumented) */
383199767f8SToomas Soome extern int	nodev(void);
384573f5931SToomas Soome extern int	noioctl(struct open_file *, ulong_t, void *);
385199767f8SToomas Soome extern void	nullsys(void);
386199767f8SToomas Soome 
387573f5931SToomas Soome extern int	null_open(const char *, struct open_file *);
388573f5931SToomas Soome extern int	null_close(struct open_file *);
389573f5931SToomas Soome extern int	null_read(struct open_file *, void *, size_t, size_t *);
390573f5931SToomas Soome extern int	null_write(struct open_file *, const void *, size_t, size_t *);
391573f5931SToomas Soome extern off_t	null_seek(struct open_file *, off_t, int);
392573f5931SToomas Soome extern int	null_stat(struct open_file *, struct stat *);
393573f5931SToomas Soome extern int	null_readdir(struct open_file *, struct dirent *);
394199767f8SToomas Soome 
395199767f8SToomas Soome 
396c142ce19SToomas Soome /*
397c142ce19SToomas Soome  * Machine dependent functions and data, must be provided or stubbed by
398c142ce19SToomas Soome  * the consumer
399199767f8SToomas Soome  */
400573f5931SToomas Soome extern void	exit(int) __dead2;
401573f5931SToomas Soome extern int	getchar(void);
402573f5931SToomas Soome extern int	ischar(void);
403573f5931SToomas Soome extern void	putchar(int);
404573f5931SToomas Soome extern int	devopen(struct open_file *, const char *, const char **);
405573f5931SToomas Soome extern int	devclose(struct open_file *f);
406573f5931SToomas Soome extern void	panic(const char *, ...) __dead2 __printflike(1, 2);
407573f5931SToomas Soome extern void	panic_action(void) __weak_symbol __dead2;
408573f5931SToomas Soome extern time_t	getsecs(void);
409199767f8SToomas Soome extern struct fs_ops	*file_system[];
410199767f8SToomas Soome extern struct fs_ops	*exclusive_file_system;
411199767f8SToomas Soome extern struct devsw	*devsw[];
412199767f8SToomas Soome 
413199767f8SToomas Soome /*
414199767f8SToomas Soome  * Expose byteorder(3) functions.
415199767f8SToomas Soome  */
416199767f8SToomas Soome #ifndef _BYTEORDER_PROTOTYPED
417199767f8SToomas Soome #define	_BYTEORDER_PROTOTYPED
418199767f8SToomas Soome extern uint32_t		htonl(uint32_t);
419199767f8SToomas Soome extern uint16_t		htons(uint16_t);
420199767f8SToomas Soome extern uint32_t		ntohl(uint32_t);
421199767f8SToomas Soome extern uint16_t		ntohs(uint16_t);
422199767f8SToomas Soome #endif
423199767f8SToomas Soome 
424199767f8SToomas Soome #ifndef _BYTEORDER_FUNC_DEFINED
425199767f8SToomas Soome #define	_BYTEORDER_FUNC_DEFINED
426199767f8SToomas Soome #define	htonl(x)	__htonl(x)
427199767f8SToomas Soome #define	htons(x)	__htons(x)
428199767f8SToomas Soome #define	ntohl(x)	__ntohl(x)
429199767f8SToomas Soome #define	ntohs(x)	__ntohs(x)
430199767f8SToomas Soome #endif
431199767f8SToomas Soome 
432199767f8SToomas Soome void *Malloc(size_t, const char *, int);
433081aa5f6SToomas Soome void *Memalign(size_t, size_t, const char *, int);
434199767f8SToomas Soome void *Calloc(size_t, size_t, const char *, int);
435199767f8SToomas Soome void *Realloc(void *, size_t, const char *, int);
436081aa5f6SToomas Soome void *Reallocf(void *, size_t, const char *, int);
437199767f8SToomas Soome void Free(void *, const char *, int);
438199767f8SToomas Soome 
439081aa5f6SToomas Soome #if DEBUG_MALLOC
440573f5931SToomas Soome #define	malloc(x)	Malloc(x, __FILE__, __LINE__)
441081aa5f6SToomas Soome #define	memalign(x, y)	Memalign(x, y, __FILE__, __LINE__)
442573f5931SToomas Soome #define	calloc(x, y)	Calloc(x, y, __FILE__, __LINE__)
443573f5931SToomas Soome #define	free(x)		Free(x, __FILE__, __LINE__)
444573f5931SToomas Soome #define	realloc(x, y)	Realloc(x, y, __FILE__, __LINE__)
445081aa5f6SToomas Soome #define	reallocf(x, y)	Reallocf(x, y, __FILE__, __LINE__)
446199767f8SToomas Soome #else
447573f5931SToomas Soome #define	malloc(x)	Malloc(x, NULL, 0)
448081aa5f6SToomas Soome #define	memalign(x, y)	Memalign(x, y, NULL, 0)
449573f5931SToomas Soome #define	calloc(x, y)	Calloc(x, y, NULL, 0)
450573f5931SToomas Soome #define	free(x)		Free(x, NULL, 0)
451573f5931SToomas Soome #define	realloc(x, y)	Realloc(x, y, NULL, 0)
452081aa5f6SToomas Soome #define	reallocf(x, y)	Reallocf(x, y, NULL, 0)
453199767f8SToomas Soome #endif
454199767f8SToomas Soome 
455199767f8SToomas Soome #endif	/* STAND_H */
456