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
45 #ifndef ROKEN_LIB_FUNCTION
47 # define ROKEN_LIB_CALL __cdecl
48 # ifdef ROKEN_LIB_DYNAMIC
49 # define ROKEN_LIB_FUNCTION __declspec(dllimport)
50 # define ROKEN_LIB_VARIABLE __declspec(dllimport)
52 # define ROKEN_LIB_FUNCTION
53 # define ROKEN_LIB_VARIABLE
56 #define ROKEN_LIB_FUNCTION
57 #define ROKEN_LIB_CALL
58 #define ROKEN_LIB_VARIABLE
63 /* Declarations for Microsoft Windows */
69 * error codes for inet_ntop/inet_pton
71 typedef SOCKET rk_socket_t
;
73 #define rk_closesocket(x) closesocket(x)
74 #define rk_INVALID_SOCKET INVALID_SOCKET
75 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
76 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
77 #define rk_SOCK_ERRNO WSAGetLastError()
79 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_SOCK_IOCTL(SOCKET s
, long cmd
, int * argp
);
81 #define rk_SOCK_INIT() rk_WSAStartup()
82 #define rk_SOCK_EXIT() rk_WSACleanup()
84 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSAStartup(void);
85 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSACleanup(void);
87 #else /* not WinSock */
89 typedef int rk_socket_t
;
91 #define rk_closesocket(x) close(x)
92 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
93 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
94 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
95 #define rk_SOCK_ERRNO errno
96 #define rk_INVALID_SOCKET (-1)
98 #define rk_SOCK_INIT() 0
99 #define rk_SOCK_EXIT() do { } while(0)
103 #ifndef IN_LOOPBACKNET
104 #define IN_LOOPBACKNET 127
108 #ifndef HAVE_STDINT_H
112 /* Declarations for Microsoft Visual C runtime on Windows */
118 #ifndef __BIT_TYPES_DEFINED__
119 #define __BIT_TYPES_DEFINED__
121 typedef __int8
int8_t;
122 typedef __int16
int16_t;
123 typedef __int32
int32_t;
124 typedef __int64
int64_t;
125 typedef unsigned __int8
uint8_t;
126 typedef unsigned __int16
uint16_t;
127 typedef unsigned __int32
uint32_t;
128 typedef unsigned __int64
uint64_t;
129 typedef uint8_t u_int8_t
;
130 typedef uint16_t u_int16_t
;
131 typedef uint32_t u_int32_t
;
132 typedef uint64_t u_int64_t
;
134 #endif /* __BIT_TYPES_DEFINED__ */
136 #define UNREACHABLE(x) x
137 #define UNUSED_ARGUMENT(x) ((void) x)
139 #define RETSIGTYPE void
141 #define VOID_RETSIGTYPE 1
143 #ifdef VOID_RETSIGTYPE
144 #define SIGRETURN(x) return
146 #define SIGRETURN(x) return (RETSIGTYPE)(x)
153 typedef unsigned int gid_t
;
155 typedef unsigned int uid_t
;
157 typedef unsigned short mode_t
;
162 #define inline __inline
167 #define UNREACHABLE(x)
168 #define UNUSED_ARGUMENT(x)
176 #ifdef HAVE_SYS_PARAM_H
177 #include <sys/param.h>
179 #ifdef HAVE_INTTYPES_H
180 #include <inttypes.h>
182 #ifdef HAVE_SYS_TYPES_H
183 #include <sys/types.h>
185 #ifdef HAVE_SYS_BITYPES_H
186 #include <sys/bitypes.h>
188 #ifdef HAVE_BIND_BITYPES_H
189 #include <bind/bitypes.h>
191 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
192 #include <netinet/in6_machtypes.h>
197 #ifdef HAVE_SYS_SOCKET_H
198 #include <sys/socket.h>
200 #ifdef HAVE_SYS_UIO_H
206 #ifdef HAVE_SYS_STAT_H
207 #include <sys/stat.h>
209 #ifdef HAVE_NETINET_IN_H
210 #include <netinet/in.h>
212 #ifdef HAVE_NETINET_IN6_H
213 #include <netinet/in6.h>
215 #ifdef HAVE_NETINET6_IN6_H
216 #include <netinet6/in6.h>
218 #ifdef HAVE_ARPA_INET_H
219 #include <arpa/inet.h>
224 #ifdef HAVE_ARPA_NAMESER_H
225 #include <arpa/nameser.h>
240 #ifdef HAVE_TERMIOS_H
243 #ifdef HAVE_SYS_IOCTL_H
244 #include <sys/ioctl.h>
246 #ifdef TIME_WITH_SYS_TIME
247 #include <sys/time.h>
249 #elif defined(HAVE_SYS_TIME_H)
250 #include <sys/time.h>
267 #ifdef BACKSLASH_PATH_DELIM
268 #define rk_PATH_DELIM '\\'
272 #ifndef SSIZE_T_DEFINED
277 typedef __int64 ssize_t
;
281 #define SSIZE_T_DEFINED
282 #endif /* SSIZE_T_DEFINED */
283 #endif /* HAVE_SSIZE_T */
285 #include <roken-common.h>
289 #ifdef HAVE_UINTPTR_T
290 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
292 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
295 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
296 #define setsid _setsid
300 /* Additional macros for Visual C/C++ runtime */
304 #define getpid _getpid
310 #define fsync _commit
312 /* The MSVC implementation of snprintf is not C99 compliant. */
313 #define snprintf rk_snprintf
314 #define vsnprintf rk_vsnprintf
315 #define vasnprintf rk_vasnprintf
316 #define vasprintf rk_vasprintf
317 #define asnprintf rk_asnprintf
318 #define asprintf rk_asprintf
320 #define _PIPE_BUFFER_SZ 8192
321 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
323 #define ftruncate(fd, sz) _chsize((fd), (sz))
325 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
326 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
328 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
329 rk_asprintf (char **ret
, const char *format
, ...);
331 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
332 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
334 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
335 rk_vasprintf (char **ret
, const char *format
, va_list args
);
337 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
338 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
340 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
341 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
343 /* missing stat.h predicates */
345 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
347 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
349 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
351 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
353 /* The following are not implemented:
360 /* The following symbolic constants are provided for rk_mkdir mode */
362 #define S_IRWXU 00700 /* user (file owner) has read, write and execute permission */
363 #define S_IRUSR 00400 /* user has read permission */
364 #define S_IWUSR 00200 /* user has write permission */
365 #define S_IXUSR 00100 /* user has execute permission */
366 #define S_IRWXG 00070 /* group has read, write and execute permission */
367 #define S_IRGRP 00040 /* group has read permission */
368 #define S_IWGRP 00020 /* group has write permission */
369 #define S_IXGRP 00010 /* group has execute permission */
370 #define S_IRWXO 00007 /* others have read, write and execute permission */
371 #define S_IROTH 00004 /* others have read permission */
372 #define S_IWOTH 00002 /* others have write permission */
373 #define S_IXOTH 00001 /* others have execute permission */
375 #if !defined(ROKEN_NO_DEFINE_ALLOCATORS)
376 /* Ensure that a common memory allocator is used by all */
377 #define calloc rk_calloc
379 #define malloc rk_malloc
380 #define realloc rk_realloc
381 #define strdup rk_strdup
382 #define wcsdup rk_wcsdup
385 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
386 rk_calloc(size_t, size_t);
388 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
391 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
394 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
395 rk_realloc(void *, size_t);
397 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
398 rk_strdup(const char *);
400 ROKEN_LIB_FUNCTION
unsigned short * ROKEN_LIB_CALL
401 rk_wcsdup(const unsigned short *);
403 #endif /* _MSC_VER */
407 /* While we are at it, define WinSock specific scatter gather socket
410 #define iovec _WSABUF
416 socklen_t msg_namelen
;
417 struct iovec
*msg_iov
;
420 socklen_t msg_controllen
;
424 #define sendmsg sendmsg_w32
426 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
427 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
429 #endif /* HAVE_WINSOCK */
432 #define putenv rk_putenv
433 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
436 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
438 #define setenv rk_setenv
440 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
443 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
444 #ifndef HAVE_UNSETENV
445 #define unsetenv rk_unsetenv
447 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
450 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
451 #ifndef HAVE_GETUSERSHELL
452 #define getusershell rk_getusershell
453 #define endusershell rk_endusershell
455 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
456 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
459 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
460 #ifndef HAVE_SNPRINTF
461 #define snprintf rk_snprintf
463 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
464 rk_snprintf (char *, size_t, const char *, ...)
465 __attribute__ ((format (printf
, 3, 4)));
468 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
469 #ifndef HAVE_VSNPRINTF
470 #define vsnprintf rk_vsnprintf
472 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
473 rk_vsnprintf (char *, size_t, const char *, va_list)
474 __attribute__((format (printf
, 3, 0)));
477 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
478 #ifndef HAVE_ASPRINTF
479 #define asprintf rk_asprintf
481 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
482 rk_asprintf (char **, const char *, ...)
483 __attribute__ ((format (printf
, 2, 3)));
486 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
487 #ifndef HAVE_VASPRINTF
488 #define vasprintf rk_vasprintf
490 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
491 rk_vasprintf (char **, const char *, va_list)
492 __attribute__((format (printf
, 2, 0)));
495 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
496 #ifndef HAVE_ASNPRINTF
497 #define asnprintf rk_asnprintf
499 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
500 rk_asnprintf (char **, size_t, const char *, ...)
501 __attribute__ ((format (printf
, 3, 4)));
504 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
505 #ifndef HAVE_VASNPRINTF
506 #define vasnprintf rk_vasnprintf
508 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
509 vasnprintf (char **, size_t, const char *, va_list)
510 __attribute__((format (printf
, 3, 0)));
514 #define strdup rk_strdup
515 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
518 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
520 #define strndup rk_strndup
522 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
526 #define strlwr rk_strlwr
527 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
531 #define strnlen rk_strnlen
532 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
535 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
537 #define strsep rk_strsep
539 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
542 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
543 #ifndef HAVE_STRSEP_COPY
544 #define strsep_copy rk_strsep_copy
546 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
549 #ifndef HAVE_STRCASECMP
550 #define strcasecmp rk_strcasecmp
551 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
554 #ifdef NEED_FCLOSE_PROTO
555 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
558 #ifdef NEED_STRTOK_R_PROTO
559 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
563 #define strupr rk_strupr
564 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
568 #define strlcpy rk_strlcpy
569 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
573 #define strlcat rk_strlcat
574 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
577 #ifndef HAVE_GETDTABLESIZE
578 #define getdtablesize rk_getdtablesize
579 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
582 #if !defined(HAVE_STRERROR) && !defined(strerror)
583 #define strerror rk_strerror
584 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
587 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
588 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
590 #define rk_strerror_r strerror_r
593 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
594 #ifndef HAVE_HSTRERROR
595 #define hstrerror rk_hstrerror
597 /* This causes a fatal error under Psoriasis */
599 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
603 #if !HAVE_DECL_H_ERRNO
607 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
608 #ifndef HAVE_INET_ATON
609 #define inet_aton rk_inet_aton
611 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
614 #ifndef HAVE_INET_NTOP
615 #define inet_ntop rk_inet_ntop
616 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
617 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
620 #ifndef HAVE_INET_PTON
621 #define inet_pton rk_inet_pton
622 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
623 inet_pton(int, const char *, void *);
627 #define getcwd rk_getcwd
628 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
633 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
634 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
637 #ifdef POSIX_GETPWNAM_R
638 #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
640 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
641 rk_getpwnam_r(const char *, struct passwd
*, char *, size_t, struct passwd
**);
644 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
647 #define seteuid rk_seteuid
648 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
652 #define setegid rk_setegid
653 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
657 #define lstat rk_lstat
658 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
661 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
663 #define mkstemp rk_mkstemp
665 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
669 #define cgetent rk_cgetent
670 #define cgetstr rk_cgetstr
671 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
672 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
675 #ifndef HAVE_INITGROUPS
676 #define initgroups rk_initgroups
677 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
681 #define fchown rk_fchown
682 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
685 #ifdef RENAME_DOES_NOT_UNLINK
686 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_rename(const char *, const char *);
688 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
691 #ifdef MKDIR_DOES_NOT_HAVE_MODE
692 #define mkdir rk_mkdir
694 #define rk_mkdir(__rk_rn_name, __rk_rn_mode) mkdir(__rk_rn_name,__rk_rn_mode)
697 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
699 #define daemon rk_daemon
701 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
705 #define chown rk_chown
706 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
711 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
712 rcmd(char **, unsigned short, const char *,
713 const char *, const char *, int *);
716 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
718 #define innetgr rk_innetgr
720 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
721 const char*, const char*);
724 #ifndef HAVE_IRUSEROK
725 #define iruserok rk_iruserok
726 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
727 const char *, const char *);
730 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
731 #ifndef HAVE_GETHOSTNAME
732 #define gethostname rk_gethostname
734 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
738 #define writev rk_writev
739 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
740 writev(int, const struct iovec
*, int);
744 #define readv rk_readv
745 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
746 readv(int, const struct iovec
*, int);
751 #define pidfile(x) ((void) 0)
753 #define pidfile rk_pidfile
754 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
759 #define bswap32 rk_bswap32
760 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
764 #define bswap16 rk_bswap16
765 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
770 #define LOCK_SH 1 /* Shared lock */
773 #define LOCK_EX 2 /* Exclusive lock */
776 #define LOCK_NB 4 /* Don't block when locking */
779 #define LOCK_UN 8 /* Unlock */
782 #define flock(_x,_y) rk_flock(_x,_y)
783 int rk_flock(int fd
, int operation
);
784 #endif /* HAVE_FLOCK */
787 #ifdef HAVE_DIR_DD_FD
788 #define dirfd(x) ((x)->dd_fd)
790 #ifndef _WIN32 /* Windows code never calls dirfd */
791 #error Missing dirfd() and ->dd_fd
796 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
798 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
800 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
802 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
804 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
806 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
807 roken_vmconcat (char **, size_t, va_list);
809 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
810 net_write (rk_socket_t
, const void *, size_t);
812 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
813 net_read (rk_socket_t
, void *, size_t);
815 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
818 #ifndef HAVE_STRUCT_WINSIZE
820 unsigned short ws_row
, ws_col
;
821 unsigned short ws_xpixel
, ws_ypixel
;
825 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, int *, int *);
828 #define vsyslog rk_vsyslog
829 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
833 #define getopt rk_getopt
834 #define optarg rk_optarg
835 #define optind rk_optind
836 #define opterr rk_opterr
837 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
838 getopt(int nargc
, char * const *nargv
, const char *ostr
);
841 #if !HAVE_DECL_OPTARG
842 ROKEN_LIB_VARIABLE
extern char *optarg
;
844 #if !HAVE_DECL_OPTIND
845 ROKEN_LIB_VARIABLE
extern int optind
;
847 #if !HAVE_DECL_OPTERR
848 ROKEN_LIB_VARIABLE
extern int opterr
;
851 #ifndef HAVE_GETIPNODEBYNAME
852 #define getipnodebyname rk_getipnodebyname
853 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
854 getipnodebyname (const char *, int, int, int *);
857 #ifndef HAVE_GETIPNODEBYADDR
858 #define getipnodebyaddr rk_getipnodebyaddr
859 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
860 getipnodebyaddr (const void *, size_t, int, int *);
863 #ifndef HAVE_FREEHOSTENT
864 #define freehostent rk_freehostent
865 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
866 freehostent (struct hostent
*);
869 #ifndef HAVE_COPYHOSTENT
870 #define copyhostent rk_copyhostent
871 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
872 copyhostent (const struct hostent
*);
875 #ifndef HAVE_SOCKLEN_T
876 typedef int socklen_t
;
879 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
881 #ifndef HAVE_SA_FAMILY_T
882 typedef unsigned short sa_family_t
;
886 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
888 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
891 #define _SS_ALIGNSIZE sizeof(unsigned long)
893 #if HAVE_STRUCT_SOCKADDR_SA_LEN
895 typedef unsigned char roken_sa_family_t
;
897 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
898 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
900 struct sockaddr_storage
{
901 unsigned char ss_len
;
902 roken_sa_family_t ss_family
;
903 char __ss_pad1
[_SS_PAD1SIZE
];
904 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
907 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
909 typedef unsigned short roken_sa_family_t
;
911 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
912 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
914 struct sockaddr_storage
{
915 roken_sa_family_t ss_family
;
916 char __ss_pad1
[_SS_PAD1SIZE
];
917 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
920 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
922 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
924 #ifndef HAVE_STRUCT_ADDRINFO
932 struct sockaddr
*ai_addr
;
933 struct addrinfo
*ai_next
;
937 #ifndef HAVE_GETADDRINFO
938 #define getaddrinfo rk_getaddrinfo
939 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
940 getaddrinfo(const char *,
942 const struct addrinfo
*,
946 #ifndef HAVE_GETNAMEINFO
947 #define getnameinfo rk_getnameinfo
948 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
949 getnameinfo(const struct sockaddr
*, socklen_t
,
955 #ifndef HAVE_FREEADDRINFO
956 #define freeaddrinfo rk_freeaddrinfo
957 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
958 freeaddrinfo(struct addrinfo
*);
961 #ifndef HAVE_GAI_STRERROR
962 #define gai_strerror rk_gai_strerror
963 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
969 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
970 sleep(unsigned int seconds
);
972 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
973 usleep(unsigned int useconds
);
977 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
978 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
983 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
984 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
985 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
986 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
988 #ifndef HAVE_STRFTIME
989 #define strftime rk_strftime
990 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
991 strftime (char *, size_t, const char *, const struct tm
*);
994 #ifndef HAVE_STRPTIME
995 #define strptime rk_strptime
996 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
997 strptime (const char *, const char *, struct tm
*);
1000 #ifndef HAVE_GETTIMEOFDAY
1001 #define gettimeofday rk_gettimeofday
1002 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1003 gettimeofday (struct timeval
*, void *);
1006 #ifndef HAVE_EMALLOC
1007 #define emalloc rk_emalloc
1008 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
1010 #ifndef HAVE_ECALLOC
1011 #define ecalloc rk_ecalloc
1012 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
1014 #ifndef HAVE_EREALLOC
1015 #define erealloc rk_erealloc
1016 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
1018 #ifndef HAVE_ESTRDUP
1019 #define estrdup rk_estrdup
1020 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
1027 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1028 roken_gethostby_setup(const char*, const char*);
1029 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
1030 roken_gethostbyname(const char*);
1031 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
1032 roken_gethostbyaddr(const void*, size_t, int);
1034 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
1035 #define roken_getservbyname(x,y) getservbyname(x,y)
1037 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
1040 #ifdef OPENLOG_PROTO_COMPATIBLE
1041 #define roken_openlog(a,b,c) openlog(a,b,c)
1043 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
1046 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
1047 #define roken_getsockname(a,b,c) getsockname(a,b,c)
1049 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1052 #ifndef HAVE_SETPROGNAME
1053 #define setprogname rk_setprogname
1054 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
1057 #ifndef HAVE_GETPROGNAME
1058 #define getprogname rk_getprogname
1059 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
1062 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1063 extern const char *__progname
;
1066 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1067 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
1069 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1070 mini_inetd (int, rk_socket_t
*);
1072 #ifndef HAVE_LOCALTIME_R
1073 #define localtime_r rk_localtime_r
1074 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
1075 localtime_r(const time_t *, struct tm
*);
1078 #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO)
1079 #ifndef HAVE_STRTOLL
1080 #define strtoll rk_strtoll
1082 ROKEN_LIB_FUNCTION
long long ROKEN_LIB_CALL
1083 strtoll(const char * nptr
, char ** endptr
, int base
);
1086 #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO)
1087 #ifndef HAVE_STRTOULL
1088 #define strtoull rk_strtoull
1090 ROKEN_LIB_FUNCTION
unsigned long long ROKEN_LIB_CALL
1091 strtoull(const char * nptr
, char ** endptr
, int base
);
1094 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1095 #ifndef HAVE_STRSVIS
1096 #define strsvis rk_strsvis
1098 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1099 strsvis(char *, const char *, int, const char *);
1102 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1103 #ifndef HAVE_STRSVISX
1104 #define strsvisx rk_strsvisx
1106 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1107 strsvisx(char *, const char *, size_t, int, const char *);
1110 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1111 #ifndef HAVE_STRUNVIS
1112 #define strunvis rk_strunvis
1114 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1115 strunvis(char *, const char *);
1118 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1120 #define strvis rk_strvis
1122 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1123 strvis(char *, const char *, int);
1126 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1127 #ifndef HAVE_STRVISX
1128 #define strvisx rk_strvisx
1130 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1131 strvisx(char *, const char *, size_t, int);
1134 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1136 #define svis rk_svis
1138 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1139 svis(char *, int, int, int, const char *);
1142 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1144 #define unvis rk_unvis
1146 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1147 unvis(char *, int, int *, int);
1150 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1154 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1155 vis(char *, int, int, int);
1158 #if !defined(HAVE_CLOSEFROM)
1159 #define closefrom rk_closefrom
1160 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1164 #if !defined(HAVE_TIMEGM)
1165 #define timegm rk_timegm
1166 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1167 rk_timegm(struct tm
*tm
);
1171 #define qsort rk_qsort
1173 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1176 #if defined(HAVE_ARC4RANDOM)
1177 #define rk_random() arc4random()
1178 #elif defined(HAVE_RANDOM)
1179 #define rk_random() random()
1181 #define rk_random() rand()
1184 #ifndef HAVE_TDELETE
1185 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1188 #define tfind(a,b,c) rk_tfind(a,b,c)
1190 #ifndef HAVE_TSEARCH
1191 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1194 #define twalk(a,b) rk_twalk(a,b)
1197 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1199 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1200 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1203 /* Microsoft VC 2010 POSIX definitions */
1204 #ifndef EAFNOSUPPORT
1205 #define EAFNOSUPPORT 102
1208 #define EINPROGRESS 112
1214 #define ENOTSOCK 128
1220 #define EOVERFLOW 132
1223 #define ETIMEDOUT 138
1226 #define EWOULDBLOCK 140
1230 #ifdef SOCKET_WRAPPER_REPLACE
1231 #include <socket_wrapper.h>