3 * Copyright (c) 1995-2005 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /* $Id: roken.h.in,v 1.175 2005/07/07 19:16:17 lha Exp $ */
47 #ifdef HAVE_SYS_PARAM_H
48 #include <sys/param.h>
50 #ifdef HAVE_INTTYPES_H
53 #ifdef HAVE_SYS_TYPES_H
54 #include <sys/types.h>
56 #ifdef HAVE_SYS_BITYPES_H
57 #include <sys/bitypes.h>
59 #ifdef HAVE_BIND_BITYPES_H
60 #include <bind/bitypes.h>
62 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
63 #include <netinet/in6_machtypes.h>
68 #ifdef HAVE_SYS_SOCKET_H
69 #include <sys/socket.h>
77 #ifdef HAVE_SYS_STAT_H
80 #ifdef HAVE_NETINET_IN_H
81 #include <netinet/in.h>
83 #ifdef HAVE_NETINET_IN6_H
84 #include <netinet/in6.h>
86 #ifdef HAVE_NETINET6_IN6_H
87 #include <netinet6/in6.h>
89 #ifdef HAVE_ARPA_INET_H
90 #include <arpa/inet.h>
95 #ifdef HAVE_ARPA_NAMESER_H
96 #include <arpa/nameser.h>
111 #ifdef HAVE_TERMIOS_H
114 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
115 #include <sys/ioctl.h>
117 #ifdef TIME_WITH_SYS_TIME
118 #include <sys/time.h>
120 #elif defined(HAVE_SYS_TIME_H)
121 #include <sys/time.h>
125 #ifdef HAVE_STRINGS_H
137 #include <roken-common.h>
141 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
142 #define setsid _setsid
146 int ROKEN_LIB_FUNCTION putenv(const char *string);
149 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
150 int ROKEN_LIB_FUNCTION setenv(const char *var, const char *val, int rewrite);
153 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
154 void ROKEN_LIB_FUNCTION unsetenv(const char *name);
157 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
158 char * ROKEN_LIB_FUNCTION getusershell(void);
159 void ROKEN_LIB_FUNCTION endusershell(void);
162 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
163 int ROKEN_LIB_FUNCTION snprintf (char *str, size_t sz, const char *format, ...)
164 __attribute__ ((format (printf, 3, 4)));
167 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
168 int ROKEN_LIB_FUNCTION
169 vsnprintf (char *str, size_t sz, const char *format, va_list ap)
170 __attribute__((format (printf, 3, 0)));
173 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
174 int ROKEN_LIB_FUNCTION
175 asprintf (char **ret, const char *format, ...)
176 __attribute__ ((format (printf, 2, 3)));
179 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
180 int ROKEN_LIB_FUNCTION
181 vasprintf (char **ret, const char *format, va_list ap)
182 __attribute__((format (printf, 2, 0)));
185 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
186 int ROKEN_LIB_FUNCTION
187 asnprintf (char **ret, size_t max_sz, const char *format, ...)
188 __attribute__ ((format (printf, 3, 4)));
191 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
192 int ROKEN_LIB_FUNCTION
193 vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap)
194 __attribute__((format (printf, 3, 0)));
198 char * ROKEN_LIB_FUNCTION strdup(const char *old);
201 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
202 char * ROKEN_LIB_FUNCTION strndup(const char *old, size_t sz);
206 char * ROKEN_LIB_FUNCTION strlwr(char *);
210 size_t ROKEN_LIB_FUNCTION strnlen(const char*, size_t);
213 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
214 char * ROKEN_LIB_FUNCTION strsep(char**, const char*);
217 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
218 ssize_t ROKEN_LIB_FUNCTION strsep_copy(const char**, const char*, char*, size_t);
221 #ifndef HAVE_STRCASECMP
222 int ROKEN_LIB_FUNCTION strcasecmp(const char *s1, const char *s2);
225 #ifdef NEED_FCLOSE_PROTO
226 int ROKEN_LIB_FUNCTION fclose(FILE *);
229 #ifdef NEED_STRTOK_R_PROTO
230 char * ROKEN_LIB_FUNCTION strtok_r(char *s1, const char *s2, char **lasts);
234 char * ROKEN_LIB_FUNCTION strupr(char *);
238 size_t ROKEN_LIB_FUNCTION strlcpy (char *dst, const char *src, size_t dst_sz);
242 size_t ROKEN_LIB_FUNCTION strlcat (char *dst, const char *src, size_t dst_sz);
245 #ifndef HAVE_GETDTABLESIZE
246 int ROKEN_LIB_FUNCTION getdtablesize(void);
249 #if !defined(HAVE_STRERROR) && !defined(strerror)
250 char * ROKEN_LIB_FUNCTION strerror(int eno);
253 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
254 /* This causes a fatal error under Psoriasis */
255 #if !(defined(SunOS) && (SunOS >= 50))
256 const char * ROKEN_LIB_FUNCTION hstrerror(int herr);
260 #if !HAVE_DECL_H_ERRNO
264 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
265 int ROKEN_LIB_FUNCTION inet_aton(const char *cp, struct in_addr *adr);
268 #ifndef HAVE_INET_NTOP
269 const char * ROKEN_LIB_FUNCTION
270 inet_ntop(int af, const void *src, char *dst, size_t size);
273 #ifndef HAVE_INET_PTON
274 int ROKEN_LIB_FUNCTION
275 inet_pton(int af, const char *src, void *dst);
278 #if !defined(HAVE_GETCWD)
279 char* ROKEN_LIB_FUNCTION getcwd(char *path, size_t size);
284 struct passwd * ROKEN_LIB_FUNCTION k_getpwnam (const char *user);
285 struct passwd * ROKEN_LIB_FUNCTION k_getpwuid (uid_t uid);
288 const char * ROKEN_LIB_FUNCTION get_default_username (void);
291 int ROKEN_LIB_FUNCTION seteuid(uid_t euid);
295 int ROKEN_LIB_FUNCTION setegid(gid_t egid);
299 int ROKEN_LIB_FUNCTION lstat(const char *path, struct stat *buf);
302 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
303 int ROKEN_LIB_FUNCTION mkstemp(char *);
307 int ROKEN_LIB_FUNCTION cgetent(char **buf, char **db_array, const char *name);
308 int ROKEN_LIB_FUNCTION cgetstr(char *buf, const char *cap, char **str);
311 #ifndef HAVE_INITGROUPS
312 int ROKEN_LIB_FUNCTION initgroups(const char *name, gid_t basegid);
316 int ROKEN_LIB_FUNCTION fchown(int fd, uid_t owner, gid_t group);
319 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
320 int ROKEN_LIB_FUNCTION daemon(int nochdir, int noclose);
324 int ROKEN_LIB_FUNCTION innetgr(const char *netgroup, const char *machine,
325 const char *user, const char *domain);
329 int ROKEN_LIB_FUNCTION chown(const char *path, uid_t owner, gid_t group);
333 int ROKEN_LIB_FUNCTION
334 rcmd(char **ahost, unsigned short inport, const char *locuser,
335 const char *remuser, const char *cmd, int *fd2p);
338 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
339 int ROKEN_LIB_FUNCTION innetgr(const char*, const char*,
340 const char*, const char*);
343 #ifndef HAVE_IRUSEROK
344 int ROKEN_LIB_FUNCTION iruserok(unsigned raddr, int superuser,
345 const char *ruser, const char *luser);
348 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
349 int ROKEN_LIB_FUNCTION gethostname(char *name, int namelen);
353 ssize_t ROKEN_LIB_FUNCTION
354 writev(int d, const struct iovec *iov, int iovcnt);
358 ssize_t ROKEN_LIB_FUNCTION
359 readv(int d, const struct iovec *iov, int iovcnt);
363 int ROKEN_LIB_FUNCTION
364 mkstemp(char *template);
368 void ROKEN_LIB_FUNCTION pidfile (const char*);
372 unsigned int ROKEN_LIB_FUNCTION bswap32(unsigned int);
376 unsigned short ROKEN_LIB_FUNCTION bswap16(unsigned short);
381 #define LOCK_SH 1 /* Shared lock */
384 #define LOCK_EX 2 /* Exclusive lock */
387 #define LOCK_NB 4 /* Don't block when locking */
390 #define LOCK_UN 8 /* Unlock */
393 int flock(int fd, int operation);
394 #endif /* HAVE_FLOCK */
396 time_t ROKEN_LIB_FUNCTION tm2time (struct tm tm, int local);
398 int ROKEN_LIB_FUNCTION unix_verify_user(char *user, char *password);
400 int ROKEN_LIB_FUNCTION roken_concat (char *s, size_t len, ...);
402 size_t ROKEN_LIB_FUNCTION roken_mconcat (char **s, size_t max_len, ...);
404 int ROKEN_LIB_FUNCTION roken_vconcat (char *s, size_t len, va_list args);
406 size_t ROKEN_LIB_FUNCTION
407 roken_vmconcat (char **s, size_t max_len, va_list args);
409 ssize_t ROKEN_LIB_FUNCTION net_write (int fd, const void *buf, size_t nbytes);
411 ssize_t ROKEN_LIB_FUNCTION net_read (int fd, void *buf, size_t nbytes);
413 int ROKEN_LIB_FUNCTION issuid(void);
415 #ifndef HAVE_STRUCT_WINSIZE
417 unsigned short ws_row, ws_col;
418 unsigned short ws_xpixel, ws_ypixel;
422 int ROKEN_LIB_FUNCTION get_window_size(int fd, struct winsize *);
425 void ROKEN_LIB_FUNCTION vsyslog(int pri, const char *fmt, va_list ap);
428 #if !HAVE_DECL_OPTARG
431 #if !HAVE_DECL_OPTIND
434 #if !HAVE_DECL_OPTERR
438 #if !HAVE_DECL_ENVIRON
439 extern char **environ;
442 #ifndef HAVE_GETIPNODEBYNAME
443 struct hostent * ROKEN_LIB_FUNCTION
444 getipnodebyname (const char *name, int af, int flags, int *error_num);
447 #ifndef HAVE_GETIPNODEBYADDR
448 struct hostent * ROKEN_LIB_FUNCTION
449 getipnodebyaddr (const void *src, size_t len, int af, int *error_num);
452 #ifndef HAVE_FREEHOSTENT
453 void ROKEN_LIB_FUNCTION
454 freehostent (struct hostent *h);
457 #ifndef HAVE_COPYHOSTENT
458 struct hostent * ROKEN_LIB_FUNCTION
459 copyhostent (const struct hostent *h);
462 #ifndef HAVE_SOCKLEN_T
463 typedef int socklen_t;
466 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
468 #ifndef HAVE_SA_FAMILY_T
469 typedef unsigned short sa_family_t;
473 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
475 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
478 #define _SS_ALIGNSIZE sizeof(unsigned long)
480 #if HAVE_STRUCT_SOCKADDR_SA_LEN
482 typedef unsigned char roken_sa_family_t;
484 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
485 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
487 struct sockaddr_storage {
488 unsigned char ss_len;
489 roken_sa_family_t ss_family;
490 char __ss_pad1[_SS_PAD1SIZE];
491 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
494 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
496 typedef unsigned short roken_sa_family_t;
498 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
499 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
501 struct sockaddr_storage {
502 roken_sa_family_t ss_family;
503 char __ss_pad1[_SS_PAD1SIZE];
504 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
507 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
509 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
511 #ifndef HAVE_STRUCT_ADDRINFO
519 struct sockaddr *ai_addr;
520 struct addrinfo *ai_next;
524 #ifndef HAVE_GETADDRINFO
525 int ROKEN_LIB_FUNCTION
526 getaddrinfo(const char *nodename,
527 const char *servname,
528 const struct addrinfo *hints,
529 struct addrinfo **res);
532 #ifndef HAVE_GETNAMEINFO
533 int ROKEN_LIB_FUNCTION
534 getnameinfo(const struct sockaddr *sa, socklen_t salen,
535 char *host, size_t hostlen,
536 char *serv, size_t servlen,
540 #ifndef HAVE_FREEADDRINFO
541 void ROKEN_LIB_FUNCTION
542 freeaddrinfo(struct addrinfo *ai);
545 #ifndef HAVE_GAI_STRERROR
546 char * ROKEN_LIB_FUNCTION
547 gai_strerror(int ecode);
550 int ROKEN_LIB_FUNCTION
551 getnameinfo_verified(const struct sockaddr *sa, socklen_t salen,
552 char *host, size_t hostlen,
553 char *serv, size_t servlen,
556 int ROKEN_LIB_FUNCTION
557 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
558 int ROKEN_LIB_FUNCTION
559 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
561 #ifndef HAVE_STRFTIME
562 size_t ROKEN_LIB_FUNCTION
563 strftime (char *buf, size_t maxsize, const char *format,
564 const struct tm *tm);
567 #ifndef HAVE_STRPTIME
568 char * ROKEN_LIB_FUNCTION
569 strptime (const char *buf, const char *format, struct tm *timeptr);
573 void * ROKEN_LIB_FUNCTION emalloc (size_t);
576 void * ROKEN_LIB_FUNCTION ecalloc(size_t num, size_t sz);
578 #ifndef HAVE_EREALLOC
579 void * ROKEN_LIB_FUNCTION erealloc (void *, size_t);
582 char * ROKEN_LIB_FUNCTION estrdup (const char *);
590 int ROKEN_LIB_FUNCTION
591 roken_gethostby_setup(const char*, const char*);
592 struct hostent* ROKEN_LIB_FUNCTION
593 roken_gethostbyname(const char*);
594 struct hostent* ROKEN_LIB_FUNCTION
595 roken_gethostbyaddr(const void*, size_t, int);
597 #ifdef GETHOSTBYNAME_PROTO_COMPATIBLE
598 #define roken_gethostbyname(x) gethostbyname(x)
600 #define roken_gethostbyname(x) gethostbyname((char *)x)
603 #ifdef GETHOSTBYADDR_PROTO_COMPATIBLE
604 #define roken_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
606 #define roken_gethostbyaddr(a, l, t) gethostbyaddr((char *)a, l, t)
610 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
611 #define roken_getservbyname(x,y) getservbyname(x,y)
613 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
616 #ifdef OPENLOG_PROTO_COMPATIBLE
617 #define roken_openlog(a,b,c) openlog(a,b,c)
619 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
622 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
623 #define roken_getsockname(a,b,c) getsockname(a,b,c)
625 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
628 #ifndef HAVE_SETPROGNAME
629 void ROKEN_LIB_FUNCTION setprogname(const char *argv0);
632 #ifndef HAVE_GETPROGNAME
633 const char * ROKEN_LIB_FUNCTION getprogname(void);
636 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
637 extern const char *__progname;
640 void ROKEN_LIB_FUNCTION mini_inetd_addrinfo (struct addrinfo*);
641 void ROKEN_LIB_FUNCTION mini_inetd (int port);
643 #ifndef HAVE_LOCALTIME_R
644 struct tm * ROKEN_LIB_FUNCTION
645 localtime_r(const time_t *timer, struct tm *result);
648 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
649 int ROKEN_LIB_FUNCTION
650 strsvis(char *dst, const char *src, int flag, const char *extra);
653 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
654 int ROKEN_LIB_FUNCTION
655 strunvis(char *dst, const char *src);
658 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
659 int ROKEN_LIB_FUNCTION
660 strvis(char *dst, const char *src, int flag);
663 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
664 int ROKEN_LIB_FUNCTION
665 strvisx(char *dst, const char *src, size_t len, int flag);
668 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
669 char * ROKEN_LIB_FUNCTION
670 svis(char *dst, int c, int flag, int nextc, const char *extra);
673 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
674 int ROKEN_LIB_FUNCTION
675 unvis(char *cp, int c, int *astate, int flag);
678 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
679 char * ROKEN_LIB_FUNCTION
680 vis(char *dst, int c, int flag, int nextc);
683 #if !defined(HAVE_CLOSEFROM)
684 int ROKEN_LIB_FUNCTION