3 * Copyright (c) 1995 - 2002 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.169 2002/08/26 21:43:38 assar 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>
113 #ifdef HAVE_TERMIOS_H
116 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
117 #include <sys/ioctl.h>
119 #ifdef TIME_WITH_SYS_TIME
120 #include <sys/time.h>
122 #elif defined(HAVE_SYS_TIME_H)
123 #include <sys/time.h>
133 #ifndef ROKEN_LIB_FUNCTION
134 #if defined(__BORLANDC__)
135 #define ROKEN_LIB_FUNCTION /* not-ready-definition-yet */
136 #elif defined(_MSC_VER)
137 #define ROKEN_LIB_FUNCTION /* not-ready-definition-yet2 */
139 #define ROKEN_LIB_FUNCTION
147 #include <roken-common.h>
151 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
152 #define setsid _setsid
156 int putenv(const char *string);
159 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
160 int setenv(const char *var, const char *val, int rewrite);
163 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
164 void unsetenv(const char *name);
167 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
168 char *getusershell(void);
169 void endusershell(void);
172 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
173 int snprintf (char *str, size_t sz, const char *format, ...)
174 __attribute__ ((format (printf, 3, 4)));
177 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
178 int vsnprintf (char *str, size_t sz, const char *format, va_list ap)
179 __attribute__((format (printf, 3, 0)));
182 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
183 int asprintf (char **ret, const char *format, ...)
184 __attribute__ ((format (printf, 2, 3)));
187 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
188 int vasprintf (char **ret, const char *format, va_list ap)
189 __attribute__((format (printf, 2, 0)));
192 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
193 int asnprintf (char **ret, size_t max_sz, const char *format, ...)
194 __attribute__ ((format (printf, 3, 4)));
197 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
198 int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap)
199 __attribute__((format (printf, 3, 0)));
203 char * strdup(const char *old);
206 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
207 char * strndup(const char *old, size_t sz);
211 char * strlwr(char *);
215 size_t strnlen(const char*, size_t);
218 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
219 char *strsep(char**, const char*);
222 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
223 ssize_t strsep_copy(const char**, const char*, char*, size_t);
226 #ifndef HAVE_STRCASECMP
227 int strcasecmp(const char *s1, const char *s2);
230 #ifdef NEED_FCLOSE_PROTO
234 #ifdef NEED_STRTOK_R_PROTO
235 char *strtok_r(char *s1, const char *s2, char **lasts);
239 char * strupr(char *);
243 size_t strlcpy (char *dst, const char *src, size_t dst_sz);
247 size_t strlcat (char *dst, const char *src, size_t dst_sz);
250 #ifndef HAVE_GETDTABLESIZE
251 int getdtablesize(void);
254 #if !defined(HAVE_STRERROR) && !defined(strerror)
255 char *strerror(int eno);
258 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
259 /* This causes a fatal error under Psoriasis */
260 #if !(defined(SunOS) && (SunOS >= 50))
261 const char *hstrerror(int herr);
265 #ifndef HAVE_H_ERRNO_DECLARATION
269 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
270 int inet_aton(const char *cp, struct in_addr *adr);
273 #ifndef HAVE_INET_NTOP
275 inet_ntop(int af, const void *src, char *dst, size_t size);
278 #ifndef HAVE_INET_PTON
280 inet_pton(int af, const char *src, void *dst);
283 #if !defined(HAVE_GETCWD)
284 char* getcwd(char *path, size_t size);
289 struct passwd *k_getpwnam (const char *user);
290 struct passwd *k_getpwuid (uid_t uid);
293 const char *get_default_username (void);
296 int seteuid(uid_t euid);
300 int setegid(gid_t egid);
304 int lstat(const char *path, struct stat *buf);
307 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
312 int cgetent(char **buf, char **db_array, const char *name);
313 int cgetstr(char *buf, const char *cap, char **str);
316 #ifndef HAVE_INITGROUPS
317 int initgroups(const char *name, gid_t basegid);
321 int fchown(int fd, uid_t owner, gid_t group);
325 int daemon(int nochdir, int noclose);
329 int innetgr(const char *netgroup, const char *machine,
330 const char *user, const char *domain);
334 int chown(const char *path, uid_t owner, gid_t group);
338 int rcmd(char **ahost, unsigned short inport, const char *locuser,
339 const char *remuser, const char *cmd, int *fd2p);
342 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
343 int innetgr(const char*, const char*, const char*, const char*);
346 #ifndef HAVE_IRUSEROK
347 int iruserok(unsigned raddr, int superuser, const char *ruser,
351 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
352 int gethostname(char *name, int namelen);
357 writev(int d, const struct iovec *iov, int iovcnt);
362 readv(int d, const struct iovec *iov, int iovcnt);
367 mkstemp(char *template);
371 void pidfile (const char*);
375 unsigned int bswap32(unsigned int);
379 unsigned short bswap16(unsigned short);
384 #define LOCK_SH 1 /* Shared lock */
387 #define LOCK_EX 2 /* Exclusive lock */
390 #define LOCK_NB 4 /* Don't block when locking */
393 #define LOCK_UN 8 /* Unlock */
396 int flock(int fd, int operation);
397 #endif /* HAVE_FLOCK */
399 time_t tm2time (struct tm tm, int local);
401 int unix_verify_user(char *user, char *password);
403 int roken_concat (char *s, size_t len, ...);
405 size_t roken_mconcat (char **s, size_t max_len, ...);
407 int roken_vconcat (char *s, size_t len, va_list args);
409 size_t roken_vmconcat (char **s, size_t max_len, va_list args);
411 ssize_t net_write (int fd, const void *buf, size_t nbytes);
413 ssize_t net_read (int fd, void *buf, size_t nbytes);
417 #ifndef HAVE_STRUCT_WINSIZE
419 unsigned short ws_row, ws_col;
420 unsigned short ws_xpixel, ws_ypixel;
424 int get_window_size(int fd, struct winsize *);
427 void vsyslog(int pri, const char *fmt, va_list ap);
430 #ifndef HAVE_OPTARG_DECLARATION
433 #ifndef HAVE_OPTIND_DECLARATION
436 #ifndef HAVE_OPTERR_DECLARATION
440 #ifndef HAVE___PROGNAME_DECLARATION
441 extern const char *__progname;
444 #ifndef HAVE_ENVIRON_DECLARATION
445 extern char **environ;
448 #ifndef HAVE_GETIPNODEBYNAME
450 getipnodebyname (const char *name, int af, int flags, int *error_num);
453 #ifndef HAVE_GETIPNODEBYADDR
455 getipnodebyaddr (const void *src, size_t len, int af, int *error_num);
458 #ifndef HAVE_FREEHOSTENT
460 freehostent (struct hostent *h);
463 #ifndef HAVE_COPYHOSTENT
465 copyhostent (const struct hostent *h);
468 #ifndef HAVE_SOCKLEN_T
469 typedef int socklen_t;
472 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
474 #ifndef HAVE_SA_FAMILY_T
475 typedef unsigned short sa_family_t;
479 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
481 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
484 #define _SS_ALIGNSIZE sizeof(unsigned long)
486 #if HAVE_STRUCT_SOCKADDR_SA_LEN
488 typedef unsigned char roken_sa_family_t;
490 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
491 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
493 struct sockaddr_storage {
494 unsigned char ss_len;
495 roken_sa_family_t ss_family;
496 char __ss_pad1[_SS_PAD1SIZE];
497 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
500 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
502 typedef unsigned short roken_sa_family_t;
504 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
505 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
507 struct sockaddr_storage {
508 roken_sa_family_t ss_family;
509 char __ss_pad1[_SS_PAD1SIZE];
510 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
513 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
515 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
517 #ifndef HAVE_STRUCT_ADDRINFO
525 struct sockaddr *ai_addr;
526 struct addrinfo *ai_next;
530 #ifndef HAVE_GETADDRINFO
532 getaddrinfo(const char *nodename,
533 const char *servname,
534 const struct addrinfo *hints,
535 struct addrinfo **res);
538 #ifndef HAVE_GETNAMEINFO
539 int getnameinfo(const struct sockaddr *sa, socklen_t salen,
540 char *host, size_t hostlen,
541 char *serv, size_t servlen,
545 #ifndef HAVE_FREEADDRINFO
547 freeaddrinfo(struct addrinfo *ai);
550 #ifndef HAVE_GAI_STRERROR
552 gai_strerror(int ecode);
556 getnameinfo_verified(const struct sockaddr *sa, socklen_t salen,
557 char *host, size_t hostlen,
558 char *serv, size_t servlen,
561 int roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
562 int roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
564 #ifndef HAVE_STRFTIME
566 strftime (char *buf, size_t maxsize, const char *format,
567 const struct tm *tm);
570 #ifndef HAVE_STRPTIME
572 strptime (const char *buf, const char *format, struct tm *timeptr);
576 void *emalloc (size_t);
579 void *ecalloc(size_t num, size_t sz);
581 #ifndef HAVE_EREALLOC
582 void *erealloc (void *, size_t);
585 char *estrdup (const char *);
593 int roken_gethostby_setup(const char*, const char*);
594 struct hostent* roken_gethostbyname(const char*);
595 struct hostent* 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 setprogname(const char *argv0);
632 #ifndef HAVE_GETPROGNAME
633 const char *getprogname(void);
636 void mini_inetd_addrinfo (struct addrinfo*);
637 void mini_inetd (int port);
639 void set_progname(char *argv0);
640 const char *get_progname(void);
642 #ifndef HAVE_LOCALTIME_R
644 localtime_r(const time_t *timer, struct tm *result);
647 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
649 strsvis(char *dst, const char *src, int flag, const char *extra);
652 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
654 strunvis(char *dst, const char *src);
657 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
659 strvis(char *dst, const char *src, int flag);
662 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
664 strvisx(char *dst, const char *src, size_t len, int flag);
667 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
669 svis(char *dst, int c, int flag, int nextc, const char *extra);
672 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
674 unvis(char *cp, int c, int *astate, int flag);
677 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
679 vis(char *dst, int c, int flag, int nextc);