3 * Copyright (c) 1995-2005 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #ifndef ROKEN_LIB_FUNCTION
46 # define ROKEN_LIB_CALL __cdecl
47 # ifdef ROKEN_LIB_DYNAMIC
48 # define ROKEN_LIB_FUNCTION __declspec(dllimport)
49 # define ROKEN_LIB_VARIABLE __declspec(dllimport)
51 # define ROKEN_LIB_FUNCTION
52 # define ROKEN_LIB_VARIABLE
55 #define ROKEN_LIB_FUNCTION
56 #define ROKEN_LIB_CALL
57 #define ROKEN_LIB_VARIABLE
62 /* Declarations for Microsoft Windows */
68 * error codes for inet_ntop/inet_pton
70 #define EAFNOSUPPORT WSAEAFNOSUPPORT
72 typedef SOCKET rk_socket_t
;
74 #define rk_closesocket(x) closesocket(x)
75 #define rk_INVALID_SOCKET INVALID_SOCKET
76 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
77 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
78 #define rk_SOCK_ERRNO WSAGetLastError()
80 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_SOCK_IOCTL(SOCKET s
, long cmd
, int * argp
);
82 #define ETIMEDOUT WSAETIMEDOUT
83 #define EWOULDBLOCK WSAEWOULDBLOCK
84 #define ENOTSOCK WSAENOTSOCK
86 #define rk_SOCK_INIT() rk_WSAStartup()
87 #define rk_SOCK_EXIT() rk_WSACleanup()
89 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSAStartup(void);
90 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_WSACleanup(void);
92 #else /* not WinSock */
94 typedef int rk_socket_t
;
96 #define rk_closesocket(x) close(x)
97 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
98 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
99 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
100 #define rk_SOCK_ERRNO errno
101 #define rk_INVALID_SOCKET (-1)
103 #define rk_SOCK_INIT() 0
104 #define rk_SOCK_EXIT() do { } while(0)
109 /* Declarations for Microsoft Visual C runtime on Windows */
115 #ifndef __BIT_TYPES_DEFINED__
116 #define __BIT_TYPES_DEFINED__
118 typedef __int8
int8_t;
119 typedef __int16
int16_t;
120 typedef __int32
int32_t;
121 typedef __int64
int64_t;
122 typedef unsigned __int8
uint8_t;
123 typedef unsigned __int16
uint16_t;
124 typedef unsigned __int32
uint32_t;
125 typedef unsigned __int64
uint64_t;
126 typedef uint8_t u_int8_t
;
127 typedef uint16_t u_int16_t
;
128 typedef uint32_t u_int32_t
;
129 typedef uint64_t u_int64_t
;
131 #endif /* __BIT_TYPES_DEFINED__ */
133 #define UNREACHABLE(x) x
134 #define UNUSED_ARGUMENT(x) ((void) x)
136 #define RETSIGTYPE void
138 #define VOID_RETSIGTYPE 1
140 #ifdef VOID_RETSIGTYPE
141 #define SIGRETURN(x) return
143 #define SIGRETURN(x) return (RETSIGTYPE)(x)
150 typedef unsigned int gid_t
;
152 typedef unsigned int uid_t
;
154 typedef unsigned short mode_t
;
159 #define inline __inline
164 #define UNREACHABLE(x)
165 #define UNUSED_ARGUMENT(x)
173 #ifdef HAVE_SYS_PARAM_H
174 #include <sys/param.h>
176 #ifdef HAVE_INTTYPES_H
177 #include <inttypes.h>
179 #ifdef HAVE_SYS_TYPES_H
180 #include <sys/types.h>
182 #ifdef HAVE_SYS_BITYPES_H
183 #include <sys/bitypes.h>
185 #ifdef HAVE_BIND_BITYPES_H
186 #include <bind/bitypes.h>
188 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
189 #include <netinet/in6_machtypes.h>
194 #ifdef HAVE_SYS_SOCKET_H
195 #include <sys/socket.h>
197 #ifdef HAVE_SYS_UIO_H
203 #ifdef HAVE_SYS_STAT_H
204 #include <sys/stat.h>
206 #ifdef HAVE_NETINET_IN_H
207 #include <netinet/in.h>
209 #ifdef HAVE_NETINET_IN6_H
210 #include <netinet/in6.h>
212 #ifdef HAVE_NETINET6_IN6_H
213 #include <netinet6/in6.h>
215 #ifdef HAVE_ARPA_INET_H
216 #include <arpa/inet.h>
221 #ifdef HAVE_ARPA_NAMESER_H
222 #include <arpa/nameser.h>
237 #ifdef HAVE_TERMIOS_H
240 #ifdef HAVE_SYS_IOCTL_H
241 #include <sys/ioctl.h>
243 #ifdef TIME_WITH_SYS_TIME
244 #include <sys/time.h>
246 #elif defined(HAVE_SYS_TIME_H)
247 #include <sys/time.h>
260 #ifdef BACKSLASH_PATH_DELIM
261 #define rk_PATH_DELIM '\\'
265 #ifndef SSIZE_T_DEFINED
270 typedef __int64 ssize_t
;
274 #define SSIZE_T_DEFINED
275 #endif /* SSIZE_T_DEFINED */
276 #endif /* HAVE_SSIZE_T */
278 #include <roken-common.h>
282 #ifdef HAVE_UINTPTR_T
283 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
285 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
288 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
289 #define setsid _setsid
293 /* Additional macros for Visual C/C++ runtime */
297 #define getpid _getpid
303 #define fsync _commit
305 /* The MSVC implementation of snprintf is not C99 compliant. */
306 #define snprintf rk_snprintf
307 #define vsnprintf rk_vsnprintf
308 #define vasnprintf rk_vasnprintf
309 #define vasprintf rk_vasprintf
310 #define asnprintf rk_asnprintf
311 #define asprintf rk_asprintf
313 #define _PIPE_BUFFER_SZ 8192
314 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
316 #define ftruncate(fd, sz) _chsize((fd), (sz))
318 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
319 rk_snprintf (char *str
, size_t sz
, const char *format
, ...);
321 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
322 rk_asprintf (char **ret
, const char *format
, ...);
324 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
325 rk_asnprintf (char **ret
, size_t max_sz
, const char *format
, ...);
327 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
328 rk_vasprintf (char **ret
, const char *format
, va_list args
);
330 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
331 rk_vasnprintf (char **ret
, size_t max_sz
, const char *format
, va_list args
);
333 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
334 rk_vsnprintf (char *str
, size_t sz
, const char *format
, va_list args
);
336 /* missing stat.h predicates */
338 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
340 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
342 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
344 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
346 /* The following are not implemented:
353 #endif /* _MSC_VER */
357 /* While we are at it, define WinSock specific scatter gather socket
360 #define iovec _WSABUF
366 socklen_t msg_namelen
;
367 struct iovec
*msg_iov
;
370 socklen_t msg_controllen
;
374 #define sendmsg sendmsg_w32
376 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
377 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
);
379 #endif /* HAVE_WINSOCK */
382 #define putenv rk_putenv
383 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
putenv(const char *);
386 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
388 #define setenv rk_setenv
390 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setenv(const char *, const char *, int);
393 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
394 #ifndef HAVE_UNSETENV
395 #define unsetenv rk_unsetenv
397 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
unsetenv(const char *);
400 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
401 #ifndef HAVE_GETUSERSHELL
402 #define getusershell rk_getusershell
403 #define endusershell rk_endusershell
405 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
getusershell(void);
406 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
endusershell(void);
409 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
410 #ifndef HAVE_SNPRINTF
411 #define snprintf rk_snprintf
413 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
414 rk_snprintf (char *, size_t, const char *, ...)
415 __attribute__ ((format (printf
, 3, 4)));
418 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
419 #ifndef HAVE_VSNPRINTF
420 #define vsnprintf rk_vsnprintf
422 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
423 rk_vsnprintf (char *, size_t, const char *, va_list)
424 __attribute__((format (printf
, 3, 0)));
427 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
428 #ifndef HAVE_ASPRINTF
429 #define asprintf rk_asprintf
431 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
432 rk_asprintf (char **, const char *, ...)
433 __attribute__ ((format (printf
, 2, 3)));
436 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
437 #ifndef HAVE_VASPRINTF
438 #define vasprintf rk_vasprintf
440 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
441 rk_vasprintf (char **, const char *, va_list)
442 __attribute__((format (printf
, 2, 0)));
445 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
446 #ifndef HAVE_ASNPRINTF
447 #define asnprintf rk_asnprintf
449 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
450 rk_asnprintf (char **, size_t, const char *, ...)
451 __attribute__ ((format (printf
, 3, 4)));
454 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
455 #ifndef HAVE_VASNPRINTF
456 #define vasnprintf rk_vasnprintf
458 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
459 vasnprintf (char **, size_t, const char *, va_list)
460 __attribute__((format (printf
, 3, 0)));
464 #define strdup rk_strdup
465 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strdup(const char *);
468 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
470 #define strndup rk_strndup
472 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strndup(const char *, size_t);
476 #define strlwr rk_strlwr
477 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strlwr(char *);
481 #define strnlen rk_strnlen
482 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strnlen(const char*, size_t);
485 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
487 #define strsep rk_strsep
489 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strsep(char**, const char*);
492 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
493 #ifndef HAVE_STRSEP_COPY
494 #define strsep_copy rk_strsep_copy
496 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
strsep_copy(const char**, const char*, char*, size_t);
499 #ifndef HAVE_STRCASECMP
500 #define strcasecmp rk_strcasecmp
501 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
strcasecmp(const char *, const char *);
504 #ifdef NEED_FCLOSE_PROTO
505 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fclose(FILE *);
508 #ifdef NEED_STRTOK_R_PROTO
509 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strtok_r(char *, const char *, char **);
513 #define strupr rk_strupr
514 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strupr(char *);
518 #define strlcpy rk_strlcpy
519 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcpy (char *, const char *, size_t);
523 #define strlcat rk_strlcat
524 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
strlcat (char *, const char *, size_t);
527 #ifndef HAVE_GETDTABLESIZE
528 #define getdtablesize rk_getdtablesize
529 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
getdtablesize(void);
532 #if !defined(HAVE_STRERROR) && !defined(strerror)
533 #define strerror rk_strerror
534 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
strerror(int);
537 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
538 int ROKEN_LIB_FUNCTION
rk_strerror_r(int, char *, size_t);
540 #define rk_strerror_r strerror_r
543 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
544 #ifndef HAVE_HSTRERROR
545 #define hstrerror rk_hstrerror
547 /* This causes a fatal error under Psoriasis */
549 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
hstrerror(int);
553 #if !HAVE_DECL_H_ERRNO
557 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
558 #ifndef HAVE_INET_ATON
559 #define inet_aton rk_inet_aton
561 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
inet_aton(const char *, struct in_addr
*);
564 #ifndef HAVE_INET_NTOP
565 #define inet_ntop rk_inet_ntop
566 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
567 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
570 #ifndef HAVE_INET_PTON
571 #define inet_pton rk_inet_pton
572 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
573 inet_pton(int, const char *, void *);
577 #define getcwd rk_getcwd
578 ROKEN_LIB_FUNCTION
char* ROKEN_LIB_CALL
getcwd(char *, size_t);
583 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwnam (const char *);
584 ROKEN_LIB_FUNCTION
struct passwd
* ROKEN_LIB_CALL
k_getpwuid (uid_t
);
587 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
get_default_username (void);
590 #define seteuid rk_seteuid
591 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
seteuid(uid_t
);
595 #define setegid rk_setegid
596 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
setegid(gid_t
);
600 #define lstat rk_lstat
601 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
lstat(const char *, struct stat
*);
604 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
606 #define mkstemp rk_mkstemp
608 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
mkstemp(char *);
612 #define cgetent rk_cgetent
613 #define cgetstr rk_cgetstr
614 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetent(char **, char **, const char *);
615 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
cgetstr(char *, const char *, char **);
618 #ifndef HAVE_INITGROUPS
619 #define initgroups rk_initgroups
620 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
initgroups(const char *, gid_t
);
624 #define fchown rk_fchown
625 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
fchown(int, uid_t
, gid_t
);
628 #ifdef RENAME_DOES_NOT_UNLINK
629 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
rk_rename(const char *, const char *);
631 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
634 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
636 #define daemon rk_daemon
638 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
daemon(int, int);
642 #define chown rk_chown
643 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
chown(const char *, uid_t
, gid_t
);
648 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
649 rcmd(char **, unsigned short, const char *,
650 const char *, const char *, int *);
653 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
655 #define innetgr rk_innetgr
657 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
innetgr(const char*, const char*,
658 const char*, const char*);
661 #ifndef HAVE_IRUSEROK
662 #define iruserok rk_iruserok
663 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
iruserok(unsigned, int,
664 const char *, const char *);
667 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
668 #ifndef HAVE_GETHOSTNAME
669 #define gethostname rk_gethostname
671 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
gethostname(char *, int);
675 #define writev rk_writev
676 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
677 writev(int, const struct iovec
*, int);
681 #define readv rk_readv
682 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
683 readv(int, const struct iovec
*, int);
688 #define pidfile(x) ((void) 0)
690 #define pidfile rk_pidfile
691 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
pidfile (const char*);
696 #define bswap32 rk_bswap32
697 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
bswap32(unsigned int);
701 #define bswap16 rk_bswap16
702 ROKEN_LIB_FUNCTION
unsigned short ROKEN_LIB_CALL
bswap16(unsigned short);
707 #define LOCK_SH 1 /* Shared lock */
710 #define LOCK_EX 2 /* Exclusive lock */
713 #define LOCK_NB 4 /* Don't block when locking */
716 #define LOCK_UN 8 /* Unlock */
719 #define flock(_x,_y) rk_flock(_x,_y)
720 int rk_flock(int fd
, int operation
);
721 #endif /* HAVE_FLOCK */
724 #ifdef HAVE_DIR_DD_FD
725 #define dirfd(x) ((x)->dd_fd)
727 #ifndef _WIN32 /* Windows code never calls dirfd */
728 #error Missing dirfd() and ->dd_fd
733 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
tm2time (struct tm
, int);
735 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
unix_verify_user(char *, char *);
737 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_concat (char *, size_t, ...);
739 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
roken_mconcat (char **, size_t, ...);
741 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
roken_vconcat (char *, size_t, va_list);
743 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
744 roken_vmconcat (char **, size_t, va_list);
746 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
747 net_write (rk_socket_t
, const void *, size_t);
749 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
750 net_read (rk_socket_t
, void *, size_t);
752 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
755 #ifndef HAVE_STRUCT_WINSIZE
757 unsigned short ws_row
, ws_col
;
758 unsigned short ws_xpixel
, ws_ypixel
;
762 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
get_window_size(int fd
, struct winsize
*);
765 #define vsyslog rk_vsyslog
766 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
vsyslog(int, const char *, va_list);
770 #define getopt rk_getopt
771 #define optarg rk_optarg
772 #define optind rk_optind
773 #define opterr rk_opterr
774 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
775 getopt(int nargc
, char * const *nargv
, const char *ostr
);
778 #if !HAVE_DECL_OPTARG
779 ROKEN_LIB_VARIABLE
extern char *optarg
;
781 #if !HAVE_DECL_OPTIND
782 ROKEN_LIB_VARIABLE
extern int optind
;
784 #if !HAVE_DECL_OPTERR
785 ROKEN_LIB_VARIABLE
extern int opterr
;
788 #ifndef HAVE_GETIPNODEBYNAME
789 #define getipnodebyname rk_getipnodebyname
790 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
791 getipnodebyname (const char *, int, int, int *);
794 #ifndef HAVE_GETIPNODEBYADDR
795 #define getipnodebyaddr rk_getipnodebyaddr
796 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
797 getipnodebyaddr (const void *, size_t, int, int *);
800 #ifndef HAVE_FREEHOSTENT
801 #define freehostent rk_freehostent
802 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
803 freehostent (struct hostent
*);
806 #ifndef HAVE_COPYHOSTENT
807 #define copyhostent rk_copyhostent
808 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
809 copyhostent (const struct hostent
*);
812 #ifndef HAVE_SOCKLEN_T
813 typedef int socklen_t
;
816 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
818 #ifndef HAVE_SA_FAMILY_T
819 typedef unsigned short sa_family_t
;
823 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
825 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
828 #define _SS_ALIGNSIZE sizeof(unsigned long)
830 #if HAVE_STRUCT_SOCKADDR_SA_LEN
832 typedef unsigned char roken_sa_family_t
;
834 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
835 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
837 struct sockaddr_storage
{
838 unsigned char ss_len
;
839 roken_sa_family_t ss_family
;
840 char __ss_pad1
[_SS_PAD1SIZE
];
841 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
844 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
846 typedef unsigned short roken_sa_family_t
;
848 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
849 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
851 struct sockaddr_storage
{
852 roken_sa_family_t ss_family
;
853 char __ss_pad1
[_SS_PAD1SIZE
];
854 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
857 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
859 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
861 #ifndef HAVE_STRUCT_ADDRINFO
869 struct sockaddr
*ai_addr
;
870 struct addrinfo
*ai_next
;
874 #ifndef HAVE_GETADDRINFO
875 #define getaddrinfo rk_getaddrinfo
876 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
877 getaddrinfo(const char *,
879 const struct addrinfo
*,
883 #ifndef HAVE_GETNAMEINFO
884 #define getnameinfo rk_getnameinfo
885 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
886 getnameinfo(const struct sockaddr
*, socklen_t
,
892 #ifndef HAVE_FREEADDRINFO
893 #define freeaddrinfo rk_freeaddrinfo
894 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
895 freeaddrinfo(struct addrinfo
*);
898 #ifndef HAVE_GAI_STRERROR
899 #define gai_strerror rk_gai_strerror
900 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
906 ROKEN_LIB_FUNCTION
unsigned int ROKEN_LIB_CALL
907 sleep(unsigned int seconds
);
911 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
912 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
917 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
918 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
919 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
920 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
922 #ifndef HAVE_STRFTIME
923 #define strftime rk_strftime
924 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
925 strftime (char *, size_t, const char *, const struct tm
*);
928 #ifndef HAVE_STRPTIME
929 #define strptime rk_strptime
930 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
931 strptime (const char *, const char *, struct tm
*);
934 #ifndef HAVE_GETTIMEOFDAY
935 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
936 gettimeofday (struct timeval
*, void *);
940 #define emalloc rk_emalloc
941 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
emalloc (size_t);
944 #define ecalloc rk_ecalloc
945 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
ecalloc(size_t, size_t);
947 #ifndef HAVE_EREALLOC
948 #define erealloc rk_erealloc
949 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
erealloc (void *, size_t);
952 #define estrdup rk_estrdup
953 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
estrdup (const char *);
960 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
961 roken_gethostby_setup(const char*, const char*);
962 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
963 roken_gethostbyname(const char*);
964 ROKEN_LIB_FUNCTION
struct hostent
* ROKEN_LIB_CALL
965 roken_gethostbyaddr(const void*, size_t, int);
967 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
968 #define roken_getservbyname(x,y) getservbyname(x,y)
970 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
973 #ifdef OPENLOG_PROTO_COMPATIBLE
974 #define roken_openlog(a,b,c) openlog(a,b,c)
976 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
979 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
980 #define roken_getsockname(a,b,c) getsockname(a,b,c)
982 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
985 #ifndef HAVE_SETPROGNAME
986 #define setprogname rk_setprogname
987 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
setprogname(const char *);
990 #ifndef HAVE_GETPROGNAME
991 #define getprogname rk_getprogname
992 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
getprogname(void);
995 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
996 extern const char *__progname
;
999 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1000 mini_inetd_addrinfo (struct addrinfo
*, rk_socket_t
*);
1002 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
1003 mini_inetd (int, rk_socket_t
*);
1005 #ifndef HAVE_LOCALTIME_R
1006 #define localtime_r rk_localtime_r
1007 ROKEN_LIB_FUNCTION
struct tm
* ROKEN_LIB_CALL
1008 localtime_r(const time_t *, struct tm
*);
1011 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1012 #ifndef HAVE_STRSVIS
1013 #define strsvis rk_strsvis
1015 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1016 strsvis(char *, const char *, int, const char *);
1019 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1020 #ifndef HAVE_STRSVISX
1021 #define strsvisx rk_strsvisx
1023 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1024 strsvisx(char *, const char *, size_t, int, const char *);
1027 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1028 #ifndef HAVE_STRUNVIS
1029 #define strunvis rk_strunvis
1031 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1032 strunvis(char *, const char *);
1035 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1037 #define strvis rk_strvis
1039 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1040 strvis(char *, const char *, int);
1043 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1044 #ifndef HAVE_STRVISX
1045 #define strvisx rk_strvisx
1047 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1048 strvisx(char *, const char *, size_t, int);
1051 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1053 #define svis rk_svis
1055 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1056 svis(char *, int, int, int, const char *);
1059 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1061 #define unvis rk_unvis
1063 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1064 unvis(char *, int, int *, int);
1067 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1071 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
1072 vis(char *, int, int, int);
1075 #if !defined(HAVE_CLOSEFROM)
1076 #define closefrom rk_closefrom
1077 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
1081 #if !defined(HAVE_TIMEGM)
1082 #define timegm rk_timegm
1083 ROKEN_LIB_FUNCTION
time_t ROKEN_LIB_CALL
1084 rk_timegm(struct tm
*tm
);
1088 #define qsort rk_qsort
1090 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1093 #if defined(HAVE_ARC4RANDOM)
1094 #define rk_random() arc4random()
1095 #elif defined(HAVE_RANDOM)
1096 #define rk_random() random()
1098 #define rk_random() rand()
1102 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1104 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1105 int ROKEN_LIB_FUNCTION
rk_socket(int, int, int);
1108 #ifdef SOCKET_WRAPPER_REPLACE
1109 #include <socket_wrapper.h>