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 /* Microsoft VC 2010 POSIX definitions */
96 #define EWOULDBLOCK 140
99 #define rk_SOCK_INIT() rk_WSAStartup()
100 #define rk_SOCK_EXIT() rk_WSACleanup()
102 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSAStartup(void);
103 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSACleanup(void);
105 #else /* not WinSock */
107 typedef int rk_socket_t
;
109 #define rk_closesocket(x) close(x)
110 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
111 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
112 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
113 #define rk_SOCK_ERRNO errno
114 #define rk_INVALID_SOCKET (-1)
116 #define rk_SOCK_INIT() 0
117 #define rk_SOCK_EXIT() do { } while(0)
121 #ifndef IN_LOOPBACKNET
122 #define IN_LOOPBACKNET 127
126 /* Declarations for Microsoft Visual C runtime on Windows */
132 #ifndef __BIT_TYPES_DEFINED__
133 #define __BIT_TYPES_DEFINED__
135 typedef __int8
int8_t;
136 typedef __int16
int16_t;
137 typedef __int32
int32_t;
138 typedef __int64
int64_t;
139 typedef unsigned __int8
uint8_t;
140 typedef unsigned __int16
uint16_t;
141 typedef unsigned __int32
uint32_t;
142 typedef unsigned __int64
uint64_t;
143 typedef uint8_t u_int8_t
;
144 typedef uint16_t u_int16_t
;
145 typedef uint32_t u_int32_t
;
146 typedef uint64_t u_int64_t
;
148 #endif /* __BIT_TYPES_DEFINED__ */
150 #define UNREACHABLE(x) x
151 #define UNUSED_ARGUMENT(x) ((void) x)
153 #define RETSIGTYPE void
155 #define VOID_RETSIGTYPE 1
157 #ifdef VOID_RETSIGTYPE
158 #define SIGRETURN(x) return
160 #define SIGRETURN(x) return (RETSIGTYPE)(x)
167 typedef unsigned int gid_t
;
169 typedef unsigned int uid_t
;
171 typedef unsigned short mode_t
;
176 #define inline __inline
181 #define UNREACHABLE(x)
182 #define UNUSED_ARGUMENT(x)
190 #ifdef HAVE_SYS_PARAM_H
191 #include <sys/param.h>
193 #ifdef HAVE_INTTYPES_H
194 #include <inttypes.h>
196 #ifdef HAVE_SYS_TYPES_H
197 #include <sys/types.h>
199 #ifdef HAVE_SYS_BITYPES_H
200 #include <sys/bitypes.h>
202 #ifdef HAVE_BIND_BITYPES_H
203 #include <bind/bitypes.h>
205 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
206 #include <netinet/in6_machtypes.h>
211 #ifdef HAVE_SYS_SOCKET_H
212 #include <sys/socket.h>
214 #ifdef HAVE_SYS_UIO_H
220 #ifdef HAVE_SYS_STAT_H
221 #include <sys/stat.h>
223 #ifdef HAVE_NETINET_IN_H
224 #include <netinet/in.h>
226 #ifdef HAVE_NETINET_IN6_H
227 #include <netinet/in6.h>
229 #ifdef HAVE_NETINET6_IN6_H
230 #include <netinet6/in6.h>
232 #ifdef HAVE_ARPA_INET_H
233 #include <arpa/inet.h>
238 #ifdef HAVE_ARPA_NAMESER_H
239 #include <arpa/nameser.h>
254 #ifdef HAVE_TERMIOS_H
257 #ifdef HAVE_SYS_IOCTL_H
258 #include <sys/ioctl.h>
260 #ifdef TIME_WITH_SYS_TIME
261 #include <sys/time.h>
263 #elif defined(HAVE_SYS_TIME_H)
264 #include <sys/time.h>
277 #ifdef BACKSLASH_PATH_DELIM
278 #define rk_PATH_DELIM '\\'
282 #ifndef SSIZE_T_DEFINED
287 typedef __int64 ssize_t
;
291 #define SSIZE_T_DEFINED
292 #endif /* SSIZE_T_DEFINED */
293 #endif /* HAVE_SSIZE_T */
295 #include <roken-common.h>
299 #ifdef HAVE_UINTPTR_T
300 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
302 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
305 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
306 #define setsid _setsid
310 /* Additional macros for Visual C/C++ runtime */
314 #define getpid _getpid
320 #define fsync _commit
322 /* The MSVC implementation of snprintf is not C99 compliant. */
323 #define snprintf rk_snprintf
324 #define vsnprintf rk_vsnprintf
325 #define vasnprintf rk_vasnprintf
326 #define vasprintf rk_vasprintf
327 #define asnprintf rk_asnprintf
328 #define asprintf rk_asprintf
330 #define _PIPE_BUFFER_SZ 8192
331 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
333 #define ftruncate(fd, sz) _chsize((fd), (sz))
335 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
336 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
338 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
339 rk_asprintf (char **ret
, const char *format
, ...);
341 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
342 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
344 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
345 rk_vasprintf (char **ret
, const char *format
, va_list args
);
347 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
348 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
350 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
351 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
353 /* missing stat.h predicates */
355 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
357 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
359 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
361 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
363 /* The following are not implemented:
370 #endif /* _MSC_VER */
374 /* While we are at it, define WinSock specific scatter gather socket
377 #define iovec _WSABUF
383 socklen_t msg_namelen
;
384 struct iovec
*msg_iov
;
387 socklen_t msg_controllen
;
391 #define sendmsg sendmsg_w32
393 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
394 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
396 #endif /* HAVE_WINSOCK */
399 #define putenv rk_putenv
400 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
403 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
405 #define setenv rk_setenv
407 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
410 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
411 #ifndef HAVE_UNSETENV
412 #define unsetenv rk_unsetenv
414 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
417 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
418 #ifndef HAVE_GETUSERSHELL
419 #define getusershell rk_getusershell
420 #define endusershell rk_endusershell
422 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
423 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
426 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
427 #ifndef HAVE_SNPRINTF
428 #define snprintf rk_snprintf
430 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
431 rk_snprintf (char *, size_t, const char *, ...)
432 __attribute__ ((format (printf
, 3, 4)));
435 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
436 #ifndef HAVE_VSNPRINTF
437 #define vsnprintf rk_vsnprintf
439 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
440 rk_vsnprintf (char *, size_t, const char *, va_list)
441 __attribute__((format (printf
, 3, 0)));
444 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
445 #ifndef HAVE_ASPRINTF
446 #define asprintf rk_asprintf
448 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
449 rk_asprintf (char **, const char *, ...)
450 __attribute__ ((format (printf
, 2, 3)));
453 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
454 #ifndef HAVE_VASPRINTF
455 #define vasprintf rk_vasprintf
457 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
458 rk_vasprintf (char **, const char *, va_list)
459 __attribute__((format (printf
, 2, 0)));
462 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
463 #ifndef HAVE_ASNPRINTF
464 #define asnprintf rk_asnprintf
466 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
467 rk_asnprintf (char **, size_t, const char *, ...)
468 __attribute__ ((format (printf
, 3, 4)));
471 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
472 #ifndef HAVE_VASNPRINTF
473 #define vasnprintf rk_vasnprintf
475 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
476 vasnprintf (char **, size_t, const char *, va_list)
477 __attribute__((format (printf
, 3, 0)));
481 #define strdup rk_strdup
482 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
485 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
487 #define strndup rk_strndup
489 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
493 #define strlwr rk_strlwr
494 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
498 #define strnlen rk_strnlen
499 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
502 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
504 #define strsep rk_strsep
506 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
509 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
510 #ifndef HAVE_STRSEP_COPY
511 #define strsep_copy rk_strsep_copy
513 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
516 #ifndef HAVE_STRCASECMP
517 #define strcasecmp rk_strcasecmp
518 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
521 #ifdef NEED_FCLOSE_PROTO
522 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
525 #ifdef NEED_STRTOK_R_PROTO
526 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
530 #define strupr rk_strupr
531 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
535 #define strlcpy rk_strlcpy
536 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
540 #define strlcat rk_strlcat
541 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
544 #ifndef HAVE_GETDTABLESIZE
545 #define getdtablesize rk_getdtablesize
546 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
549 #if !defined(HAVE_STRERROR) && !defined(strerror)
550 #define strerror rk_strerror
551 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
554 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
555 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
557 #define rk_strerror_r strerror_r
560 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
561 #ifndef HAVE_HSTRERROR
562 #define hstrerror rk_hstrerror
564 /* This causes a fatal error under Psoriasis */
566 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
570 #if !HAVE_DECL_H_ERRNO
574 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
575 #ifndef HAVE_INET_ATON
576 #define inet_aton rk_inet_aton
578 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
581 #ifndef HAVE_INET_NTOP
582 #define inet_ntop rk_inet_ntop
583 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
584 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
587 #ifndef HAVE_INET_PTON
588 #define inet_pton rk_inet_pton
589 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
590 inet_pton(int, const char *, void *);
594 #define getcwd rk_getcwd
595 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
600 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
601 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
604 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
607 #define seteuid rk_seteuid
608 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
612 #define setegid rk_setegid
613 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
617 #define lstat rk_lstat
618 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
621 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
623 #define mkstemp rk_mkstemp
625 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
629 #define cgetent rk_cgetent
630 #define cgetstr rk_cgetstr
631 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
632 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
635 #ifndef HAVE_INITGROUPS
636 #define initgroups rk_initgroups
637 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
641 #define fchown rk_fchown
642 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
645 #ifdef RENAME_DOES_NOT_UNLINK
646 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_rename(const char *, const char *);
648 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
651 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
653 #define daemon rk_daemon
655 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
659 #define chown rk_chown
660 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
665 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
666 rcmd(char **, unsigned short, const char *,
667 const char *, const char *, int *);
670 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
672 #define innetgr rk_innetgr
674 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
675 const char*, const char*);
678 #ifndef HAVE_IRUSEROK
679 #define iruserok rk_iruserok
680 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
681 const char *, const char *);
684 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
685 #ifndef HAVE_GETHOSTNAME
686 #define gethostname rk_gethostname
688 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
692 #define writev rk_writev
693 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
694 writev(int, const struct iovec
*, int);
698 #define readv rk_readv
699 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
700 readv(int, const struct iovec
*, int);
705 #define pidfile(x) ((void) 0)
707 #define pidfile rk_pidfile
708 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
713 #define bswap32 rk_bswap32
714 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
718 #define bswap16 rk_bswap16
719 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
724 #define LOCK_SH 1 /* Shared lock */
727 #define LOCK_EX 2 /* Exclusive lock */
730 #define LOCK_NB 4 /* Don't block when locking */
733 #define LOCK_UN 8 /* Unlock */
736 #define flock(_x,_y) rk_flock(_x,_y)
737 int rk_flock(int fd
, int operation
);
738 #endif /* HAVE_FLOCK */
741 #ifdef HAVE_DIR_DD_FD
742 #define dirfd(x) ((x)->dd_fd)
744 #ifndef _WIN32 /* Windows code never calls dirfd */
745 #error Missing dirfd() and ->dd_fd
750 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
752 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
754 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
756 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
758 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
760 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
761 roken_vmconcat (char **, size_t, va_list);
763 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
764 net_write (rk_socket_t
, const void *, size_t);
766 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
767 net_read (rk_socket_t
, void *, size_t);
769 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
772 #ifndef HAVE_STRUCT_WINSIZE
774 unsigned short ws_row
, ws_col
;
775 unsigned short ws_xpixel
, ws_ypixel
;
779 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, int *, int *);
782 #define vsyslog rk_vsyslog
783 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
787 #define getopt rk_getopt
788 #define optarg rk_optarg
789 #define optind rk_optind
790 #define opterr rk_opterr
791 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
792 getopt(int nargc
, char * const *nargv
, const char *ostr
);
795 #if !HAVE_DECL_OPTARG
796 ROKEN_LIB_VARIABLE
extern char *optarg
;
798 #if !HAVE_DECL_OPTIND
799 ROKEN_LIB_VARIABLE
extern int optind
;
801 #if !HAVE_DECL_OPTERR
802 ROKEN_LIB_VARIABLE
extern int opterr
;
805 #ifndef HAVE_GETIPNODEBYNAME
806 #define getipnodebyname rk_getipnodebyname
807 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
808 getipnodebyname (const char *, int, int, int *);
811 #ifndef HAVE_GETIPNODEBYADDR
812 #define getipnodebyaddr rk_getipnodebyaddr
813 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
814 getipnodebyaddr (const void *, size_t, int, int *);
817 #ifndef HAVE_FREEHOSTENT
818 #define freehostent rk_freehostent
819 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
820 freehostent (struct hostent
*);
823 #ifndef HAVE_COPYHOSTENT
824 #define copyhostent rk_copyhostent
825 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
826 copyhostent (const struct hostent
*);
829 #ifndef HAVE_SOCKLEN_T
830 typedef int socklen_t
;
833 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
835 #ifndef HAVE_SA_FAMILY_T
836 typedef unsigned short sa_family_t
;
840 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
842 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
845 #define _SS_ALIGNSIZE sizeof(unsigned long)
847 #if HAVE_STRUCT_SOCKADDR_SA_LEN
849 typedef unsigned char roken_sa_family_t
;
851 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
852 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
854 struct sockaddr_storage
{
855 unsigned char ss_len
;
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 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
863 typedef unsigned short roken_sa_family_t
;
865 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
866 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
868 struct sockaddr_storage
{
869 roken_sa_family_t ss_family
;
870 char __ss_pad1
[_SS_PAD1SIZE
];
871 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
874 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
876 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
878 #ifndef HAVE_STRUCT_ADDRINFO
886 struct sockaddr
*ai_addr
;
887 struct addrinfo
*ai_next
;
891 #ifndef HAVE_GETADDRINFO
892 #define getaddrinfo rk_getaddrinfo
893 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
894 getaddrinfo(const char *,
896 const struct addrinfo
*,
900 #ifndef HAVE_GETNAMEINFO
901 #define getnameinfo rk_getnameinfo
902 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
903 getnameinfo(const struct sockaddr
*, socklen_t
,
909 #ifndef HAVE_FREEADDRINFO
910 #define freeaddrinfo rk_freeaddrinfo
911 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
912 freeaddrinfo(struct addrinfo
*);
915 #ifndef HAVE_GAI_STRERROR
916 #define gai_strerror rk_gai_strerror
917 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
923 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
924 sleep(unsigned int seconds
);
928 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
929 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
934 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
935 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
936 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
937 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
939 #ifndef HAVE_STRFTIME
940 #define strftime rk_strftime
941 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
942 strftime (char *, size_t, const char *, const struct tm
*);
945 #ifndef HAVE_STRPTIME
946 #define strptime rk_strptime
947 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
948 strptime (const char *, const char *, struct tm
*);
951 #ifndef HAVE_GETTIMEOFDAY
952 #define gettimeofday rk_gettimeofday
953 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
954 gettimeofday (struct timeval
*, void *);
958 #define emalloc rk_emalloc
959 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
962 #define ecalloc rk_ecalloc
963 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
965 #ifndef HAVE_EREALLOC
966 #define erealloc rk_erealloc
967 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
970 #define estrdup rk_estrdup
971 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
978 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
979 roken_gethostby_setup(const char*, const char*);
980 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
981 roken_gethostbyname(const char*);
982 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
983 roken_gethostbyaddr(const void*, size_t, int);
985 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
986 #define roken_getservbyname(x,y) getservbyname(x,y)
988 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
991 #ifdef OPENLOG_PROTO_COMPATIBLE
992 #define roken_openlog(a,b,c) openlog(a,b,c)
994 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
997 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
998 #define roken_getsockname(a,b,c) getsockname(a,b,c)
1000 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1003 #ifndef HAVE_SETPROGNAME
1004 #define setprogname rk_setprogname
1005 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
1008 #ifndef HAVE_GETPROGNAME
1009 #define getprogname rk_getprogname
1010 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
1013 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1014 extern const char *__progname
;
1017 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1018 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
1020 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1021 mini_inetd (int, rk_socket_t
*);
1023 #ifndef HAVE_LOCALTIME_R
1024 #define localtime_r rk_localtime_r
1025 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
1026 localtime_r(const time_t *, struct tm
*);
1029 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1030 #ifndef HAVE_STRSVIS
1031 #define strsvis rk_strsvis
1033 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1034 strsvis(char *, const char *, int, const char *);
1037 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1038 #ifndef HAVE_STRSVISX
1039 #define strsvisx rk_strsvisx
1041 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1042 strsvisx(char *, const char *, size_t, int, const char *);
1045 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1046 #ifndef HAVE_STRUNVIS
1047 #define strunvis rk_strunvis
1049 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1050 strunvis(char *, const char *);
1053 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1055 #define strvis rk_strvis
1057 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1058 strvis(char *, const char *, int);
1061 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1062 #ifndef HAVE_STRVISX
1063 #define strvisx rk_strvisx
1065 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1066 strvisx(char *, const char *, size_t, int);
1069 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1071 #define svis rk_svis
1073 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1074 svis(char *, int, int, int, const char *);
1077 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1079 #define unvis rk_unvis
1081 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1082 unvis(char *, int, int *, int);
1085 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1089 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1090 vis(char *, int, int, int);
1093 #if !defined(HAVE_CLOSEFROM)
1094 #define closefrom rk_closefrom
1095 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1099 #if !defined(HAVE_TIMEGM)
1100 #define timegm rk_timegm
1101 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1102 rk_timegm(struct tm
*tm
);
1106 #define qsort rk_qsort
1108 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1111 #if defined(HAVE_ARC4RANDOM)
1112 #define rk_random() arc4random()
1113 #elif defined(HAVE_RANDOM)
1114 #define rk_random() random()
1116 #define rk_random() rand()
1119 #ifndef HAVE_TDELETE
1120 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1123 #define tfind(a,b,c) rk_tfind(a,b,c)
1125 #ifndef HAVE_TSEARCH
1126 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1129 #define twalk(a,b) rk_twalk(a,b)
1132 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1134 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1135 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1138 #ifdef SOCKET_WRAPPER_REPLACE
1139 #include <socket_wrapper.h>