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)
108 #ifndef IN_LOOPBACKNET
109 #define IN_LOOPBACKNET 127
113 /* Declarations for Microsoft Visual C runtime on Windows */
119 #ifndef __BIT_TYPES_DEFINED__
120 #define __BIT_TYPES_DEFINED__
122 typedef __int8
int8_t;
123 typedef __int16
int16_t;
124 typedef __int32
int32_t;
125 typedef __int64
int64_t;
126 typedef unsigned __int8
uint8_t;
127 typedef unsigned __int16
uint16_t;
128 typedef unsigned __int32
uint32_t;
129 typedef unsigned __int64
uint64_t;
130 typedef uint8_t u_int8_t
;
131 typedef uint16_t u_int16_t
;
132 typedef uint32_t u_int32_t
;
133 typedef uint64_t u_int64_t
;
135 #endif /* __BIT_TYPES_DEFINED__ */
137 #define UNREACHABLE(x) x
138 #define UNUSED_ARGUMENT(x) ((void) x)
140 #define RETSIGTYPE void
142 #define VOID_RETSIGTYPE 1
144 #ifdef VOID_RETSIGTYPE
145 #define SIGRETURN(x) return
147 #define SIGRETURN(x) return (RETSIGTYPE)(x)
154 typedef unsigned int gid_t
;
156 typedef unsigned int uid_t
;
158 typedef unsigned short mode_t
;
163 #define inline __inline
168 #define UNREACHABLE(x)
169 #define UNUSED_ARGUMENT(x)
177 #ifdef HAVE_SYS_PARAM_H
178 #include <sys/param.h>
180 #ifdef HAVE_INTTYPES_H
181 #include <inttypes.h>
183 #ifdef HAVE_SYS_TYPES_H
184 #include <sys/types.h>
186 #ifdef HAVE_SYS_BITYPES_H
187 #include <sys/bitypes.h>
189 #ifdef HAVE_BIND_BITYPES_H
190 #include <bind/bitypes.h>
192 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
193 #include <netinet/in6_machtypes.h>
198 #ifdef HAVE_SYS_SOCKET_H
199 #include <sys/socket.h>
201 #ifdef HAVE_SYS_UIO_H
207 #ifdef HAVE_SYS_STAT_H
208 #include <sys/stat.h>
210 #ifdef HAVE_NETINET_IN_H
211 #include <netinet/in.h>
213 #ifdef HAVE_NETINET_IN6_H
214 #include <netinet/in6.h>
216 #ifdef HAVE_NETINET6_IN6_H
217 #include <netinet6/in6.h>
219 #ifdef HAVE_ARPA_INET_H
220 #include <arpa/inet.h>
225 #ifdef HAVE_ARPA_NAMESER_H
226 #include <arpa/nameser.h>
241 #ifdef HAVE_TERMIOS_H
244 #ifdef HAVE_SYS_IOCTL_H
245 #include <sys/ioctl.h>
247 #ifdef TIME_WITH_SYS_TIME
248 #include <sys/time.h>
250 #elif defined(HAVE_SYS_TIME_H)
251 #include <sys/time.h>
264 #ifdef BACKSLASH_PATH_DELIM
265 #define rk_PATH_DELIM '\\'
269 #ifndef SSIZE_T_DEFINED
274 typedef __int64 ssize_t
;
278 #define SSIZE_T_DEFINED
279 #endif /* SSIZE_T_DEFINED */
280 #endif /* HAVE_SSIZE_T */
282 #include <roken-common.h>
286 #ifdef HAVE_UINTPTR_T
287 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
289 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
292 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
293 #define setsid _setsid
297 /* Additional macros for Visual C/C++ runtime */
301 #define getpid _getpid
307 #define fsync _commit
309 /* The MSVC implementation of snprintf is not C99 compliant. */
310 #define snprintf rk_snprintf
311 #define vsnprintf rk_vsnprintf
312 #define vasnprintf rk_vasnprintf
313 #define vasprintf rk_vasprintf
314 #define asnprintf rk_asnprintf
315 #define asprintf rk_asprintf
317 #define _PIPE_BUFFER_SZ 8192
318 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
320 #define ftruncate(fd, sz) _chsize((fd), (sz))
322 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
323 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
325 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
326 rk_asprintf (char **ret
, const char *format
, ...);
328 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
329 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
331 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
332 rk_vasprintf (char **ret
, const char *format
, va_list args
);
334 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
335 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
337 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
338 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
340 /* missing stat.h predicates */
342 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
344 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
346 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
348 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
350 /* The following are not implemented:
357 #endif /* _MSC_VER */
361 /* While we are at it, define WinSock specific scatter gather socket
364 #define iovec _WSABUF
370 socklen_t msg_namelen
;
371 struct iovec
*msg_iov
;
374 socklen_t msg_controllen
;
378 #define sendmsg sendmsg_w32
380 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
381 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
383 #endif /* HAVE_WINSOCK */
386 #define putenv rk_putenv
387 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
390 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
392 #define setenv rk_setenv
394 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
397 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
398 #ifndef HAVE_UNSETENV
399 #define unsetenv rk_unsetenv
401 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
404 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
405 #ifndef HAVE_GETUSERSHELL
406 #define getusershell rk_getusershell
407 #define endusershell rk_endusershell
409 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
410 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
413 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
414 #ifndef HAVE_SNPRINTF
415 #define snprintf rk_snprintf
417 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
418 rk_snprintf (char *, size_t, const char *, ...)
419 __attribute__ ((format (printf
, 3, 4)));
422 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
423 #ifndef HAVE_VSNPRINTF
424 #define vsnprintf rk_vsnprintf
426 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
427 rk_vsnprintf (char *, size_t, const char *, va_list)
428 __attribute__((format (printf
, 3, 0)));
431 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
432 #ifndef HAVE_ASPRINTF
433 #define asprintf rk_asprintf
435 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
436 rk_asprintf (char **, const char *, ...)
437 __attribute__ ((format (printf
, 2, 3)));
440 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
441 #ifndef HAVE_VASPRINTF
442 #define vasprintf rk_vasprintf
444 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
445 rk_vasprintf (char **, const char *, va_list)
446 __attribute__((format (printf
, 2, 0)));
449 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
450 #ifndef HAVE_ASNPRINTF
451 #define asnprintf rk_asnprintf
453 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
454 rk_asnprintf (char **, size_t, const char *, ...)
455 __attribute__ ((format (printf
, 3, 4)));
458 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
459 #ifndef HAVE_VASNPRINTF
460 #define vasnprintf rk_vasnprintf
462 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
463 vasnprintf (char **, size_t, const char *, va_list)
464 __attribute__((format (printf
, 3, 0)));
468 #define strdup rk_strdup
469 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
472 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
474 #define strndup rk_strndup
476 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
480 #define strlwr rk_strlwr
481 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
485 #define strnlen rk_strnlen
486 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
489 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
491 #define strsep rk_strsep
493 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
496 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
497 #ifndef HAVE_STRSEP_COPY
498 #define strsep_copy rk_strsep_copy
500 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
503 #ifndef HAVE_STRCASECMP
504 #define strcasecmp rk_strcasecmp
505 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
508 #ifdef NEED_FCLOSE_PROTO
509 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
512 #ifdef NEED_STRTOK_R_PROTO
513 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
517 #define strupr rk_strupr
518 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
522 #define strlcpy rk_strlcpy
523 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
527 #define strlcat rk_strlcat
528 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
531 #ifndef HAVE_GETDTABLESIZE
532 #define getdtablesize rk_getdtablesize
533 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
536 #if !defined(HAVE_STRERROR) && !defined(strerror)
537 #define strerror rk_strerror
538 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
541 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
542 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
544 #define rk_strerror_r strerror_r
547 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
548 #ifndef HAVE_HSTRERROR
549 #define hstrerror rk_hstrerror
551 /* This causes a fatal error under Psoriasis */
553 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
557 #if !HAVE_DECL_H_ERRNO
561 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
562 #ifndef HAVE_INET_ATON
563 #define inet_aton rk_inet_aton
565 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
568 #ifndef HAVE_INET_NTOP
569 #define inet_ntop rk_inet_ntop
570 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
571 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
574 #ifndef HAVE_INET_PTON
575 #define inet_pton rk_inet_pton
576 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
577 inet_pton(int, const char *, void *);
581 #define getcwd rk_getcwd
582 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
587 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
588 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
591 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
594 #define seteuid rk_seteuid
595 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
599 #define setegid rk_setegid
600 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
604 #define lstat rk_lstat
605 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
608 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
610 #define mkstemp rk_mkstemp
612 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
616 #define cgetent rk_cgetent
617 #define cgetstr rk_cgetstr
618 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
619 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
622 #ifndef HAVE_INITGROUPS
623 #define initgroups rk_initgroups
624 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
628 #define fchown rk_fchown
629 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
632 #ifdef RENAME_DOES_NOT_UNLINK
633 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_rename(const char *, const char *);
635 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
638 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
640 #define daemon rk_daemon
642 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
646 #define chown rk_chown
647 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
652 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
653 rcmd(char **, unsigned short, const char *,
654 const char *, const char *, int *);
657 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
659 #define innetgr rk_innetgr
661 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
662 const char*, const char*);
665 #ifndef HAVE_IRUSEROK
666 #define iruserok rk_iruserok
667 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
668 const char *, const char *);
671 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
672 #ifndef HAVE_GETHOSTNAME
673 #define gethostname rk_gethostname
675 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
679 #define writev rk_writev
680 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
681 writev(int, const struct iovec
*, int);
685 #define readv rk_readv
686 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
687 readv(int, const struct iovec
*, int);
692 #define pidfile(x) ((void) 0)
694 #define pidfile rk_pidfile
695 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
700 #define bswap32 rk_bswap32
701 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
705 #define bswap16 rk_bswap16
706 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
711 #define LOCK_SH 1 /* Shared lock */
714 #define LOCK_EX 2 /* Exclusive lock */
717 #define LOCK_NB 4 /* Don't block when locking */
720 #define LOCK_UN 8 /* Unlock */
723 #define flock(_x,_y) rk_flock(_x,_y)
724 int rk_flock(int fd
, int operation
);
725 #endif /* HAVE_FLOCK */
728 #ifdef HAVE_DIR_DD_FD
729 #define dirfd(x) ((x)->dd_fd)
731 #ifndef _WIN32 /* Windows code never calls dirfd */
732 #error Missing dirfd() and ->dd_fd
737 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
739 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
741 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
743 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
745 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
747 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
748 roken_vmconcat (char **, size_t, va_list);
750 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
751 net_write (rk_socket_t
, const void *, size_t);
753 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
754 net_read (rk_socket_t
, void *, size_t);
756 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
759 #ifndef HAVE_STRUCT_WINSIZE
761 unsigned short ws_row
, ws_col
;
762 unsigned short ws_xpixel
, ws_ypixel
;
766 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, int *, int *);
769 #define vsyslog rk_vsyslog
770 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
774 #define getopt rk_getopt
775 #define optarg rk_optarg
776 #define optind rk_optind
777 #define opterr rk_opterr
778 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
779 getopt(int nargc
, char * const *nargv
, const char *ostr
);
782 #if !HAVE_DECL_OPTARG
783 ROKEN_LIB_VARIABLE
extern char *optarg
;
785 #if !HAVE_DECL_OPTIND
786 ROKEN_LIB_VARIABLE
extern int optind
;
788 #if !HAVE_DECL_OPTERR
789 ROKEN_LIB_VARIABLE
extern int opterr
;
792 #ifndef HAVE_GETIPNODEBYNAME
793 #define getipnodebyname rk_getipnodebyname
794 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
795 getipnodebyname (const char *, int, int, int *);
798 #ifndef HAVE_GETIPNODEBYADDR
799 #define getipnodebyaddr rk_getipnodebyaddr
800 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
801 getipnodebyaddr (const void *, size_t, int, int *);
804 #ifndef HAVE_FREEHOSTENT
805 #define freehostent rk_freehostent
806 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
807 freehostent (struct hostent
*);
810 #ifndef HAVE_COPYHOSTENT
811 #define copyhostent rk_copyhostent
812 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
813 copyhostent (const struct hostent
*);
816 #ifndef HAVE_SOCKLEN_T
817 typedef int socklen_t
;
820 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
822 #ifndef HAVE_SA_FAMILY_T
823 typedef unsigned short sa_family_t
;
827 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
829 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
832 #define _SS_ALIGNSIZE sizeof(unsigned long)
834 #if HAVE_STRUCT_SOCKADDR_SA_LEN
836 typedef unsigned char roken_sa_family_t
;
838 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
839 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
841 struct sockaddr_storage
{
842 unsigned char ss_len
;
843 roken_sa_family_t ss_family
;
844 char __ss_pad1
[_SS_PAD1SIZE
];
845 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
848 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
850 typedef unsigned short roken_sa_family_t
;
852 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
853 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
855 struct sockaddr_storage
{
856 roken_sa_family_t ss_family
;
857 char __ss_pad1
[_SS_PAD1SIZE
];
858 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
861 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
863 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
865 #ifndef HAVE_STRUCT_ADDRINFO
873 struct sockaddr
*ai_addr
;
874 struct addrinfo
*ai_next
;
878 #ifndef HAVE_GETADDRINFO
879 #define getaddrinfo rk_getaddrinfo
880 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
881 getaddrinfo(const char *,
883 const struct addrinfo
*,
887 #ifndef HAVE_GETNAMEINFO
888 #define getnameinfo rk_getnameinfo
889 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
890 getnameinfo(const struct sockaddr
*, socklen_t
,
896 #ifndef HAVE_FREEADDRINFO
897 #define freeaddrinfo rk_freeaddrinfo
898 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
899 freeaddrinfo(struct addrinfo
*);
902 #ifndef HAVE_GAI_STRERROR
903 #define gai_strerror rk_gai_strerror
904 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
910 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
911 sleep(unsigned int seconds
);
915 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
916 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
921 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
922 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
923 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
924 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
926 #ifndef HAVE_STRFTIME
927 #define strftime rk_strftime
928 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
929 strftime (char *, size_t, const char *, const struct tm
*);
932 #ifndef HAVE_STRPTIME
933 #define strptime rk_strptime
934 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
935 strptime (const char *, const char *, struct tm
*);
938 #ifndef HAVE_GETTIMEOFDAY
939 #define gettimeofday rk_gettimeofday
940 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
941 gettimeofday (struct timeval
*, void *);
945 #define emalloc rk_emalloc
946 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
949 #define ecalloc rk_ecalloc
950 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
952 #ifndef HAVE_EREALLOC
953 #define erealloc rk_erealloc
954 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
957 #define estrdup rk_estrdup
958 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
965 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
966 roken_gethostby_setup(const char*, const char*);
967 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
968 roken_gethostbyname(const char*);
969 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
970 roken_gethostbyaddr(const void*, size_t, int);
972 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
973 #define roken_getservbyname(x,y) getservbyname(x,y)
975 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
978 #ifdef OPENLOG_PROTO_COMPATIBLE
979 #define roken_openlog(a,b,c) openlog(a,b,c)
981 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
984 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
985 #define roken_getsockname(a,b,c) getsockname(a,b,c)
987 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
990 #ifndef HAVE_SETPROGNAME
991 #define setprogname rk_setprogname
992 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
995 #ifndef HAVE_GETPROGNAME
996 #define getprogname rk_getprogname
997 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
1000 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1001 extern const char *__progname
;
1004 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1005 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
1007 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1008 mini_inetd (int, rk_socket_t
*);
1010 #ifndef HAVE_LOCALTIME_R
1011 #define localtime_r rk_localtime_r
1012 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
1013 localtime_r(const time_t *, struct tm
*);
1016 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1017 #ifndef HAVE_STRSVIS
1018 #define strsvis rk_strsvis
1020 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1021 strsvis(char *, const char *, int, const char *);
1024 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1025 #ifndef HAVE_STRSVISX
1026 #define strsvisx rk_strsvisx
1028 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1029 strsvisx(char *, const char *, size_t, int, const char *);
1032 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1033 #ifndef HAVE_STRUNVIS
1034 #define strunvis rk_strunvis
1036 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1037 strunvis(char *, const char *);
1040 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1042 #define strvis rk_strvis
1044 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1045 strvis(char *, const char *, int);
1048 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1049 #ifndef HAVE_STRVISX
1050 #define strvisx rk_strvisx
1052 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1053 strvisx(char *, const char *, size_t, int);
1056 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1058 #define svis rk_svis
1060 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1061 svis(char *, int, int, int, const char *);
1064 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1066 #define unvis rk_unvis
1068 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1069 unvis(char *, int, int *, int);
1072 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1076 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1077 vis(char *, int, int, int);
1080 #if !defined(HAVE_CLOSEFROM)
1081 #define closefrom rk_closefrom
1082 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1086 #if !defined(HAVE_TIMEGM)
1087 #define timegm rk_timegm
1088 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1089 rk_timegm(struct tm
*tm
);
1093 #define qsort rk_qsort
1095 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1098 #if defined(HAVE_ARC4RANDOM)
1099 #define rk_random() arc4random()
1100 #elif defined(HAVE_RANDOM)
1101 #define rk_random() random()
1103 #define rk_random() rand()
1106 #ifndef HAVE_TDELETE
1107 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1110 #define tfind(a,b,c) rk_tfind(a,b,c)
1112 #ifndef HAVE_TSEARCH
1113 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1116 #define twalk(a,b) rk_twalk(a,b)
1119 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1121 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1122 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1125 #ifdef SOCKET_WRAPPER_REPLACE
1126 #include <socket_wrapper.h>