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
44 #ifndef ROKEN_LIB_FUNCTION
46 # define ROKEN_LIB_CALL __cdecl
47 # ifdef ROKEN_LIB_DYNAMIC
48 # define ROKEN_LIB_FUNCTION __declspec(dllimport)
49 # define ROKEN_LIB_VARIABLE __declspec(dllimport)
51 # define ROKEN_LIB_FUNCTION
52 # define ROKEN_LIB_VARIABLE
55 #define ROKEN_LIB_FUNCTION
56 #define ROKEN_LIB_CALL
57 #define ROKEN_LIB_VARIABLE
62 /* Declarations for Microsoft Windows */
68 * error codes for inet_ntop/inet_pton
70 #define EAFNOSUPPORT WSAEAFNOSUPPORT
72 typedef SOCKET rk_socket_t;
74 #define rk_closesocket(x) closesocket(x)
75 #define rk_INVALID_SOCKET INVALID_SOCKET
76 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
77 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
78 #define rk_SOCK_ERRNO WSAGetLastError()
80 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
82 #define ETIMEDOUT WSAETIMEDOUT
83 #define EWOULDBLOCK WSAEWOULDBLOCK
84 #define ENOTSOCK WSAENOTSOCK
86 #define rk_SOCK_INIT() rk_WSAStartup()
87 #define rk_SOCK_EXIT() rk_WSACleanup()
89 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
90 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
92 #else /* not WinSock */
94 typedef int rk_socket_t;
96 #define rk_closesocket(x) close(x)
97 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
98 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
99 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
100 #define rk_SOCK_ERRNO errno
101 #define rk_INVALID_SOCKET (-1)
103 #define rk_SOCK_INIT() 0
104 #define rk_SOCK_EXIT() do { } while(0)
109 /* Declarations for Microsoft Visual C runtime on Windows */
115 #ifndef __BIT_TYPES_DEFINED__
116 #define __BIT_TYPES_DEFINED__
118 typedef __int8 int8_t;
119 typedef __int16 int16_t;
120 typedef __int32 int32_t;
121 typedef __int64 int64_t;
122 typedef unsigned __int8 uint8_t;
123 typedef unsigned __int16 uint16_t;
124 typedef unsigned __int32 uint32_t;
125 typedef unsigned __int64 uint64_t;
126 typedef uint8_t u_int8_t;
127 typedef uint16_t u_int16_t;
128 typedef uint32_t u_int32_t;
129 typedef uint64_t u_int64_t;
131 #endif /* __BIT_TYPES_DEFINED__ */
133 #define UNREACHABLE(x) x
134 #define UNUSED_ARGUMENT(x) ((void) x)
136 #define RETSIGTYPE void
138 #define VOID_RETSIGTYPE 1
140 #ifdef VOID_RETSIGTYPE
141 #define SIGRETURN(x) return
143 #define SIGRETURN(x) return (RETSIGTYPE)(x)
150 typedef unsigned int gid_t;
152 typedef unsigned int uid_t;
154 typedef unsigned short mode_t;
159 #define inline __inline
164 #define UNREACHABLE(x)
165 #define UNUSED_ARGUMENT(x)
173 #ifdef HAVE_SYS_PARAM_H
174 #include <sys/param.h>
176 #ifdef HAVE_INTTYPES_H
177 #include <inttypes.h>
179 #ifdef HAVE_SYS_TYPES_H
180 #include <sys/types.h>
182 #ifdef HAVE_SYS_BITYPES_H
183 #include <sys/bitypes.h>
185 #ifdef HAVE_BIND_BITYPES_H
186 #include <bind/bitypes.h>
188 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
189 #include <netinet/in6_machtypes.h>
194 #ifdef HAVE_SYS_SOCKET_H
195 #include <sys/socket.h>
197 #ifdef HAVE_SYS_UIO_H
203 #ifdef HAVE_SYS_STAT_H
204 #include <sys/stat.h>
206 #ifdef HAVE_NETINET_IN_H
207 #include <netinet/in.h>
209 #ifdef HAVE_NETINET_IN6_H
210 #include <netinet/in6.h>
212 #ifdef HAVE_NETINET6_IN6_H
213 #include <netinet6/in6.h>
215 #ifdef HAVE_ARPA_INET_H
216 #include <arpa/inet.h>
221 #ifdef HAVE_ARPA_NAMESER_H
222 #include <arpa/nameser.h>
237 #ifdef HAVE_TERMIOS_H
240 #ifdef HAVE_SYS_IOCTL_H
241 #include <sys/ioctl.h>
243 #ifdef TIME_WITH_SYS_TIME
244 #include <sys/time.h>
246 #elif defined(HAVE_SYS_TIME_H)
247 #include <sys/time.h>
252 #ifdef HAVE_WS2TCPIP_H
253 #include <ws2tcpip.h>
264 #ifdef BACKSLASH_PATH_DELIM
265 #define rk_PATH_DELIM '\\'
270 typedef __int64 ssize_t;
276 #include <roken-common.h>
280 #ifdef HAVE_UINTPTR_T
281 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
283 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
286 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
287 #define setsid _setsid
291 /* Additional macros for Visual C/C++ runtime */
295 #define getpid _getpid
301 #define fsync _commit
303 /* The MSVC implementation of snprintf is not C99 compliant. */
304 #define snprintf rk_snprintf
305 #define vsnprintf rk_vsnprintf
306 #define vasnprintf rk_vasnprintf
307 #define vasprintf rk_vasprintf
308 #define asnprintf rk_asnprintf
309 #define asprintf rk_asprintf
311 #define _PIPE_BUFFER_SZ 8192
312 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
314 #define ftruncate(fd, sz) _chsize((fd), (sz))
316 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
317 rk_snprintf (char *str, size_t sz, const char *format, ...);
319 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
320 rk_asprintf (char **ret, const char *format, ...);
322 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
323 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
325 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
326 rk_vasprintf (char **ret, const char *format, va_list args);
328 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
329 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
331 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
332 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
334 /* missing stat.h predicates */
336 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
338 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
340 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
342 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
344 /* The following are not implemented:
351 #endif /* _MSC_VER */
355 /* While we are at it, define WinSock specific scatter gather socket
358 #define iovec _WSABUF
364 socklen_t msg_namelen;
365 struct iovec *msg_iov;
368 socklen_t msg_controllen;
372 #define sendmsg sendmsg_w32
374 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
375 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
377 #endif /* HAVE_WINSOCK */
380 #define putenv rk_putenv
381 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
384 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
386 #define setenv rk_setenv
388 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
391 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
392 #ifndef HAVE_UNSETENV
393 #define unsetenv rk_unsetenv
395 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
398 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
399 #ifndef HAVE_GETUSERSHELL
400 #define getusershell rk_getusershell
401 #define endusershell rk_endusershell
403 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
404 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
407 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
408 #ifndef HAVE_SNPRINTF
409 #define snprintf rk_snprintf
411 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
412 rk_snprintf (char *, size_t, const char *, ...)
413 __attribute__ ((format (printf, 3, 4)));
416 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
417 #ifndef HAVE_VSNPRINTF
418 #define vsnprintf rk_vsnprintf
420 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
421 rk_vsnprintf (char *, size_t, const char *, va_list)
422 __attribute__((format (printf, 3, 0)));
425 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
426 #ifndef HAVE_ASPRINTF
427 #define asprintf rk_asprintf
429 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
430 rk_asprintf (char **, const char *, ...)
431 __attribute__ ((format (printf, 2, 3)));
434 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
435 #ifndef HAVE_VASPRINTF
436 #define vasprintf rk_vasprintf
438 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
439 rk_vasprintf (char **, const char *, va_list)
440 __attribute__((format (printf, 2, 0)));
443 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
444 #ifndef HAVE_ASNPRINTF
445 #define asnprintf rk_asnprintf
447 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
448 rk_asnprintf (char **, size_t, const char *, ...)
449 __attribute__ ((format (printf, 3, 4)));
452 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
453 #ifndef HAVE_VASNPRINTF
454 #define vasnprintf rk_vasnprintf
456 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
457 vasnprintf (char **, size_t, const char *, va_list)
458 __attribute__((format (printf, 3, 0)));
462 #define strdup rk_strdup
463 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
466 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
468 #define strndup rk_strndup
470 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
474 #define strlwr rk_strlwr
475 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
479 #define strnlen rk_strnlen
480 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
483 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
485 #define strsep rk_strsep
487 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
490 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
491 #ifndef HAVE_STRSEP_COPY
492 #define strsep_copy rk_strsep_copy
494 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
497 #ifndef HAVE_STRCASECMP
498 #define strcasecmp rk_strcasecmp
499 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
502 #ifdef NEED_FCLOSE_PROTO
503 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
506 #ifdef NEED_STRTOK_R_PROTO
507 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
511 #define strupr rk_strupr
512 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
516 #define strlcpy rk_strlcpy
517 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
521 #define strlcat rk_strlcat
522 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
525 #ifndef HAVE_GETDTABLESIZE
526 #define getdtablesize rk_getdtablesize
527 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
530 #if !defined(HAVE_STRERROR) && !defined(strerror)
531 #define strerror rk_strerror
532 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
535 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
536 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
538 #define rk_strerror_r strerror_r
541 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
542 #ifndef HAVE_HSTRERROR
543 #define hstrerror rk_hstrerror
545 /* This causes a fatal error under Psoriasis */
547 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
551 #if !HAVE_DECL_H_ERRNO
555 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
556 #ifndef HAVE_INET_ATON
557 #define inet_aton rk_inet_aton
559 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
562 #ifndef HAVE_INET_NTOP
563 #define inet_ntop rk_inet_ntop
564 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
565 inet_ntop(int af, const void *src, char *dst, size_t size);
568 #ifndef HAVE_INET_PTON
569 #define inet_pton rk_inet_pton
570 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
571 inet_pton(int, const char *, void *);
575 #define getcwd rk_getcwd
576 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
581 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
582 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
585 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
588 #define seteuid rk_seteuid
589 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
593 #define setegid rk_setegid
594 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
598 #define lstat rk_lstat
599 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
602 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
604 #define mkstemp rk_mkstemp
606 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
610 #define cgetent rk_cgetent
611 #define cgetstr rk_cgetstr
612 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
613 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
616 #ifndef HAVE_INITGROUPS
617 #define initgroups rk_initgroups
618 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
622 #define fchown rk_fchown
623 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
626 #ifdef RENAME_DOES_NOT_UNLINK
627 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
629 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
632 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
634 #define daemon rk_daemon
636 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
640 #define chown rk_chown
641 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
646 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
647 rcmd(char **, unsigned short, const char *,
648 const char *, const char *, int *);
651 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
653 #define innetgr rk_innetgr
655 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
656 const char*, const char*);
659 #ifndef HAVE_IRUSEROK
660 #define iruserok rk_iruserok
661 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
662 const char *, const char *);
665 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
666 #ifndef HAVE_GETHOSTNAME
667 #define gethostname rk_gethostname
669 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
673 #define writev rk_writev
674 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
675 writev(int, const struct iovec *, int);
679 #define readv rk_readv
680 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
681 readv(int, const struct iovec *, int);
686 #define pidfile(x) ((void) 0)
688 #define pidfile rk_pidfile
689 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
694 #define bswap32 rk_bswap32
695 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
699 #define bswap16 rk_bswap16
700 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
705 #define LOCK_SH 1 /* Shared lock */
708 #define LOCK_EX 2 /* Exclusive lock */
711 #define LOCK_NB 4 /* Don't block when locking */
714 #define LOCK_UN 8 /* Unlock */
717 #define flock(_x,_y) rk_flock(_x,_y)
718 int rk_flock(int fd, int operation);
719 #endif /* HAVE_FLOCK */
722 #ifdef HAVE_DIR_DD_FD
723 #define dirfd(x) ((x)->dd_fd)
725 #ifndef _WIN32 /* Windows code never calls dirfd */
726 #error Missing dirfd() and ->dd_fd
731 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
733 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
735 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
737 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
739 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
741 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
742 roken_vmconcat (char **, size_t, va_list);
744 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
745 net_write (rk_socket_t, const void *, size_t);
747 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
748 net_read (rk_socket_t, void *, size_t);
750 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
753 #ifndef HAVE_STRUCT_WINSIZE
755 unsigned short ws_row, ws_col;
756 unsigned short ws_xpixel, ws_ypixel;
760 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
763 #define vsyslog rk_vsyslog
764 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
768 #define getopt rk_getopt
769 #define optarg rk_optarg
770 #define optind rk_optind
771 #define opterr rk_opterr
772 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
773 getopt(int nargc, char * const *nargv, const char *ostr);
776 #if !HAVE_DECL_OPTARG
777 ROKEN_LIB_VARIABLE extern char *optarg;
779 #if !HAVE_DECL_OPTIND
780 ROKEN_LIB_VARIABLE extern int optind;
782 #if !HAVE_DECL_OPTERR
783 ROKEN_LIB_VARIABLE extern int opterr;
786 #ifndef HAVE_GETIPNODEBYNAME
787 #define getipnodebyname rk_getipnodebyname
788 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
789 getipnodebyname (const char *, int, int, int *);
792 #ifndef HAVE_GETIPNODEBYADDR
793 #define getipnodebyaddr rk_getipnodebyaddr
794 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
795 getipnodebyaddr (const void *, size_t, int, int *);
798 #ifndef HAVE_FREEHOSTENT
799 #define freehostent rk_freehostent
800 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
801 freehostent (struct hostent *);
804 #ifndef HAVE_COPYHOSTENT
805 #define copyhostent rk_copyhostent
806 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
807 copyhostent (const struct hostent *);
810 #ifndef HAVE_SOCKLEN_T
811 typedef int socklen_t;
814 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
816 #ifndef HAVE_SA_FAMILY_T
817 typedef unsigned short sa_family_t;
821 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
823 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
826 #define _SS_ALIGNSIZE sizeof(unsigned long)
828 #if HAVE_STRUCT_SOCKADDR_SA_LEN
830 typedef unsigned char roken_sa_family_t;
832 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
833 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
835 struct sockaddr_storage {
836 unsigned char ss_len;
837 roken_sa_family_t ss_family;
838 char __ss_pad1[_SS_PAD1SIZE];
839 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
842 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
844 typedef unsigned short roken_sa_family_t;
846 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
847 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
849 struct sockaddr_storage {
850 roken_sa_family_t ss_family;
851 char __ss_pad1[_SS_PAD1SIZE];
852 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
855 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
857 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
859 #ifndef HAVE_STRUCT_ADDRINFO
867 struct sockaddr *ai_addr;
868 struct addrinfo *ai_next;
872 #ifndef HAVE_GETADDRINFO
873 #define getaddrinfo rk_getaddrinfo
874 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
875 getaddrinfo(const char *,
877 const struct addrinfo *,
881 #ifndef HAVE_GETNAMEINFO
882 #define getnameinfo rk_getnameinfo
883 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
884 getnameinfo(const struct sockaddr *, socklen_t,
890 #ifndef HAVE_FREEADDRINFO
891 #define freeaddrinfo rk_freeaddrinfo
892 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
893 freeaddrinfo(struct addrinfo *);
896 #ifndef HAVE_GAI_STRERROR
897 #define gai_strerror rk_gai_strerror
898 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
904 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
905 sleep(unsigned int seconds);
909 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
910 getnameinfo_verified(const struct sockaddr *, socklen_t,
915 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
916 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
917 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
918 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
920 #ifndef HAVE_STRFTIME
921 #define strftime rk_strftime
922 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
923 strftime (char *, size_t, const char *, const struct tm *);
926 #ifndef HAVE_STRPTIME
927 #define strptime rk_strptime
928 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
929 strptime (const char *, const char *, struct tm *);
932 #ifndef HAVE_GETTIMEOFDAY
933 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
934 gettimeofday (struct timeval *, void *);
938 #define emalloc rk_emalloc
939 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
942 #define ecalloc rk_ecalloc
943 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
945 #ifndef HAVE_EREALLOC
946 #define erealloc rk_erealloc
947 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
950 #define estrdup rk_estrdup
951 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
958 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
959 roken_gethostby_setup(const char*, const char*);
960 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
961 roken_gethostbyname(const char*);
962 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
963 roken_gethostbyaddr(const void*, size_t, int);
965 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
966 #define roken_getservbyname(x,y) getservbyname(x,y)
968 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
971 #ifdef OPENLOG_PROTO_COMPATIBLE
972 #define roken_openlog(a,b,c) openlog(a,b,c)
974 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
977 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
978 #define roken_getsockname(a,b,c) getsockname(a,b,c)
980 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
983 #ifndef HAVE_SETPROGNAME
984 #define setprogname rk_setprogname
985 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
988 #ifndef HAVE_GETPROGNAME
989 #define getprogname rk_getprogname
990 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
993 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
994 extern const char *__progname;
997 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
998 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1000 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1001 mini_inetd (int, rk_socket_t *);
1003 #ifndef HAVE_LOCALTIME_R
1004 #define localtime_r rk_localtime_r
1005 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1006 localtime_r(const time_t *, struct tm *);
1009 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1010 #ifndef HAVE_STRSVIS
1011 #define strsvis rk_strsvis
1013 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1014 strsvis(char *, const char *, int, const char *);
1017 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1018 #ifndef HAVE_STRSVISX
1019 #define strsvisx rk_strsvisx
1021 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1022 strsvisx(char *, const char *, size_t, int, const char *);
1025 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1026 #ifndef HAVE_STRUNVIS
1027 #define strunvis rk_strunvis
1029 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1030 strunvis(char *, const char *);
1033 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1035 #define strvis rk_strvis
1037 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1038 strvis(char *, const char *, int);
1041 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1042 #ifndef HAVE_STRVISX
1043 #define strvisx rk_strvisx
1045 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1046 strvisx(char *, const char *, size_t, int);
1049 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1051 #define svis rk_svis
1053 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1054 svis(char *, int, int, int, const char *);
1057 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1059 #define unvis rk_unvis
1061 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1062 unvis(char *, int, int *, int);
1065 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1069 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1070 vis(char *, int, int, int);
1073 #if !defined(HAVE_CLOSEFROM)
1074 #define closefrom rk_closefrom
1075 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1079 #if !defined(HAVE_TIMEGM)
1080 #define timegm rk_timegm
1081 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1082 rk_timegm(struct tm *tm);
1086 #define qsort rk_qsort
1088 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1091 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1093 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1094 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1097 #ifdef SOCKET_WRAPPER_REPLACE
1098 #include <socket_wrapper.h>