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_ERRNO_H
186 #include <sys/errno.h>
188 #ifdef HAVE_SYS_BITYPES_H
189 #include <sys/bitypes.h>
191 #ifdef HAVE_BIND_BITYPES_H
192 #include <bind/bitypes.h>
194 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
195 #include <netinet/in6_machtypes.h>
200 #ifdef HAVE_SYS_SOCKET_H
201 #include <sys/socket.h>
203 #ifdef HAVE_SYS_UIO_H
209 #ifdef HAVE_SYS_STAT_H
210 #include <sys/stat.h>
212 #ifdef HAVE_NETINET_IN_H
213 #include <netinet/in.h>
215 #ifdef HAVE_NETINET_IN6_H
216 #include <netinet/in6.h>
218 #ifdef HAVE_NETINET6_IN6_H
219 #include <netinet6/in6.h>
221 #ifdef HAVE_ARPA_INET_H
222 #include <arpa/inet.h>
227 #ifdef HAVE_ARPA_NAMESER_H
228 #include <arpa/nameser.h>
243 #ifdef HAVE_TERMIOS_H
246 #ifdef HAVE_SYS_IOCTL_H
247 #include <sys/ioctl.h>
249 #ifdef TIME_WITH_SYS_TIME
250 #include <sys/time.h>
252 #elif defined(HAVE_SYS_TIME_H)
253 #include <sys/time.h>
270 #ifdef BACKSLASH_PATH_DELIM
271 #define rk_PATH_DELIM '\\'
275 #ifndef SSIZE_T_DEFINED
280 typedef __int64 ssize_t
;
284 #define SSIZE_T_DEFINED
285 #endif /* SSIZE_T_DEFINED */
286 #endif /* HAVE_SSIZE_T */
288 #include <roken-common.h>
292 #ifdef HAVE_UINTPTR_T
293 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
295 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
298 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
299 #define setsid _setsid
303 /* Additional macros for Visual C/C++ runtime */
307 #define getpid _getpid
313 #define fsync _commit
315 /* The MSVC implementation of snprintf is not C99 compliant. */
316 #define snprintf rk_snprintf
317 #define vsnprintf rk_vsnprintf
318 #define vasnprintf rk_vasnprintf
319 #define vasprintf rk_vasprintf
320 #define asnprintf rk_asnprintf
321 #define asprintf rk_asprintf
323 #define _PIPE_BUFFER_SZ 8192
324 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
326 #define ftruncate(fd, sz) _chsize((fd), (sz))
328 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
329 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
331 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
332 rk_asprintf (char **ret
, const char *format
, ...);
334 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
335 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
337 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
338 rk_vasprintf (char **ret
, const char *format
, va_list args
);
340 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
341 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
343 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
344 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
346 /* missing stat.h predicates */
348 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
350 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
352 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
354 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
356 /* The following are not implemented:
363 /* The following symbolic constants are provided for rk_mkdir mode */
365 #define S_IRWXU 00700 /* user (file owner) has read, write and execute permission */
366 #define S_IRUSR 00400 /* user has read permission */
367 #define S_IWUSR 00200 /* user has write permission */
368 #define S_IXUSR 00100 /* user has execute permission */
369 #define S_IRWXG 00070 /* group has read, write and execute permission */
370 #define S_IRGRP 00040 /* group has read permission */
371 #define S_IWGRP 00020 /* group has write permission */
372 #define S_IXGRP 00010 /* group has execute permission */
373 #define S_IRWXO 00007 /* others have read, write and execute permission */
374 #define S_IROTH 00004 /* others have read permission */
375 #define S_IWOTH 00002 /* others have write permission */
376 #define S_IXOTH 00001 /* others have execute permission */
378 #if !defined(ROKEN_NO_DEFINE_ALLOCATORS)
379 /* Ensure that a common memory allocator is used by all */
380 #define calloc rk_calloc
382 #define malloc rk_malloc
383 #define realloc rk_realloc
384 #define strdup rk_strdup
385 #define wcsdup rk_wcsdup
388 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
389 rk_calloc(size_t, size_t);
391 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
394 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
397 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
398 rk_realloc(void *, size_t);
400 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
401 rk_strdup(const char *);
403 ROKEN_LIB_FUNCTION
unsigned short * ROKEN_LIB_CALL
404 rk_wcsdup(const unsigned short *);
406 #endif /* _MSC_VER */
410 /* While we are at it, define WinSock specific scatter gather socket
413 #define iovec _WSABUF
419 socklen_t msg_namelen
;
420 struct iovec
*msg_iov
;
423 socklen_t msg_controllen
;
427 #define sendmsg sendmsg_w32
429 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
430 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
432 #endif /* HAVE_WINSOCK */
435 #define putenv rk_putenv
436 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
439 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
441 #define setenv rk_setenv
443 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
446 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
447 #ifndef HAVE_UNSETENV
448 #define unsetenv rk_unsetenv
450 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
453 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
454 #ifndef HAVE_GETUSERSHELL
455 #define getusershell rk_getusershell
456 #define endusershell rk_endusershell
458 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
459 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
462 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
463 #ifndef HAVE_SNPRINTF
464 #define snprintf rk_snprintf
466 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
467 rk_snprintf (char *, size_t, const char *, ...)
468 __attribute__ ((format (printf
, 3, 4)));
471 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
472 #ifndef HAVE_VSNPRINTF
473 #define vsnprintf rk_vsnprintf
475 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
476 rk_vsnprintf (char *, size_t, const char *, va_list)
477 __attribute__((format (printf
, 3, 0)));
480 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
481 #ifndef HAVE_ASPRINTF
482 #define asprintf rk_asprintf
484 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
485 rk_asprintf (char **, const char *, ...)
486 __attribute__ ((format (printf
, 2, 3)));
489 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
490 #ifndef HAVE_VASPRINTF
491 #define vasprintf rk_vasprintf
493 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
494 rk_vasprintf (char **, const char *, va_list)
495 __attribute__((format (printf
, 2, 0)));
498 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
499 #ifndef HAVE_ASNPRINTF
500 #define asnprintf rk_asnprintf
502 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
503 rk_asnprintf (char **, size_t, const char *, ...)
504 __attribute__ ((format (printf
, 3, 4)));
507 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
508 #ifndef HAVE_VASNPRINTF
509 #define vasnprintf rk_vasnprintf
511 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
512 vasnprintf (char **, size_t, const char *, va_list)
513 __attribute__((format (printf
, 3, 0)));
517 #define strdup rk_strdup
518 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
521 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
523 #define strndup rk_strndup
525 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
529 #define strlwr rk_strlwr
530 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
534 #define strnlen rk_strnlen
535 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
538 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
540 #define strsep rk_strsep
542 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
545 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
546 #ifndef HAVE_STRSEP_COPY
547 #define strsep_copy rk_strsep_copy
549 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
552 #ifndef HAVE_STRCASECMP
553 #define strcasecmp rk_strcasecmp
554 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
557 #ifdef NEED_FCLOSE_PROTO
558 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
561 #ifdef NEED_STRTOK_R_PROTO
562 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
566 #define strupr rk_strupr
567 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
571 #define strlcpy rk_strlcpy
572 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
576 #define strlcat rk_strlcat
577 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
580 #ifndef HAVE_GETDTABLESIZE
581 #define getdtablesize rk_getdtablesize
582 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
585 #if !defined(HAVE_STRERROR) && !defined(strerror)
586 #define strerror rk_strerror
587 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
590 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
591 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
593 #define rk_strerror_r strerror_r
596 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
597 #ifndef HAVE_HSTRERROR
598 #define hstrerror rk_hstrerror
600 /* This causes a fatal error under Psoriasis */
602 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
606 #if !HAVE_DECL_H_ERRNO
610 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
611 #ifndef HAVE_INET_ATON
612 #define inet_aton rk_inet_aton
614 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
617 #ifndef HAVE_INET_NTOP
618 #define inet_ntop rk_inet_ntop
619 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
620 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
623 #ifndef HAVE_INET_PTON
624 #define inet_pton rk_inet_pton
625 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
626 inet_pton(int, const char *, void *);
630 #define getcwd rk_getcwd
631 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
636 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
637 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
640 #ifdef POSIX_GETPWNAM_R
641 #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
643 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
644 rk_getpwnam_r(const char *, struct passwd
*, char *, size_t, struct passwd
**);
647 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
650 #define seteuid rk_seteuid
651 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
655 #define setegid rk_setegid
656 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
660 #define lstat rk_lstat
661 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
664 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
666 #define mkstemp rk_mkstemp
668 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
672 #define cgetent rk_cgetent
673 #define cgetstr rk_cgetstr
674 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
675 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
678 #ifndef HAVE_INITGROUPS
679 #define initgroups rk_initgroups
680 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
684 #define fchown rk_fchown
685 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
688 #ifdef RENAME_DOES_NOT_UNLINK
689 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_rename(const char *, const char *);
691 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
694 #ifdef MKDIR_DOES_NOT_HAVE_MODE
695 #define mkdir rk_mkdir
697 #define rk_mkdir(__rk_rn_name, __rk_rn_mode) mkdir(__rk_rn_name,__rk_rn_mode)
700 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
702 #define daemon rk_daemon
704 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
708 #define chown rk_chown
709 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
714 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
715 rcmd(char **, unsigned short, const char *,
716 const char *, const char *, int *);
719 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
721 #define innetgr rk_innetgr
723 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
724 const char*, const char*);
727 #ifndef HAVE_IRUSEROK
728 #define iruserok rk_iruserok
729 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
730 const char *, const char *);
733 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
734 #ifndef HAVE_GETHOSTNAME
735 #define gethostname rk_gethostname
737 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
741 #define writev rk_writev
742 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
743 writev(int, const struct iovec
*, int);
747 #define readv rk_readv
748 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
749 readv(int, const struct iovec
*, int);
754 #define pidfile(x) ((void) 0)
756 #define pidfile rk_pidfile
757 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
762 #define bswap32 rk_bswap32
763 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
767 #define bswap16 rk_bswap16
768 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
773 #define LOCK_SH 1 /* Shared lock */
776 #define LOCK_EX 2 /* Exclusive lock */
779 #define LOCK_NB 4 /* Don't block when locking */
782 #define LOCK_UN 8 /* Unlock */
785 #define flock(_x,_y) rk_flock(_x,_y)
786 int rk_flock(int fd
, int operation
);
787 #endif /* HAVE_FLOCK */
790 #ifdef HAVE_DIR_DD_FD
791 #define dirfd(x) ((x)->dd_fd)
793 #ifndef _WIN32 /* Windows code never calls dirfd */
794 #error Missing dirfd() and ->dd_fd
799 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
801 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
803 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
805 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
807 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
809 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
810 roken_vmconcat (char **, size_t, va_list);
812 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
813 net_write (rk_socket_t
, const void *, size_t);
815 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
816 net_read (rk_socket_t
, void *, size_t);
818 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
821 #ifndef HAVE_STRUCT_WINSIZE
823 unsigned short ws_row
, ws_col
;
824 unsigned short ws_xpixel
, ws_ypixel
;
828 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, int *, int *);
831 #define vsyslog rk_vsyslog
832 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
836 #define getopt rk_getopt
837 #define optarg rk_optarg
838 #define optind rk_optind
839 #define opterr rk_opterr
840 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
841 getopt(int nargc
, char * const *nargv
, const char *ostr
);
844 #if !HAVE_DECL_OPTARG
845 ROKEN_LIB_VARIABLE
extern char *optarg
;
847 #if !HAVE_DECL_OPTIND
848 ROKEN_LIB_VARIABLE
extern int optind
;
850 #if !HAVE_DECL_OPTERR
851 ROKEN_LIB_VARIABLE
extern int opterr
;
854 #ifndef HAVE_GETIPNODEBYNAME
855 #define getipnodebyname rk_getipnodebyname
856 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
857 getipnodebyname (const char *, int, int, int *);
860 #ifndef HAVE_GETIPNODEBYADDR
861 #define getipnodebyaddr rk_getipnodebyaddr
862 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
863 getipnodebyaddr (const void *, size_t, int, int *);
866 #ifndef HAVE_FREEHOSTENT
867 #define freehostent rk_freehostent
868 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
869 freehostent (struct hostent
*);
872 #ifndef HAVE_COPYHOSTENT
873 #define copyhostent rk_copyhostent
874 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
875 copyhostent (const struct hostent
*);
878 #ifndef HAVE_SOCKLEN_T
879 typedef int socklen_t
;
882 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
884 #ifndef HAVE_SA_FAMILY_T
885 typedef unsigned short sa_family_t
;
889 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
891 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
894 #define _SS_ALIGNSIZE sizeof(unsigned long)
896 #if HAVE_STRUCT_SOCKADDR_SA_LEN
898 typedef unsigned char roken_sa_family_t
;
900 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
901 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
903 struct sockaddr_storage
{
904 unsigned char ss_len
;
905 roken_sa_family_t ss_family
;
906 char __ss_pad1
[_SS_PAD1SIZE
];
907 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
910 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
912 typedef unsigned short roken_sa_family_t
;
914 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
915 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
917 struct sockaddr_storage
{
918 roken_sa_family_t ss_family
;
919 char __ss_pad1
[_SS_PAD1SIZE
];
920 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
923 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
925 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
927 #ifndef HAVE_STRUCT_ADDRINFO
935 struct sockaddr
*ai_addr
;
936 struct addrinfo
*ai_next
;
940 #ifndef HAVE_GETADDRINFO
941 #define getaddrinfo rk_getaddrinfo
942 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
943 getaddrinfo(const char *,
945 const struct addrinfo
*,
949 #ifndef HAVE_GETNAMEINFO
950 #define getnameinfo rk_getnameinfo
951 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
952 getnameinfo(const struct sockaddr
*, socklen_t
,
958 #ifndef HAVE_FREEADDRINFO
959 #define freeaddrinfo rk_freeaddrinfo
960 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
961 freeaddrinfo(struct addrinfo
*);
964 #ifndef HAVE_GAI_STRERROR
965 #define gai_strerror rk_gai_strerror
966 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
972 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
973 sleep(unsigned int seconds
);
975 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
976 usleep(unsigned int useconds
);
980 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
981 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
986 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
987 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
988 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
989 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
991 #ifndef HAVE_STRFTIME
992 #define strftime rk_strftime
993 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
994 strftime (char *, size_t, const char *, const struct tm
*);
997 #ifndef HAVE_STRPTIME
998 #define strptime rk_strptime
999 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1000 strptime (const char *, const char *, struct tm
*);
1003 #ifndef HAVE_GETTIMEOFDAY
1004 #define gettimeofday rk_gettimeofday
1005 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1006 gettimeofday (struct timeval
*, void *);
1009 #ifndef HAVE_EMALLOC
1010 #define emalloc rk_emalloc
1011 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
1013 #ifndef HAVE_ECALLOC
1014 #define ecalloc rk_ecalloc
1015 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
1017 #ifndef HAVE_EREALLOC
1018 #define erealloc rk_erealloc
1019 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
1021 #ifndef HAVE_ESTRDUP
1022 #define estrdup rk_estrdup
1023 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
1030 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1031 roken_gethostby_setup(const char*, const char*);
1032 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
1033 roken_gethostbyname(const char*);
1034 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
1035 roken_gethostbyaddr(const void*, size_t, int);
1037 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
1038 #define roken_getservbyname(x,y) getservbyname(x,y)
1040 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
1043 #ifdef OPENLOG_PROTO_COMPATIBLE
1044 #define roken_openlog(a,b,c) openlog(a,b,c)
1046 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
1049 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
1050 #define roken_getsockname(a,b,c) getsockname(a,b,c)
1052 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1055 #ifndef HAVE_SETPROGNAME
1056 #define setprogname rk_setprogname
1057 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
1060 #ifndef HAVE_GETPROGNAME
1061 #define getprogname rk_getprogname
1062 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
1065 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1066 extern const char *__progname
;
1069 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1070 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
1072 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1073 mini_inetd (int, rk_socket_t
*);
1075 #ifndef HAVE_LOCALTIME_R
1076 #define localtime_r rk_localtime_r
1077 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
1078 localtime_r(const time_t *, struct tm
*);
1081 #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO)
1082 #ifndef HAVE_STRTOLL
1083 #define strtoll rk_strtoll
1085 ROKEN_LIB_FUNCTION
long long ROKEN_LIB_CALL
1086 strtoll(const char * nptr
, char ** endptr
, int base
);
1089 #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO)
1090 #ifndef HAVE_STRTOULL
1091 #define strtoull rk_strtoull
1093 ROKEN_LIB_FUNCTION
unsigned long long ROKEN_LIB_CALL
1094 strtoull(const char * nptr
, char ** endptr
, int base
);
1097 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1098 #ifndef HAVE_STRSVIS
1099 #define strsvis rk_strsvis
1101 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1102 strsvis(char *, const char *, int, const char *);
1105 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1106 #ifndef HAVE_STRSVISX
1107 #define strsvisx rk_strsvisx
1109 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1110 strsvisx(char *, const char *, size_t, int, const char *);
1113 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1114 #ifndef HAVE_STRUNVIS
1115 #define strunvis rk_strunvis
1117 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1118 strunvis(char *, const char *);
1121 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1123 #define strvis rk_strvis
1125 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1126 strvis(char *, const char *, int);
1129 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1130 #ifndef HAVE_STRVISX
1131 #define strvisx rk_strvisx
1133 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1134 strvisx(char *, const char *, size_t, int);
1137 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1139 #define svis rk_svis
1141 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1142 svis(char *, int, int, int, const char *);
1145 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1147 #define unvis rk_unvis
1149 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1150 unvis(char *, int, int *, int);
1153 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1157 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1158 vis(char *, int, int, int);
1161 #if !defined(HAVE_CLOSEFROM)
1162 #define closefrom rk_closefrom
1163 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1167 #if !defined(HAVE_TIMEGM)
1168 #define timegm rk_timegm
1169 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1170 rk_timegm(struct tm
*tm
);
1174 #define qsort rk_qsort
1176 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1179 #if defined(HAVE_ARC4RANDOM)
1180 #define rk_random() arc4random()
1181 #elif defined(HAVE_RANDOM)
1182 #define rk_random() random()
1184 #define rk_random() rand()
1187 #ifndef HAVE_TDELETE
1188 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1191 #define tfind(a,b,c) rk_tfind(a,b,c)
1193 #ifndef HAVE_TSEARCH
1194 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1197 #define twalk(a,b) rk_twalk(a,b)
1200 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1202 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1203 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1206 /* Microsoft VC 2010 POSIX definitions */
1207 #ifndef EAFNOSUPPORT
1208 #define EAFNOSUPPORT 102
1211 #define EINPROGRESS 112
1217 #define ENOTSOCK 128
1223 #define EOVERFLOW 132
1226 #define ETIMEDOUT 138
1229 #define EWOULDBLOCK 140
1233 #ifdef SOCKET_WRAPPER_REPLACE
1234 #include <socket_wrapper.h>