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_FUNCTION
47 #define ROKEN_LIB_CALL __cdecl
49 #define ROKEN_LIB_FUNCTION
50 #define ROKEN_LIB_CALL
55 /* Declarations for Microsoft Windows */
61 * error codes for inet_ntop/inet_pton
63 #define EAFNOSUPPORT WSAEAFNOSUPPORT
65 typedef SOCKET rk_socket_t;
67 #define rk_closesocket(x) closesocket(x)
68 #define rk_INVALID_SOCKET INVALID_SOCKET
69 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
70 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
71 #define rk_SOCK_ERRNO WSAGetLastError()
73 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
75 #define ETIMEDOUT WSAETIMEDOUT
76 #define EWOULDBLOCK WSAEWOULDBLOCK
77 #define ENOTSOCK WSAENOTSOCK
79 #define rk_SOCK_INIT() rk_WSAStartup()
80 #define rk_SOCK_EXIT() rk_WSACleanup()
82 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
83 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
85 #else /* not WinSock */
87 typedef int rk_socket_t;
89 #define rk_closesocket(x) close(x)
90 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
91 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
92 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
93 #define rk_SOCK_ERRNO errno
94 #define rk_INVALID_SOCKET (-1)
96 #define rk_SOCK_INIT() 0
97 #define rk_SOCK_EXIT() do { } while(0)
102 /* Declarations for Microsoft Visual C runtime on Windows */
108 #ifndef __BIT_TYPES_DEFINED__
109 #define __BIT_TYPES_DEFINED__
111 typedef __int8 int8_t;
112 typedef __int16 int16_t;
113 typedef __int32 int32_t;
114 typedef __int64 int64_t;
115 typedef unsigned __int8 uint8_t;
116 typedef unsigned __int16 uint16_t;
117 typedef unsigned __int32 uint32_t;
118 typedef unsigned __int64 uint64_t;
119 typedef uint8_t u_int8_t;
120 typedef uint16_t u_int16_t;
121 typedef uint32_t u_int32_t;
122 typedef uint64_t u_int64_t;
124 #endif /* __BIT_TYPES_DEFINED__ */
126 #define UNREACHABLE(x) x
127 #define UNUSED_ARGUMENT(x) ((void) x)
129 #define RETSIGTYPE void
131 #define VOID_RETSIGTYPE 1
133 #ifdef VOID_RETSIGTYPE
134 #define SIGRETURN(x) return
136 #define SIGRETURN(x) return (RETSIGTYPE)(x)
143 typedef unsigned int gid_t;
145 typedef unsigned int uid_t;
147 typedef unsigned short mode_t;
152 #define inline __inline
157 #define UNREACHABLE(x)
158 #define UNUSED_ARGUMENT(x)
166 #ifdef HAVE_SYS_PARAM_H
167 #include <sys/param.h>
169 #ifdef HAVE_INTTYPES_H
170 #include <inttypes.h>
172 #ifdef HAVE_SYS_TYPES_H
173 #include <sys/types.h>
175 #ifdef HAVE_SYS_BITYPES_H
176 #include <sys/bitypes.h>
178 #ifdef HAVE_BIND_BITYPES_H
179 #include <bind/bitypes.h>
181 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
182 #include <netinet/in6_machtypes.h>
187 #ifdef HAVE_SYS_SOCKET_H
188 #include <sys/socket.h>
190 #ifdef HAVE_SYS_UIO_H
196 #ifdef HAVE_SYS_STAT_H
197 #include <sys/stat.h>
199 #ifdef HAVE_NETINET_IN_H
200 #include <netinet/in.h>
202 #ifdef HAVE_NETINET_IN6_H
203 #include <netinet/in6.h>
205 #ifdef HAVE_NETINET6_IN6_H
206 #include <netinet6/in6.h>
208 #ifdef HAVE_ARPA_INET_H
209 #include <arpa/inet.h>
214 #ifdef HAVE_ARPA_NAMESER_H
215 #include <arpa/nameser.h>
230 #ifdef HAVE_TERMIOS_H
233 #ifdef HAVE_SYS_IOCTL_H
234 #include <sys/ioctl.h>
236 #ifdef TIME_WITH_SYS_TIME
237 #include <sys/time.h>
239 #elif defined(HAVE_SYS_TIME_H)
240 #include <sys/time.h>
245 #ifdef HAVE_WS2TCPIP_H
246 #include <ws2tcpip.h>
257 #ifdef BACKSLASH_PATH_DELIM
258 #define rk_PATH_DELIM '\\'
263 typedef __int64 ssize_t;
269 #include <roken-common.h>
273 #ifdef HAVE_UINTPTR_T
274 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
276 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
279 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
280 #define setsid _setsid
284 /* Additional macros for Visual C/C++ runtime */
288 #define getpid _getpid
294 #define fsync _commit
296 /* The MSVC implementation of snprintf is not C99 compliant. */
297 #define snprintf rk_snprintf
298 #define vsnprintf rk_vsnprintf
299 #define vasnprintf rk_vasnprintf
300 #define vasprintf rk_vasprintf
301 #define asnprintf rk_asnprintf
302 #define asprintf rk_asprintf
304 #define _PIPE_BUFFER_SZ 8192
305 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
307 #define ftruncate(fd, sz) _chsize((fd), (sz))
309 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
310 rk_snprintf (char *str, size_t sz, const char *format, ...);
312 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
313 rk_asprintf (char **ret, const char *format, ...);
315 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
316 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
318 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
319 rk_vasprintf (char **ret, const char *format, va_list args);
321 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
322 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
324 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
325 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
327 /* missing stat.h predicates */
329 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
331 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
333 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
335 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
337 /* The following are not implemented:
344 #endif /* _MSC_VER */
348 /* While we are at it, define WinSock specific scatter gather socket
351 #define iovec _WSABUF
357 socklen_t msg_namelen;
358 struct iovec *msg_iov;
361 socklen_t msg_controllen;
365 #define sendmsg sendmsg_w32
367 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
368 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
370 #endif /* HAVE_WINSOCK */
373 #define putenv rk_putenv
374 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
377 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
379 #define setenv rk_setenv
381 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
384 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
385 #ifndef HAVE_UNSETENV
386 #define unsetenv rk_unsetenv
388 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
391 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
392 #ifndef HAVE_GETUSERSHELL
393 #define getusershell rk_getusershell
394 #define endusershell rk_endusershell
396 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
397 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
400 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
401 #ifndef HAVE_SNPRINTF
402 #define snprintf rk_snprintf
404 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
405 rk_snprintf (char *, size_t, const char *, ...)
406 __attribute__ ((format (printf, 3, 4)));
409 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
410 #ifndef HAVE_VSNPRINTF
411 #define vsnprintf rk_vsnprintf
413 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
414 rk_vsnprintf (char *, size_t, const char *, va_list)
415 __attribute__((format (printf, 3, 0)));
418 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
419 #ifndef HAVE_ASPRINTF
420 #define asprintf rk_asprintf
422 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
423 rk_asprintf (char **, const char *, ...)
424 __attribute__ ((format (printf, 2, 3)));
427 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
428 #ifndef HAVE_VASPRINTF
429 #define vasprintf rk_vasprintf
431 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
432 rk_vasprintf (char **, const char *, va_list)
433 __attribute__((format (printf, 2, 0)));
436 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
437 #ifndef HAVE_ASNPRINTF
438 #define asnprintf rk_asnprintf
440 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
441 rk_asnprintf (char **, size_t, const char *, ...)
442 __attribute__ ((format (printf, 3, 4)));
445 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
446 #ifndef HAVE_VASNPRINTF
447 #define vasnprintf rk_vasnprintf
449 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
450 vasnprintf (char **, size_t, const char *, va_list)
451 __attribute__((format (printf, 3, 0)));
455 #define strdup rk_strdup
456 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
459 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
461 #define strndup rk_strndup
463 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
467 #define strlwr rk_strlwr
468 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
472 #define strnlen rk_strnlen
473 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
476 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
478 #define strsep rk_strsep
480 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
483 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
484 #ifndef HAVE_STRSEP_COPY
485 #define strsep_copy rk_strsep_copy
487 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
490 #ifndef HAVE_STRCASECMP
491 #define strcasecmp rk_strcasecmp
492 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
495 #ifdef NEED_FCLOSE_PROTO
496 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
499 #ifdef NEED_STRTOK_R_PROTO
500 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
504 #define strupr rk_strupr
505 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
509 #define strlcpy rk_strlcpy
510 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
514 #define strlcat rk_strlcat
515 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
518 #ifndef HAVE_GETDTABLESIZE
519 #define getdtablesize rk_getdtablesize
520 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
523 #if !defined(HAVE_STRERROR) && !defined(strerror)
524 #define strerror rk_strerror
525 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
528 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
529 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
531 #define rk_strerror_r strerror_r
534 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
535 #ifndef HAVE_HSTRERROR
536 #define hstrerror rk_hstrerror
538 /* This causes a fatal error under Psoriasis */
540 const char * ROKEN_LIB_FUNCTION hstrerror(int);
541 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
545 #if !HAVE_DECL_H_ERRNO
549 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
550 #ifndef HAVE_INET_ATON
551 #define inet_aton rk_inet_aton
553 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
556 #ifndef HAVE_INET_NTOP
557 #define inet_ntop rk_inet_ntop
558 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
559 inet_ntop(int af, const void *src, char *dst, size_t size);
562 #ifndef HAVE_INET_PTON
563 #define inet_pton rk_inet_pton
564 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
565 inet_pton(int, const char *, void *);
569 #define getcwd rk_getcwd
570 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
575 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
576 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
579 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
582 #define seteuid rk_seteuid
583 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
587 #define setegid rk_setegid
588 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
592 #define lstat rk_lstat
593 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
596 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
598 #define mkstemp rk_mkstemp
600 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
604 #define cgetent rk_cgetent
605 #define cgetstr rk_cgetstr
606 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
607 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
610 #ifndef HAVE_INITGROUPS
611 #define initgroups rk_initgroups
612 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
616 #define fchown rk_fchown
617 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
620 #ifdef RENAME_DOES_NOT_UNLINK
621 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
623 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
626 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
628 #define daemon rk_daemon
630 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
634 #define chown rk_chown
635 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
640 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
641 rcmd(char **, unsigned short, const char *,
642 const char *, const char *, int *);
645 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
647 #define innetgr rk_innetgr
649 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
650 const char*, const char*);
653 #ifndef HAVE_IRUSEROK
654 #define iruserok rk_iruserok
655 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
656 const char *, const char *);
659 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
660 #ifndef HAVE_GETHOSTNAME
661 #define gethostname rk_gethostname
663 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
667 #define writev rk_writev
668 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
669 writev(int, const struct iovec *, int);
673 #define readv rk_readv
674 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
675 readv(int, const struct iovec *, int);
680 #define pidfile(x) ((void) 0)
682 #define pidfile rk_pidfile
683 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
688 #define bswap32 rk_bswap32
689 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
693 #define bswap16 rk_bswap16
694 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
699 #define LOCK_SH 1 /* Shared lock */
702 #define LOCK_EX 2 /* Exclusive lock */
705 #define LOCK_NB 4 /* Don't block when locking */
708 #define LOCK_UN 8 /* Unlock */
711 #define flock(_x,_y) rk_flock(_x,_y)
712 int rk_flock(int fd, int operation);
713 #endif /* HAVE_FLOCK */
716 #ifdef HAVE_DIR_DD_FD
717 #define dirfd(x) ((x)->dd_fd)
719 #ifndef _WIN32 /* Windows code never calls dirfd */
720 #error Missing dirfd() and ->dd_fd
725 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
727 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
729 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
731 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
733 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
735 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
736 roken_vmconcat (char **, size_t, va_list);
738 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
739 net_write (rk_socket_t, const void *, size_t);
741 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
742 net_read (rk_socket_t, void *, size_t);
744 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
747 #ifndef HAVE_STRUCT_WINSIZE
749 unsigned short ws_row, ws_col;
750 unsigned short ws_xpixel, ws_ypixel;
754 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
757 #define vsyslog rk_vsyslog
758 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
761 #if !HAVE_DECL_OPTARG
764 #if !HAVE_DECL_OPTIND
767 #if !HAVE_DECL_OPTERR
771 #ifndef HAVE_GETIPNODEBYNAME
772 #define getipnodebyname rk_getipnodebyname
773 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
774 getipnodebyname (const char *, int, int, int *);
777 #ifndef HAVE_GETIPNODEBYADDR
778 #define getipnodebyaddr rk_getipnodebyaddr
779 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
780 getipnodebyaddr (const void *, size_t, int, int *);
783 #ifndef HAVE_FREEHOSTENT
784 #define freehostent rk_freehostent
785 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
786 freehostent (struct hostent *);
789 #ifndef HAVE_COPYHOSTENT
790 #define copyhostent rk_copyhostent
791 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
792 copyhostent (const struct hostent *);
795 #ifndef HAVE_SOCKLEN_T
796 typedef int socklen_t;
799 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
801 #ifndef HAVE_SA_FAMILY_T
802 typedef unsigned short sa_family_t;
806 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
808 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
811 #define _SS_ALIGNSIZE sizeof(unsigned long)
813 #if HAVE_STRUCT_SOCKADDR_SA_LEN
815 typedef unsigned char roken_sa_family_t;
817 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
818 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
820 struct sockaddr_storage {
821 unsigned char ss_len;
822 roken_sa_family_t ss_family;
823 char __ss_pad1[_SS_PAD1SIZE];
824 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
827 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
829 typedef unsigned short roken_sa_family_t;
831 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
832 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
834 struct sockaddr_storage {
835 roken_sa_family_t ss_family;
836 char __ss_pad1[_SS_PAD1SIZE];
837 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
840 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
842 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
844 #ifndef HAVE_STRUCT_ADDRINFO
852 struct sockaddr *ai_addr;
853 struct addrinfo *ai_next;
857 #ifndef HAVE_GETADDRINFO
858 #define getaddrinfo rk_getaddrinfo
859 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
860 getaddrinfo(const char *,
862 const struct addrinfo *,
866 #ifndef HAVE_GETNAMEINFO
867 #define getnameinfo rk_getnameinfo
868 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
869 getnameinfo(const struct sockaddr *, socklen_t,
875 #ifndef HAVE_FREEADDRINFO
876 #define freeaddrinfo rk_freeaddrinfo
877 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
878 freeaddrinfo(struct addrinfo *);
881 #ifndef HAVE_GAI_STRERROR
882 #define gai_strerror rk_gai_strerror
883 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
889 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
890 sleep(unsigned int seconds);
894 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
895 getnameinfo_verified(const struct sockaddr *, socklen_t,
900 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
901 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
902 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
903 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
905 #ifndef HAVE_STRFTIME
906 #define strftime rk_strftime
907 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
908 strftime (char *, size_t, const char *, const struct tm *);
911 #ifndef HAVE_STRPTIME
912 #define strptime rk_strptime
913 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
914 strptime (const char *, const char *, struct tm *);
917 #ifndef HAVE_GETTIMEOFDAY
918 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
919 gettimeofday (struct timeval *, void *);
923 #define emalloc rk_emalloc
924 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
927 #define ecalloc rk_ecalloc
928 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
930 #ifndef HAVE_EREALLOC
931 #define erealloc rk_erealloc
932 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
935 #define estrdup rk_estrdup
936 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
943 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
944 roken_gethostby_setup(const char*, const char*);
945 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
946 roken_gethostbyname(const char*);
947 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
948 roken_gethostbyaddr(const void*, size_t, int);
950 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
951 #define roken_getservbyname(x,y) getservbyname(x,y)
953 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
956 #ifdef OPENLOG_PROTO_COMPATIBLE
957 #define roken_openlog(a,b,c) openlog(a,b,c)
959 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
962 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
963 #define roken_getsockname(a,b,c) getsockname(a,b,c)
965 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
968 #ifndef HAVE_SETPROGNAME
969 #define setprogname rk_setprogname
970 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
973 #ifndef HAVE_GETPROGNAME
974 #define getprogname rk_getprogname
975 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
978 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
979 extern const char *__progname;
982 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
983 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
985 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
986 mini_inetd (int, rk_socket_t *);
988 #ifndef HAVE_LOCALTIME_R
989 #define localtime_r rk_localtime_r
990 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
991 localtime_r(const time_t *, struct tm *);
994 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
996 #define strsvis rk_strsvis
998 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
999 strsvis(char *, const char *, int, const char *);
1002 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1003 #ifndef HAVE_STRSVISX
1004 #define strsvisx rk_strsvisx
1006 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1007 strsvisx(char *, const char *, size_t, int, const char *);
1010 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1011 #ifndef HAVE_STRUNVIS
1012 #define strunvis rk_strunvis
1014 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1015 strunvis(char *, const char *);
1018 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1020 #define strvis rk_strvis
1022 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1023 strvis(char *, const char *, int);
1026 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1027 #ifndef HAVE_STRVISX
1028 #define strvisx rk_strvisx
1030 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1031 strvisx(char *, const char *, size_t, int);
1034 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1036 #define svis rk_svis
1038 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1039 svis(char *, int, int, int, const char *);
1042 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1044 #define unvis rk_unvis
1046 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1047 unvis(char *, int, int *, int);
1050 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1054 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1055 vis(char *, int, int, int);
1058 #if !defined(HAVE_CLOSEFROM)
1059 #define closefrom rk_closefrom
1060 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1064 #if !defined(HAVE_TIMEGM)
1065 #define timegm rk_timegm
1066 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1067 rk_timegm(struct tm *tm);
1071 #define qsort rk_qsort
1073 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1076 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1078 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1079 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1082 #ifdef SOCKET_WRAPPER_REPLACE
1083 #include <socket_wrapper.h>