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>
68*a2027c5dSToomas Soome #include <sys/queue.h>
69199767f8SToomas Soome
70199767f8SToomas Soome /* this header intentionally exports NULL from <string.h> */
71199767f8SToomas Soome #include <string.h>
72199767f8SToomas Soome
73573f5931SToomas Soome #define CHK(fmt, args...) \
74573f5931SToomas Soome printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args)
75573f5931SToomas Soome #define PCHK(fmt, args...) {\
76573f5931SToomas Soome printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args); getchar();\
77573f5931SToomas Soome }
78199767f8SToomas Soome
79199767f8SToomas Soome /* Avoid unwanted userlandish components */
80573f5931SToomas Soome #define _KERNEL
81199767f8SToomas Soome #include <sys/errno.h>
82199767f8SToomas Soome #undef _KERNEL
83199767f8SToomas Soome
84199767f8SToomas Soome /* special stand error codes */
85199767f8SToomas Soome #define EADAPT (ELAST+1) /* bad adaptor */
86199767f8SToomas Soome #define ECTLR (ELAST+2) /* bad controller */
87199767f8SToomas Soome #define EUNIT (ELAST+3) /* bad unit */
88573f5931SToomas Soome #define ESLICE (ELAST+4) /* bad slice */
89199767f8SToomas Soome #define EPART (ELAST+5) /* bad partition */
90199767f8SToomas Soome #define ERDLAB (ELAST+6) /* can't read disk label */
91199767f8SToomas Soome #define EUNLAB (ELAST+7) /* unlabeled disk */
92199767f8SToomas Soome #define EOFFSET (ELAST+8) /* relative seek not supported */
93199767f8SToomas Soome #define ESALAST (ELAST+8) /* */
94199767f8SToomas Soome
95199767f8SToomas Soome struct open_file;
96199767f8SToomas Soome
97199767f8SToomas Soome /*
98199767f8SToomas Soome * This structure is used to define file system operations in a file system
99199767f8SToomas Soome * independent way.
100199767f8SToomas Soome *
101199767f8SToomas Soome * XXX note that filesystem providers should export a pointer to their fs_ops
102199767f8SToomas Soome * struct, so that consumers can reference this and thus include the
103199767f8SToomas Soome * filesystems that they require.
104199767f8SToomas Soome */
105199767f8SToomas Soome struct fs_ops {
106573f5931SToomas Soome const char *fs_name;
107573f5931SToomas Soome int (*fo_open)(const char *path, struct open_file *f);
108573f5931SToomas Soome int (*fo_close)(struct open_file *f);
109573f5931SToomas Soome int (*fo_read)(struct open_file *f, void *buf,
110573f5931SToomas Soome size_t size, size_t *resid);
111573f5931SToomas Soome int (*fo_write)(struct open_file *f, const void *buf,
112573f5931SToomas Soome size_t size, size_t *resid);
113573f5931SToomas Soome off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
114573f5931SToomas Soome int (*fo_stat)(struct open_file *f, struct stat *sb);
115573f5931SToomas Soome int (*fo_readdir)(struct open_file *f, struct dirent *d);
116199767f8SToomas Soome };
117199767f8SToomas Soome
118199767f8SToomas Soome /*
119199767f8SToomas Soome * libstand-supplied filesystems
120199767f8SToomas Soome */
121199767f8SToomas Soome extern struct fs_ops ufs_fsops;
122199767f8SToomas Soome extern struct fs_ops tftp_fsops;
123199767f8SToomas Soome extern struct fs_ops nfs_fsops;
124199767f8SToomas Soome extern struct fs_ops cd9660_fsops;
125199767f8SToomas Soome extern struct fs_ops gzipfs_fsops;
126199767f8SToomas Soome extern struct fs_ops bzipfs_fsops;
127199767f8SToomas Soome extern struct fs_ops dosfs_fsops;
128199767f8SToomas Soome extern struct fs_ops ext2fs_fsops;
129199767f8SToomas Soome extern struct fs_ops splitfs_fsops;
130199767f8SToomas Soome extern struct fs_ops pkgfs_fsops;
131199767f8SToomas Soome
132199767f8SToomas Soome /* where values for lseek(2) */
133199767f8SToomas Soome #define SEEK_SET 0 /* set file offset to offset */
134199767f8SToomas Soome #define SEEK_CUR 1 /* set file offset to current plus offset */
135199767f8SToomas Soome #define SEEK_END 2 /* set file offset to EOF plus offset */
136199767f8SToomas Soome
137c142ce19SToomas Soome /*
138199767f8SToomas Soome * Device switch
139199767f8SToomas Soome */
140199767f8SToomas Soome struct devsw {
141573f5931SToomas Soome const char dv_name[8];
142573f5931SToomas Soome int dv_type; /* opaque type constant, arch-dependant */
1430a06a804SToomas Soome #define DEVT_NONE 0
1440a06a804SToomas Soome #define DEVT_DISK 1
1450a06a804SToomas Soome #define DEVT_NET 2
1460a06a804SToomas Soome #define DEVT_CD 3
1470a06a804SToomas Soome #define DEVT_ZFS 4
1480a06a804SToomas Soome #define DEVT_FD 5
149573f5931SToomas Soome int (*dv_init)(void); /* early probe call */
150573f5931SToomas Soome int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
15138dea910SToomas Soome size_t size, char *buf, size_t *rsize);
152573f5931SToomas Soome int (*dv_open)(struct open_file *f, ...);
153573f5931SToomas Soome int (*dv_close)(struct open_file *f);
154573f5931SToomas Soome int (*dv_ioctl)(struct open_file *f, ulong_t cmd, void *data);
155573f5931SToomas Soome int (*dv_print)(int verbose); /* print device information */
156573f5931SToomas Soome void (*dv_cleanup)(void);
157199767f8SToomas Soome };
158199767f8SToomas Soome
159199767f8SToomas Soome /*
160199767f8SToomas Soome * libstand-supplied device switch
161199767f8SToomas Soome */
162199767f8SToomas Soome extern struct devsw netdev;
163199767f8SToomas Soome
164199767f8SToomas Soome extern int errno;
165199767f8SToomas Soome
166199767f8SToomas Soome /*
167199767f8SToomas Soome * Generic device specifier; architecture-dependent
168199767f8SToomas Soome * versions may be larger, but should be allowed to
169199767f8SToomas Soome * overlap.
170199767f8SToomas Soome */
1710a06a804SToomas Soome struct devdesc {
172573f5931SToomas Soome struct devsw *d_dev;
173573f5931SToomas Soome int d_unit;
174573f5931SToomas Soome void *d_opendata;
175199767f8SToomas Soome };
176199767f8SToomas Soome
177199767f8SToomas Soome struct open_file {
178573f5931SToomas Soome int f_flags; /* see F_* below */
179573f5931SToomas Soome struct devsw *f_dev; /* pointer to device operations */
180573f5931SToomas Soome void *f_devdata; /* device specific data */
181573f5931SToomas Soome struct fs_ops *f_ops; /* pointer to file system operations */
182573f5931SToomas Soome void *f_fsdata; /* file system specific data */
183573f5931SToomas Soome off_t f_offset; /* current file offset */
184573f5931SToomas Soome char *f_rabuf; /* readahead buffer pointer */
185573f5931SToomas Soome size_t f_ralen; /* valid data in readahead buffer */
186573f5931SToomas Soome off_t f_raoffset; /* consumer offset in readahead buffer */
187*a2027c5dSToomas Soome int f_id; /* file number */
188*a2027c5dSToomas Soome TAILQ_ENTRY(open_file) f_link; /* next entry */
189573f5931SToomas Soome #define SOPEN_RASIZE 512
190199767f8SToomas Soome };
191199767f8SToomas Soome
192*a2027c5dSToomas Soome typedef TAILQ_HEAD(file_list, open_file) file_list_t;
193*a2027c5dSToomas Soome extern file_list_t files;
194*a2027c5dSToomas Soome extern struct open_file *fd2open_file(int);
195199767f8SToomas Soome
196199767f8SToomas Soome /* f_flags values */
197199767f8SToomas Soome #define F_READ 0x0001 /* file opened for reading */
198199767f8SToomas Soome #define F_WRITE 0x0002 /* file opened for writing */
199199767f8SToomas Soome #define F_RAW 0x0004 /* raw device open - no file system */
200199767f8SToomas Soome #define F_NODEV 0x0008 /* network open - no device */
201199767f8SToomas Soome #define F_GZIP 0x0010 /* file is compressed by gzip */
202199767f8SToomas Soome #define F_BZIP 0x0020 /* file is compressed by bzip */
2033dab2501SToomas Soome #define F_MASK 0xFFFF
2043dab2501SToomas Soome /* Mode modifier for strategy() */
2053dab2501SToomas Soome #define F_NORA (0x01 << 16) /* Disable Read-Ahead */
206199767f8SToomas Soome
207573f5931SToomas Soome #define isascii(c) (((c) & ~0x7F) == 0)
208199767f8SToomas Soome
isupper(int c)209199767f8SToomas Soome static __inline int isupper(int c)
210199767f8SToomas Soome {
211573f5931SToomas Soome return (c >= 'A' && c <= 'Z');
212199767f8SToomas Soome }
213199767f8SToomas Soome
islower(int c)214199767f8SToomas Soome static __inline int islower(int c)
215199767f8SToomas Soome {
216573f5931SToomas Soome return (c >= 'a' && c <= 'z');
217199767f8SToomas Soome }
218199767f8SToomas Soome
isspace(int c)219199767f8SToomas Soome static __inline int isspace(int c)
220199767f8SToomas Soome {
221573f5931SToomas Soome return (c == ' ' || (c >= 0x9 && c <= 0xd));
222199767f8SToomas Soome }
223199767f8SToomas Soome
isdigit(int c)224199767f8SToomas Soome static __inline int isdigit(int c)
225199767f8SToomas Soome {
226573f5931SToomas Soome return (c >= '0' && c <= '9');
227199767f8SToomas Soome }
228199767f8SToomas Soome
isxdigit(int c)229199767f8SToomas Soome static __inline int isxdigit(int c)
230199767f8SToomas Soome {
231573f5931SToomas Soome return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
232199767f8SToomas Soome }
233199767f8SToomas Soome
isalpha(int c)234199767f8SToomas Soome static __inline int isalpha(int c)
235199767f8SToomas Soome {
236573f5931SToomas Soome return (isupper(c) || islower(c));
237199767f8SToomas Soome }
238199767f8SToomas Soome
isalnum(int c)239199767f8SToomas Soome static __inline int isalnum(int c)
240199767f8SToomas Soome {
241573f5931SToomas Soome return (isalpha(c) || isdigit(c));
242199767f8SToomas Soome }
243199767f8SToomas Soome
iscntrl(int c)244be9c3adbSToomas Soome static __inline int iscntrl(int c)
245be9c3adbSToomas Soome {
246be9c3adbSToomas Soome return ((c >= 0 && c < ' ') || c == 127);
247be9c3adbSToomas Soome }
248be9c3adbSToomas Soome
isgraph(int c)249be9c3adbSToomas Soome static __inline int isgraph(int c)
250be9c3adbSToomas Soome {
251be9c3adbSToomas Soome return (c >= '!' && c <= '~');
252be9c3adbSToomas Soome }
253be9c3adbSToomas Soome
ispunct(int c)254be9c3adbSToomas Soome static __inline int ispunct(int c)
255be9c3adbSToomas Soome {
256be9c3adbSToomas Soome return ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
257be9c3adbSToomas Soome (c >= '[' && c <= '`') || (c >= '{' && c <= '~'));
258be9c3adbSToomas Soome }
259be9c3adbSToomas Soome
toupper(int c)260199767f8SToomas Soome static __inline int toupper(int c)
261199767f8SToomas Soome {
262573f5931SToomas Soome return (islower(c) ? c - 'a' + 'A' : c);
263199767f8SToomas Soome }
264199767f8SToomas Soome
tolower(int c)265199767f8SToomas Soome static __inline int tolower(int c)
266199767f8SToomas Soome {
267573f5931SToomas Soome return (isupper(c) ? c - 'A' + 'a' : c);
268199767f8SToomas Soome }
269199767f8SToomas Soome
270199767f8SToomas Soome /* sbrk emulation */
271199767f8SToomas Soome extern void setheap(void *base, void *top);
272199767f8SToomas Soome extern char *sbrk(int incr);
273199767f8SToomas Soome
274199767f8SToomas Soome extern void mallocstats(void);
275199767f8SToomas Soome
276199767f8SToomas Soome extern int printf(const char *fmt, ...) __printflike(1, 2);
277199767f8SToomas Soome extern void vprintf(const char *fmt, __va_list);
2786ea3a31bSToomas Soome extern int asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
279199767f8SToomas Soome extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
280573f5931SToomas Soome extern int snprintf(char *buf, size_t size, const char *cfmt, ...) \
281573f5931SToomas Soome __printflike(3, 4);
282199767f8SToomas Soome extern void vsprintf(char *buf, const char *cfmt, __va_list);
283199767f8SToomas Soome extern void vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
284199767f8SToomas Soome
285573f5931SToomas Soome extern void twiddle(uint_t callerdiv);
286573f5931SToomas Soome extern void twiddle_divisor(uint_t globaldiv);
287199767f8SToomas Soome
288199767f8SToomas Soome extern void ngets(char *, int);
289573f5931SToomas Soome #define gets(x) ngets((x), 0)
290199767f8SToomas Soome extern int fgetstr(char *buf, int size, int fd);
291199767f8SToomas Soome
292199767f8SToomas Soome extern int open(const char *, int);
293199767f8SToomas Soome #define O_RDONLY 0x0
294573f5931SToomas Soome #define O_WRONLY 0x1
295573f5931SToomas Soome #define O_RDWR 0x2
296199767f8SToomas Soome extern int close(int);
297199767f8SToomas Soome extern void closeall(void);
298199767f8SToomas Soome extern ssize_t read(int, void *, size_t);
299cf837ed8SToomas Soome extern ssize_t write(int, const void *, size_t);
300199767f8SToomas Soome extern struct dirent *readdirfd(int);
301199767f8SToomas Soome
302573f5931SToomas Soome extern void srandom(ulong_t seed);
303573f5931SToomas Soome extern ulong_t random(void);
304c142ce19SToomas Soome
305573f5931SToomas Soome extern char *optarg; /* getopt(3) external variables */
306199767f8SToomas Soome extern int optind, opterr, optopt, optreset;
307199767f8SToomas Soome extern int getopt(int, char * const [], const char *);
308199767f8SToomas Soome
309199767f8SToomas Soome /* pager.c */
310199767f8SToomas Soome extern void pager_open(void);
311199767f8SToomas Soome extern void pager_close(void);
312199767f8SToomas Soome extern int pager_output(const char *lines);
313199767f8SToomas Soome extern int pager_file(const char *fname);
314199767f8SToomas Soome
315199767f8SToomas Soome /* No signal state to preserve */
316573f5931SToomas Soome #define setjmp _setjmp
317573f5931SToomas Soome #define longjmp _longjmp
318199767f8SToomas Soome
319199767f8SToomas Soome /* environment.c */
320573f5931SToomas Soome /* value was dynamically allocated, free if changed/unset */
321573f5931SToomas Soome #define EV_DYNAMIC (1<<0)
322573f5931SToomas Soome /* value is volatile, make a copy of it */
323573f5931SToomas Soome #define EV_VOLATILE (1<<1)
324573f5931SToomas Soome /* don't call hook when setting */
325573f5931SToomas Soome #define EV_NOHOOK (1<<2)
326199767f8SToomas Soome
327199767f8SToomas Soome struct env_var;
328199767f8SToomas Soome typedef char *(ev_format_t)(struct env_var *ev);
329199767f8SToomas Soome typedef int (ev_sethook_t)(struct env_var *ev, int flags,
330199767f8SToomas Soome const void *value);
331199767f8SToomas Soome typedef int (ev_unsethook_t)(struct env_var *ev);
332199767f8SToomas Soome
333199767f8SToomas Soome struct env_var
334199767f8SToomas Soome {
335199767f8SToomas Soome char *ev_name;
336199767f8SToomas Soome int ev_flags;
337199767f8SToomas Soome void *ev_value;
338199767f8SToomas Soome ev_sethook_t *ev_sethook;
339199767f8SToomas Soome ev_unsethook_t *ev_unsethook;
340199767f8SToomas Soome struct env_var *ev_next, *ev_prev;
341199767f8SToomas Soome };
342199767f8SToomas Soome extern struct env_var *environ;
343199767f8SToomas Soome
344199767f8SToomas Soome extern struct env_var *env_getenv(const char *name);
345199767f8SToomas Soome extern int env_setenv(const char *name, int flags,
346573f5931SToomas Soome const void *value, ev_sethook_t sethook,
347573f5931SToomas Soome ev_unsethook_t unsethook);
3485fae793bSToomas Soome extern void env_discard(struct env_var *);
349199767f8SToomas Soome extern char *getenv(const char *name);
350199767f8SToomas Soome extern int setenv(const char *name, const char *value,
351573f5931SToomas Soome int overwrite);
352199767f8SToomas Soome extern int putenv(const char *string);
353199767f8SToomas Soome extern int unsetenv(const char *name);
354199767f8SToomas Soome
355199767f8SToomas Soome extern ev_sethook_t env_noset; /* refuse set operation */
356199767f8SToomas Soome extern ev_unsethook_t env_nounset; /* refuse unset operation */
357199767f8SToomas Soome
35828de4f3cSToomas Soome /* stdlib.h routines */
35928de4f3cSToomas Soome extern long strtol(const char *__restrict, char **__restrict, int);
36028de4f3cSToomas Soome extern long long strtoll(const char *__restrict, char **__restrict, int);
36128de4f3cSToomas Soome extern unsigned long strtoul(const char *__restrict, char **__restrict, int);
36228de4f3cSToomas Soome extern unsigned long long strtoull(const char *__restrict, char **__restrict,
36328de4f3cSToomas Soome int);
36428de4f3cSToomas Soome
365199767f8SToomas Soome /* BCD conversions (undocumented) */
366573f5931SToomas Soome extern uchar_t const bcd2bin_data[];
367573f5931SToomas Soome extern uchar_t const bin2bcd_data[];
368199767f8SToomas Soome extern char const hex2ascii_data[];
369199767f8SToomas Soome
370199767f8SToomas Soome #define bcd2bin(bcd) (bcd2bin_data[bcd])
371199767f8SToomas Soome #define bin2bcd(bin) (bin2bcd_data[bin])
372199767f8SToomas Soome #define hex2ascii(hex) (hex2ascii_data[hex])
373199767f8SToomas Soome
374199767f8SToomas Soome /* min/max (undocumented) */
imax(int a,int b)375199767f8SToomas Soome static __inline int imax(int a, int b) { return (a > b ? a : b); }
imin(int a,int b)376199767f8SToomas Soome static __inline int imin(int a, int b) { return (a < b ? a : b); }
lmax(long a,long b)377199767f8SToomas Soome static __inline long lmax(long a, long b) { return (a > b ? a : b); }
lmin(long a,long b)378199767f8SToomas Soome static __inline long lmin(long a, long b) { return (a < b ? a : b); }
max(uint_t a,uint_t b)379573f5931SToomas Soome static __inline uint_t max(uint_t a, uint_t b) { return (a > b ? a : b); }
min(uint_t a,uint_t b)380573f5931SToomas Soome static __inline uint_t min(uint_t a, uint_t b) { return (a < b ? a : b); }
qmax(quad_t a,quad_t b)381199767f8SToomas Soome static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
qmin(quad_t a,quad_t b)382199767f8SToomas Soome static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
ulmax(ulong_t a,ulong_t b)383573f5931SToomas Soome static __inline ulong_t ulmax(ulong_t a, ulong_t b) { return (a > b ? a : b); }
ulmin(ulong_t a,ulong_t b)384573f5931SToomas Soome static __inline ulong_t ulmin(ulong_t a, ulong_t b) { return (a < b ? a : b); }
385199767f8SToomas Soome
386199767f8SToomas Soome /* null functions for device/filesystem switches (undocumented) */
387199767f8SToomas Soome extern int nodev(void);
388573f5931SToomas Soome extern int noioctl(struct open_file *, ulong_t, void *);
389199767f8SToomas Soome extern void nullsys(void);
390199767f8SToomas Soome
391573f5931SToomas Soome extern int null_open(const char *, struct open_file *);
392573f5931SToomas Soome extern int null_close(struct open_file *);
393573f5931SToomas Soome extern int null_read(struct open_file *, void *, size_t, size_t *);
394573f5931SToomas Soome extern int null_write(struct open_file *, const void *, size_t, size_t *);
395573f5931SToomas Soome extern off_t null_seek(struct open_file *, off_t, int);
396573f5931SToomas Soome extern int null_stat(struct open_file *, struct stat *);
397573f5931SToomas Soome extern int null_readdir(struct open_file *, struct dirent *);
398199767f8SToomas Soome
399199767f8SToomas Soome
400c142ce19SToomas Soome /*
401c142ce19SToomas Soome * Machine dependent functions and data, must be provided or stubbed by
402c142ce19SToomas Soome * the consumer
403199767f8SToomas Soome */
404573f5931SToomas Soome extern void exit(int) __dead2;
405573f5931SToomas Soome extern int getchar(void);
406573f5931SToomas Soome extern int ischar(void);
407573f5931SToomas Soome extern void putchar(int);
408573f5931SToomas Soome extern int devopen(struct open_file *, const char *, const char **);
409573f5931SToomas Soome extern int devclose(struct open_file *f);
410573f5931SToomas Soome extern void panic(const char *, ...) __dead2 __printflike(1, 2);
411573f5931SToomas Soome extern void panic_action(void) __weak_symbol __dead2;
412573f5931SToomas Soome extern time_t getsecs(void);
413199767f8SToomas Soome extern struct fs_ops *file_system[];
414199767f8SToomas Soome extern struct fs_ops *exclusive_file_system;
415199767f8SToomas Soome extern struct devsw *devsw[];
416199767f8SToomas Soome
417199767f8SToomas Soome /*
418199767f8SToomas Soome * Expose byteorder(3) functions.
419199767f8SToomas Soome */
420199767f8SToomas Soome #ifndef _BYTEORDER_PROTOTYPED
421199767f8SToomas Soome #define _BYTEORDER_PROTOTYPED
422199767f8SToomas Soome extern uint32_t htonl(uint32_t);
423199767f8SToomas Soome extern uint16_t htons(uint16_t);
424199767f8SToomas Soome extern uint32_t ntohl(uint32_t);
425199767f8SToomas Soome extern uint16_t ntohs(uint16_t);
426199767f8SToomas Soome #endif
427199767f8SToomas Soome
428199767f8SToomas Soome #ifndef _BYTEORDER_FUNC_DEFINED
429199767f8SToomas Soome #define _BYTEORDER_FUNC_DEFINED
430199767f8SToomas Soome #define htonl(x) __htonl(x)
431199767f8SToomas Soome #define htons(x) __htons(x)
432199767f8SToomas Soome #define ntohl(x) __ntohl(x)
433199767f8SToomas Soome #define ntohs(x) __ntohs(x)
434199767f8SToomas Soome #endif
435199767f8SToomas Soome
436199767f8SToomas Soome void *Malloc(size_t, const char *, int);
437081aa5f6SToomas Soome void *Memalign(size_t, size_t, const char *, int);
438199767f8SToomas Soome void *Calloc(size_t, size_t, const char *, int);
439199767f8SToomas Soome void *Realloc(void *, size_t, const char *, int);
440081aa5f6SToomas Soome void *Reallocf(void *, size_t, const char *, int);
441199767f8SToomas Soome void Free(void *, const char *, int);
442199767f8SToomas Soome
443081aa5f6SToomas Soome #if DEBUG_MALLOC
444573f5931SToomas Soome #define malloc(x) Malloc(x, __FILE__, __LINE__)
445081aa5f6SToomas Soome #define memalign(x, y) Memalign(x, y, __FILE__, __LINE__)
446573f5931SToomas Soome #define calloc(x, y) Calloc(x, y, __FILE__, __LINE__)
447573f5931SToomas Soome #define free(x) Free(x, __FILE__, __LINE__)
448573f5931SToomas Soome #define realloc(x, y) Realloc(x, y, __FILE__, __LINE__)
449081aa5f6SToomas Soome #define reallocf(x, y) Reallocf(x, y, __FILE__, __LINE__)
450199767f8SToomas Soome #else
451573f5931SToomas Soome #define malloc(x) Malloc(x, NULL, 0)
452081aa5f6SToomas Soome #define memalign(x, y) Memalign(x, y, NULL, 0)
453573f5931SToomas Soome #define calloc(x, y) Calloc(x, y, NULL, 0)
454573f5931SToomas Soome #define free(x) Free(x, NULL, 0)
455573f5931SToomas Soome #define realloc(x, y) Realloc(x, y, NULL, 0)
456081aa5f6SToomas Soome #define reallocf(x, y) Reallocf(x, y, NULL, 0)
457199767f8SToomas Soome #endif
458199767f8SToomas Soome
459199767f8SToomas Soome #endif /* STAND_H */
460