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 */
60 * error codes for inet_ntop/inet_pton
62 #define EAFNOSUPPORT WSAEAFNOSUPPORT
64 typedef SOCKET rk_socket_t
;
66 #define rk_closesocket(x) closesocket(x)
67 #define rk_INVALID_SOCKET INVALID_SOCKET
68 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
69 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
70 #define rk_SOCK_ERRNO WSAGetLastError()
71 #define rk_SOCK_IOCTL(s,c,a) ioctlsocket((s),(c),(a))
73 #define ETIMEDOUT WSAETIMEDOUT
74 #define EWOULDBLOCK WSAEWOULDBLOCK
75 #define ENOTSOCK WSAENOTSOCK
77 #define rk_SOCK_INIT() rk_WSAStartup()
78 #define rk_SOCK_EXIT() rk_WSACleanup()
80 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSAStartup(void);
81 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSACleanup(void);
83 #else /* not WinSock */
85 typedef int rk_socket_t
;
87 #define rk_closesocket(x) close(x)
88 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
89 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
90 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
91 #define rk_SOCK_ERRNO errno
92 #define rk_INVALID_SOCKET (-1)
94 #define rk_SOCK_INIT() 0
95 #define rk_SOCK_EXIT() do { } while(0)
100 /* Declarations for Microsoft Visual C runtime on Windows */
106 #ifndef __BIT_TYPES_DEFINED__
107 #define __BIT_TYPES_DEFINED__
109 typedef __int8
int8_t;
110 typedef __int16
int16_t;
111 typedef __int32
int32_t;
112 typedef __int64
int64_t;
113 typedef unsigned __int8
uint8_t;
114 typedef unsigned __int16
uint16_t;
115 typedef unsigned __int32
uint32_t;
116 typedef unsigned __int64
uint64_t;
117 typedef uint8_t u_int8_t
;
118 typedef uint16_t u_int16_t
;
119 typedef uint32_t u_int32_t
;
120 typedef uint64_t u_int64_t
;
122 #endif /* __BIT_TYPES_DEFINED__ */
124 #define UNREACHABLE(x) x
125 #define UNUSED_ARGUMENT(x) ((void) x)
129 #define UNREACHABLE(x)
130 #define UNUSED_ARGUMENT(x)
138 #ifdef HAVE_SYS_PARAM_H
139 #include <sys/param.h>
141 #ifdef HAVE_INTTYPES_H
142 #include <inttypes.h>
144 #ifdef HAVE_SYS_TYPES_H
145 #include <sys/types.h>
147 #ifdef HAVE_SYS_BITYPES_H
148 #include <sys/bitypes.h>
150 #ifdef HAVE_BIND_BITYPES_H
151 #include <bind/bitypes.h>
153 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
154 #include <netinet/in6_machtypes.h>
159 #ifdef HAVE_SYS_SOCKET_H
160 #include <sys/socket.h>
162 #ifdef HAVE_SYS_UIO_H
168 #ifdef HAVE_SYS_STAT_H
169 #include <sys/stat.h>
171 #ifdef HAVE_NETINET_IN_H
172 #include <netinet/in.h>
174 #ifdef HAVE_NETINET_IN6_H
175 #include <netinet/in6.h>
177 #ifdef HAVE_NETINET6_IN6_H
178 #include <netinet6/in6.h>
180 #ifdef HAVE_ARPA_INET_H
181 #include <arpa/inet.h>
186 #ifdef HAVE_ARPA_NAMESER_H
187 #include <arpa/nameser.h>
202 #ifdef HAVE_TERMIOS_H
205 #ifdef HAVE_SYS_IOCTL_H
206 #include <sys/ioctl.h>
208 #ifdef TIME_WITH_SYS_TIME
209 #include <sys/time.h>
211 #elif defined(HAVE_SYS_TIME_H)
212 #include <sys/time.h>
217 #ifdef HAVE_WS2TCPIP_H
218 #include <ws2tcpip.h>
229 #ifdef BACKSLASH_PATH_DELIM
230 #define rk_PATH_DELIM '\\'
235 typedef __int64 ssize_t
;
241 #include <roken-common.h>
245 #ifdef HAVE_UINTPTR_T
246 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
248 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
251 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
252 #define setsid _setsid
256 /* Additional macros for Visual C/C++ runtime */
260 #define getpid _getpid
266 #define fsync _commit
268 /* The MSVC implementation of snprintf is not C99 compliant. */
269 #define snprintf rk_snprintf
270 #define vsnprintf rk_vsnprintf
271 #define vasnprintf rk_vasnprintf
272 #define vasprintf rk_vasprintf
273 #define asnprintf rk_asnprintf
274 #define asprintf rk_asprintf
276 #define _PIPE_BUFFER_SZ 8192
277 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
279 #define ftruncate(fd, sz) _chsize((fd), (sz))
281 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
282 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
284 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
285 rk_asprintf (char **ret
, const char *format
, ...);
287 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
288 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
290 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
291 rk_vasprintf (char **ret
, const char *format
, va_list args
);
293 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
294 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
296 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
297 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
299 /* missing stat.h predicates */
301 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
303 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
305 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
307 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
309 /* The following are not implemented:
316 #endif /* _MSC_VER */
319 #define putenv rk_putenv
320 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
323 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
325 #define setenv rk_setenv
327 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
330 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
331 #ifndef HAVE_UNSETENV
332 #define unsetenv rk_unsetenv
334 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
337 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
338 #ifndef HAVE_GETUSERSHELL
339 #define getusershell rk_getusershell
340 #define endusershell rk_endusershell
342 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
343 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
346 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
347 #ifndef HAVE_SNPRINTF
348 #define snprintf rk_snprintf
350 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
351 rk_snprintf (char *, size_t, const char *, ...)
352 __attribute__ ((format (printf
, 3, 4)));
355 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
356 #ifndef HAVE_VSNPRINTF
357 #define vsnprintf rk_vsnprintf
359 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
360 rk_vsnprintf (char *, size_t, const char *, va_list)
361 __attribute__((format (printf
, 3, 0)));
364 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
365 #ifndef HAVE_ASPRINTF
366 #define asprintf rk_asprintf
368 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
369 rk_asprintf (char **, const char *, ...)
370 __attribute__ ((format (printf
, 2, 3)));
373 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
374 #ifndef HAVE_VASPRINTF
375 #define vasprintf rk_vasprintf
377 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
378 rk_vasprintf (char **, const char *, va_list)
379 __attribute__((format (printf
, 2, 0)));
382 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
383 #ifndef HAVE_ASNPRINTF
384 #define asnprintf rk_asnprintf
386 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
387 rk_asnprintf (char **, size_t, const char *, ...)
388 __attribute__ ((format (printf
, 3, 4)));
391 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
392 #ifndef HAVE_VASNPRINTF
393 #define vasnprintf rk_vasnprintf
395 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
396 vasnprintf (char **, size_t, const char *, va_list)
397 __attribute__((format (printf
, 3, 0)));
401 #define strdup rk_strdup
402 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
405 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
407 #define strndup rk_strndup
409 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
413 #define strlwr rk_strlwr
414 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
418 #define strnlen rk_strnlen
419 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
422 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
424 #define strsep rk_strsep
426 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
429 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
430 #ifndef HAVE_STRSEP_COPY
431 #define strsep_copy rk_strsep_copy
433 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
436 #ifndef HAVE_STRCASECMP
437 #define strcasecmp rk_strcasecmp
438 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
441 #ifdef NEED_FCLOSE_PROTO
442 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
445 #ifdef NEED_STRTOK_R_PROTO
446 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
450 #define strupr rk_strupr
451 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
455 #define strlcpy rk_strlcpy
456 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
460 #define strlcat rk_strlcat
461 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
464 #ifndef HAVE_GETDTABLESIZE
465 #define getdtablesize rk_getdtablesize
466 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
469 #if !defined(HAVE_STRERROR) && !defined(strerror)
470 #define strerror rk_strerror
471 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
474 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
475 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
477 #define rk_strerror_r strerror_r
480 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
481 #ifndef HAVE_HSTRERROR
482 #define hstrerror rk_hstrerror
484 /* This causes a fatal error under Psoriasis */
486 const char * ROKEN_LIB_FUNCTION
hstrerror(int);
487 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
491 #if !HAVE_DECL_H_ERRNO
495 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
496 #ifndef HAVE_INET_ATON
497 #define inet_aton rk_inet_aton
499 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
502 #ifndef HAVE_INET_NTOP
503 #define inet_ntop rk_inet_ntop
504 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
505 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
508 #ifndef HAVE_INET_PTON
509 #define inet_pton rk_inet_pton
510 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
511 inet_pton(int, const char *, void *);
515 #define getcwd rk_getcwd
516 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
521 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
522 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
525 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
528 #define seteuid rk_seteuid
529 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
533 #define setegid rk_setegid
534 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
538 #define lstat rk_lstat
539 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
542 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
544 #define mkstemp rk_mkstemp
546 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
550 #define cgetent rk_cgetent
551 #define cgetstr rk_cgetstr
552 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
553 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
556 #ifndef HAVE_INITGROUPS
557 #define initgroups rk_initgroups
558 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
562 #define fchown rk_fchown
563 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
566 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
568 #define daemon rk_daemon
570 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
574 #define chown rk_chown
575 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
580 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
581 rcmd(char **, unsigned short, const char *,
582 const char *, const char *, int *);
585 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
587 #define innetgr rk_innetgr
589 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
590 const char*, const char*);
593 #ifndef HAVE_IRUSEROK
594 #define iruserok rk_iruserok
595 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
596 const char *, const char *);
599 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
600 #ifndef HAVE_GETHOSTNAME
601 #define gethostname rk_gethostname
603 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
607 #define writev rk_writev
608 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
609 writev(int, const struct iovec
*, int);
613 #define readv rk_readv
614 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
615 readv(int, const struct iovec
*, int);
620 #define pidfile(x) ((void) 0)
622 #define pidfile rk_pidfile
623 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
628 #define bswap32 rk_bswap32
629 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
633 #define bswap16 rk_bswap16
634 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
639 #define LOCK_SH 1 /* Shared lock */
642 #define LOCK_EX 2 /* Exclusive lock */
645 #define LOCK_NB 4 /* Don't block when locking */
648 #define LOCK_UN 8 /* Unlock */
651 #define flock(_x,_y) rk_flock(_x,_y)
652 int rk_flock(int fd
, int operation
);
653 #endif /* HAVE_FLOCK */
656 #ifdef HAVE_DIR_DD_FD
657 #define dirfd(x) ((x)->dd_fd)
659 #ifndef _WIN32 /* Windows code never calls dirfd */
660 #error Missing dirfd() and ->dd_fd
665 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
667 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
669 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
671 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
673 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
675 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
676 roken_vmconcat (char **, size_t, va_list);
678 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
679 net_write (rk_socket_t
, const void *, size_t);
681 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
682 net_read (rk_socket_t
, void *, size_t);
684 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
687 #ifndef HAVE_STRUCT_WINSIZE
689 unsigned short ws_row
, ws_col
;
690 unsigned short ws_xpixel
, ws_ypixel
;
694 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, struct winsize
*);
697 #define vsyslog rk_vsyslog
698 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
701 #if !HAVE_DECL_OPTARG
704 #if !HAVE_DECL_OPTIND
707 #if !HAVE_DECL_OPTERR
711 #ifndef HAVE_GETIPNODEBYNAME
712 #define getipnodebyname rk_getipnodebyname
713 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
714 getipnodebyname (const char *, int, int, int *);
717 #ifndef HAVE_GETIPNODEBYADDR
718 #define getipnodebyaddr rk_getipnodebyaddr
719 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
720 getipnodebyaddr (const void *, size_t, int, int *);
723 #ifndef HAVE_FREEHOSTENT
724 #define freehostent rk_freehostent
725 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
726 freehostent (struct hostent
*);
729 #ifndef HAVE_COPYHOSTENT
730 #define copyhostent rk_copyhostent
731 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
732 copyhostent (const struct hostent
*);
735 #ifndef HAVE_SOCKLEN_T
736 typedef int socklen_t
;
739 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
741 #ifndef HAVE_SA_FAMILY_T
742 typedef unsigned short sa_family_t
;
746 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
748 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
751 #define _SS_ALIGNSIZE sizeof(unsigned long)
753 #if HAVE_STRUCT_SOCKADDR_SA_LEN
755 typedef unsigned char roken_sa_family_t
;
757 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
758 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
760 struct sockaddr_storage
{
761 unsigned char ss_len
;
762 roken_sa_family_t ss_family
;
763 char __ss_pad1
[_SS_PAD1SIZE
];
764 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
767 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
769 typedef unsigned short roken_sa_family_t
;
771 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
772 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
774 struct sockaddr_storage
{
775 roken_sa_family_t ss_family
;
776 char __ss_pad1
[_SS_PAD1SIZE
];
777 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
780 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
782 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
784 #ifndef HAVE_STRUCT_ADDRINFO
792 struct sockaddr
*ai_addr
;
793 struct addrinfo
*ai_next
;
797 #ifndef HAVE_GETADDRINFO
798 #define getaddrinfo rk_getaddrinfo
799 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
800 getaddrinfo(const char *,
802 const struct addrinfo
*,
806 #ifndef HAVE_GETNAMEINFO
807 #define getnameinfo rk_getnameinfo
808 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
809 getnameinfo(const struct sockaddr
*, socklen_t
,
815 #ifndef HAVE_FREEADDRINFO
816 #define freeaddrinfo rk_freeaddrinfo
817 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
818 freeaddrinfo(struct addrinfo
*);
821 #ifndef HAVE_GAI_STRERROR
822 #define gai_strerror rk_gai_strerror
823 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
829 /* While we are at it, define WinSock specific scatter gather socket
832 #define iovec _WSABUF
838 socklen_t msg_namelen
;
839 struct iovec
*msg_iov
;
842 socklen_t msg_controllen
;
846 #define sendmsg sendmsg_w32
848 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
849 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
855 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
856 sleep(unsigned int seconds
);
860 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
861 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
866 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
867 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
868 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
869 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
871 #ifndef HAVE_STRFTIME
872 #define strftime rk_strftime
873 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
874 strftime (char *, size_t, const char *, const struct tm
*);
877 #ifndef HAVE_STRPTIME
878 #define strptime rk_strptime
879 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
880 strptime (const char *, const char *, struct tm
*);
883 #ifndef HAVE_GETTIMEOFDAY
884 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
885 gettimeofday (struct timeval
*, void *);
889 #define emalloc rk_emalloc
890 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
893 #define ecalloc rk_ecalloc
894 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
896 #ifndef HAVE_EREALLOC
897 #define erealloc rk_erealloc
898 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
901 #define estrdup rk_estrdup
902 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
909 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
910 roken_gethostby_setup(const char*, const char*);
911 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
912 roken_gethostbyname(const char*);
913 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
914 roken_gethostbyaddr(const void*, size_t, int);
916 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
917 #define roken_getservbyname(x,y) getservbyname(x,y)
919 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
922 #ifdef OPENLOG_PROTO_COMPATIBLE
923 #define roken_openlog(a,b,c) openlog(a,b,c)
925 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
928 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
929 #define roken_getsockname(a,b,c) getsockname(a,b,c)
931 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
934 #ifndef HAVE_SETPROGNAME
935 #define setprogname rk_setprogname
936 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
939 #ifndef HAVE_GETPROGNAME
940 #define getprogname rk_getprogname
941 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
944 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
945 extern const char *__progname
;
948 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
949 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
951 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
952 mini_inetd (int, rk_socket_t
*);
954 #ifndef HAVE_LOCALTIME_R
955 #define localtime_r rk_localtime_r
956 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
957 localtime_r(const time_t *, struct tm
*);
960 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
962 #define strsvis rk_strsvis
964 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
965 strsvis(char *, const char *, int, const char *);
968 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
969 #ifndef HAVE_STRSVISX
970 #define strsvisx rk_strsvisx
972 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
973 strsvisx(char *, const char *, size_t, int, const char *);
976 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
977 #ifndef HAVE_STRUNVIS
978 #define strunvis rk_strunvis
980 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
981 strunvis(char *, const char *);
984 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
986 #define strvis rk_strvis
988 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
989 strvis(char *, const char *, int);
992 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
994 #define strvisx rk_strvisx
996 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
997 strvisx(char *, const char *, size_t, int);
1000 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1002 #define svis rk_svis
1004 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1005 svis(char *, int, int, int, const char *);
1008 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1010 #define unvis rk_unvis
1012 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1013 unvis(char *, int, int *, int);
1016 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1020 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1021 vis(char *, int, int, int);
1024 #if !defined(HAVE_CLOSEFROM)
1025 #define closefrom rk_closefrom
1026 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1030 #if !defined(HAVE_TIMEGM)
1031 #define timegm rk_timegm
1032 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1033 rk_timegm(struct tm
*tm
);
1037 #define qsort rk_qsort
1039 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1042 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE)
1044 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1045 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1048 #ifdef SOCKET_WRAPPER_REPLACE
1049 #include <socket_wrapper.h>