xref: /minix3/include/util.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: util.h,v 1.68 2015/09/24 14:39:37 christos Exp $	*/
2b697b67dSBen Gras 
3b697b67dSBen Gras /*-
4b697b67dSBen Gras  * Copyright (c) 1995
5b697b67dSBen Gras  *	The Regents of the University of California.  All rights reserved.
6b697b67dSBen Gras  *
7b697b67dSBen Gras  * Redistribution and use in source and binary forms, with or without
8b697b67dSBen Gras  * modification, are permitted provided that the following conditions
9b697b67dSBen Gras  * are met:
10b697b67dSBen Gras  * 1. Redistributions of source code must retain the above copyright
11b697b67dSBen Gras  *    notice, this list of conditions and the following disclaimer.
12b697b67dSBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
13b697b67dSBen Gras  *    notice, this list of conditions and the following disclaimer in the
14b697b67dSBen Gras  *    documentation and/or other materials provided with the distribution.
15b697b67dSBen Gras  * 3. Neither the name of the University nor the names of its contributors
16b697b67dSBen Gras  *    may be used to endorse or promote products derived from this software
17b697b67dSBen Gras  *    without specific prior written permission.
18b697b67dSBen Gras  *
19b697b67dSBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20b697b67dSBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21b697b67dSBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22b697b67dSBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23b697b67dSBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24b697b67dSBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25b697b67dSBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26b697b67dSBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27b697b67dSBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28b697b67dSBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29b697b67dSBen Gras  * SUCH DAMAGE.
30b697b67dSBen Gras  */
31b697b67dSBen Gras 
32b697b67dSBen Gras #ifndef _UTIL_H_
33b697b67dSBen Gras #define	_UTIL_H_
34b697b67dSBen Gras 
35b697b67dSBen Gras #include <sys/cdefs.h>
36b697b67dSBen Gras #include <sys/types.h>
3784d9c625SLionel Sambuc #include <sys/ansi.h>
3884d9c625SLionel Sambuc #include <sys/inttypes.h>
39b697b67dSBen Gras 
40b697b67dSBen Gras #ifdef  _BSD_TIME_T_
41b697b67dSBen Gras typedef _BSD_TIME_T_    time_t;
42b697b67dSBen Gras #undef  _BSD_TIME_T_
43b697b67dSBen Gras #endif
4484d9c625SLionel Sambuc #ifdef  _BSD_SIZE_T_
4584d9c625SLionel Sambuc typedef _BSD_SIZE_T_    size_t;
4684d9c625SLionel Sambuc #undef  _BSD_SIZE_T_
4784d9c625SLionel Sambuc #endif
4884d9c625SLionel Sambuc 
4984d9c625SLionel Sambuc #if defined(_POSIX_C_SOURCE)
5084d9c625SLionel Sambuc #ifndef __VA_LIST_DECLARED
5184d9c625SLionel Sambuc typedef __va_list va_list;
5284d9c625SLionel Sambuc #define __VA_LIST_DECLARED
5384d9c625SLionel Sambuc #endif
5484d9c625SLionel Sambuc #endif
55b697b67dSBen Gras 
56b697b67dSBen Gras #define	PIDLOCK_NONBLOCK	1
57b697b67dSBen Gras #define	PIDLOCK_USEHOSTNAME	2
58b697b67dSBen Gras 
59b697b67dSBen Gras #define	PW_POLICY_BYSTRING	0
60b697b67dSBen Gras #define	PW_POLICY_BYPASSWD	1
61b697b67dSBen Gras #define	PW_POLICY_BYGROUP	2
62b697b67dSBen Gras 
63b697b67dSBen Gras __BEGIN_DECLS
64b697b67dSBen Gras struct disklabel;
65b697b67dSBen Gras struct iovec;
66b697b67dSBen Gras struct passwd;
67b697b67dSBen Gras struct termios;
68b697b67dSBen Gras struct utmp;
6984d9c625SLionel Sambuc struct utmpx;
70b697b67dSBen Gras struct winsize;
71b697b67dSBen Gras struct sockaddr;
72b697b67dSBen Gras 
73b697b67dSBen Gras char	       *flags_to_string(unsigned long, const char *);
74b697b67dSBen Gras pid_t		forkpty(int *, char *, struct termios *, struct winsize *);
75b697b67dSBen Gras const char     *getbootfile(void);
7684d9c625SLionel Sambuc int		getbyteorder(void);
77b697b67dSBen Gras off_t		getlabeloffset(void);
78b697b67dSBen Gras int		getlabelsector(void);
79dba3562dSLionel Sambuc int		getlabelusesmbr(void);
80b697b67dSBen Gras int		getmaxpartitions(void);
81b697b67dSBen Gras int		getrawpartition(void);
82dba3562dSLionel Sambuc const char     *getdiskrawname(char *, size_t, const char *);
83dba3562dSLionel Sambuc const char     *getdiskcookedname(char *, size_t, const char *);
84dba3562dSLionel Sambuc const char     *getfstypename(int);
85dba3562dSLionel Sambuc const char     *getfsspecname(char *, size_t, const char *);
86*0a6a1f1dSLionel Sambuc struct kinfo_vmentry *kinfo_getvmmap(pid_t, size_t *);
872fe8fb19SBen Gras #ifndef __LIBC12_SOURCE__
882fe8fb19SBen Gras void		login(const struct utmp *) __RENAME(__login50);
892fe8fb19SBen Gras void		loginx(const struct utmpx *) __RENAME(__loginx50);
902fe8fb19SBen Gras #endif
91b697b67dSBen Gras int		login_tty(int);
92b697b67dSBen Gras int		logout(const char *);
93b697b67dSBen Gras int		logoutx(const char *, int, int);
94b697b67dSBen Gras void		logwtmp(const char *, const char *, const char *);
95b697b67dSBen Gras void		logwtmpx(const char *, const char *, const char *, int, int);
96b697b67dSBen Gras int		opendisk(const char *, int, char *, size_t, int);
972fe8fb19SBen Gras int		opendisk1(const char *, int, char *, size_t, int,
982fe8fb19SBen Gras 			  int (*)(const char *, int, ...));
99b697b67dSBen Gras int		openpty(int *, int *, char *, struct termios *,
100b697b67dSBen Gras     struct winsize *);
1012fe8fb19SBen Gras #ifndef __LIBC12_SOURCE__
1022fe8fb19SBen Gras time_t		parsedate(const char *, const time_t *, const int *)
1032fe8fb19SBen Gras     __RENAME(__parsedate50);
1042fe8fb19SBen Gras #endif
105b697b67dSBen Gras int		pidfile(const char *);
106b697b67dSBen Gras int		pidlock(const char *, int, pid_t *, const char *);
107b697b67dSBen Gras int		pw_abort(void);
1082fe8fb19SBen Gras #ifndef __LIBC12_SOURCE__
1092fe8fb19SBen Gras void		pw_copy(int, int, struct passwd *, struct passwd *)
1102fe8fb19SBen Gras     __RENAME(__pw_copy50);
111b697b67dSBen Gras int		pw_copyx(int, int, struct passwd *, struct passwd *,
1122fe8fb19SBen Gras     char *, size_t) __RENAME(__pw_copyx50);
1132fe8fb19SBen Gras #endif
114b697b67dSBen Gras void		pw_edit(int, const char *);
115dba3562dSLionel Sambuc __dead void	pw_error(const char *, int, int);
116b697b67dSBen Gras void		pw_getconf(char *, size_t, const char *, const char *);
1172fe8fb19SBen Gras #ifndef __LIBC12_SOURCE__
118b697b67dSBen Gras void		pw_getpwconf(char *, size_t, const struct passwd *,
1192fe8fb19SBen Gras     const char *) __RENAME(__pw_getpwconf50);
1202fe8fb19SBen Gras #endif
121b697b67dSBen Gras const char     *pw_getprefix(void);
122b697b67dSBen Gras void		pw_init(void);
123b697b67dSBen Gras int		pw_lock(int);
124b697b67dSBen Gras int		pw_mkdb(const char *, int);
125b697b67dSBen Gras void		pw_prompt(void);
126b697b67dSBen Gras int		pw_setprefix(const char *);
127b697b67dSBen Gras int		raise_default_signal(int);
128b697b67dSBen Gras int		secure_path(const char *);
1292fe8fb19SBen Gras int		snprintb_m(char *, size_t, const char *, uint64_t, size_t);
130b697b67dSBen Gras int		snprintb(char *, size_t, const char *, uint64_t);
131b697b67dSBen Gras int		sockaddr_snprintf(char *, size_t, const char *,
132b697b67dSBen Gras     const struct sockaddr *);
133dba3562dSLionel Sambuc char 	       *strpct(char *, size_t, uintmax_t, uintmax_t, size_t);
134dba3562dSLionel Sambuc char 	       *strspct(char *, size_t, intmax_t, intmax_t, size_t);
135b697b67dSBen Gras int		string_to_flags(char **, unsigned long *, unsigned long *);
136b697b67dSBen Gras int		ttyaction(const char *, const char *, const char *);
137b697b67dSBen Gras int		ttylock(const char *, int, pid_t *);
138b697b67dSBen Gras char	       *ttymsg(struct iovec *, int, const char *, int);
139b697b67dSBen Gras int		ttyunlock(const char *);
140b697b67dSBen Gras 
141b697b67dSBen Gras uint16_t	disklabel_dkcksum(struct disklabel *);
142b697b67dSBen Gras int		disklabel_scan(struct disklabel *, char *, size_t);
143b697b67dSBen Gras 
144b697b67dSBen Gras /* Error checked functions */
145b697b67dSBen Gras void		(*esetfunc(void (*)(int, const char *, ...)))
146b697b67dSBen Gras     (int, const char *, ...);
147b697b67dSBen Gras size_t 		estrlcpy(char *, const char *, size_t);
148b697b67dSBen Gras size_t 		estrlcat(char *, const char *, size_t);
149b697b67dSBen Gras char 		*estrdup(const char *);
150b697b67dSBen Gras char 		*estrndup(const char *, size_t);
151*0a6a1f1dSLionel Sambuc intmax_t	estrtoi(const char *, int, intmax_t, intmax_t);
152*0a6a1f1dSLionel Sambuc uintmax_t	estrtou(const char *, int, uintmax_t, uintmax_t);
153b697b67dSBen Gras void 		*ecalloc(size_t, size_t);
154b697b67dSBen Gras void 		*emalloc(size_t);
155b697b67dSBen Gras void 		*erealloc(void *, size_t);
156*0a6a1f1dSLionel Sambuc void 		ereallocarr(void *, size_t, size_t);
1572fe8fb19SBen Gras struct __sFILE	*efopen(const char *, const char *);
158b697b67dSBen Gras int	 	easprintf(char ** __restrict, const char * __restrict, ...)
1592fe8fb19SBen Gras 			__printflike(2, 3);
16084d9c625SLionel Sambuc int		evasprintf(char ** __restrict, const char * __restrict,
16184d9c625SLionel Sambuc     __va_list) __printflike(2, 0);
162b697b67dSBen Gras __END_DECLS
163b697b67dSBen Gras 
164b697b67dSBen Gras #endif /* !_UTIL_H_ */
165