1 /* -*- C -*- */ 2 /* 3 * Copyright (c) 1995-2005 Kungliga Tekniska Hgskolan 4 * (Royal Institute of Technology, Stockholm, Sweden). 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 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. 17 * 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. 21 * 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 32 * SUCH DAMAGE. 33 */ 34 35 #if defined(_WIN32) && _MSC_VER >= 1400 36 /* _CRT_RAND_S must be defined before including stdlib.h */ 37 # define _CRT_RAND_S 38 # define HAVE_WIN32_RAND_S 1 39 #endif 40 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <stdarg.h> 44 #ifdef HAVE_STDINT_H 45 #include <stdint.h> 46 #endif 47 #include <string.h> 48 #include <limits.h> 49 #include <signal.h> 50 51 #ifndef ROKEN_LIB_FUNCTION 52 #ifdef _WIN32 53 # define ROKEN_LIB_CALL __cdecl 54 # ifdef ROKEN_LIB_DYNAMIC 55 # define ROKEN_LIB_FUNCTION __declspec(dllimport) 56 # define ROKEN_LIB_VARIABLE __declspec(dllimport) 57 # else 58 # define ROKEN_LIB_FUNCTION 59 # define ROKEN_LIB_VARIABLE 60 # endif 61 #else 62 #define ROKEN_LIB_FUNCTION 63 #define ROKEN_LIB_CALL 64 #define ROKEN_LIB_VARIABLE 65 #endif 66 #endif 67 68 #ifdef HAVE_WINSOCK 69 /* Declarations for Microsoft Windows */ 70 71 #include <winsock2.h> 72 #include <ws2tcpip.h> 73 74 /* 75 * error codes for inet_ntop/inet_pton 76 */ 77 typedef SOCKET rk_socket_t; 78 79 #define rk_closesocket(x) closesocket(x) 80 #define rk_INVALID_SOCKET INVALID_SOCKET 81 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET) 82 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR) 83 #define rk_SOCK_ERRNO WSAGetLastError() 84 85 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp); 86 87 #define rk_SOCK_INIT() rk_WSAStartup() 88 #define rk_SOCK_EXIT() rk_WSACleanup() 89 90 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void); 91 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void); 92 93 #else /* not WinSock */ 94 95 typedef int rk_socket_t; 96 97 #define rk_closesocket(x) close(x) 98 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a)) 99 #define rk_IS_BAD_SOCKET(s) ((s) < 0) 100 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0) 101 #define rk_SOCK_ERRNO errno 102 #define rk_INVALID_SOCKET (-1) 103 104 #define rk_SOCK_INIT() 0 105 #define rk_SOCK_EXIT() do { } while(0) 106 107 #endif /* WinSock */ 108 109 #ifndef IN_LOOPBACKNET 110 #define IN_LOOPBACKNET 127 111 #endif 112 113 #ifdef _MSC_VER 114 #ifndef HAVE_STDINT_H 115 #include <intsafe.h> 116 #endif 117 118 /* Declarations for Microsoft Visual C runtime on Windows */ 119 120 #include<process.h> 121 122 #include<io.h> 123 124 #ifndef __BIT_TYPES_DEFINED__ 125 #define __BIT_TYPES_DEFINED__ 126 127 typedef __int8 int8_t; 128 typedef __int16 int16_t; 129 typedef __int32 int32_t; 130 typedef __int64 int64_t; 131 typedef unsigned __int8 uint8_t; 132 typedef unsigned __int16 uint16_t; 133 typedef unsigned __int32 uint32_t; 134 typedef unsigned __int64 uint64_t; 135 typedef uint8_t u_int8_t; 136 typedef uint16_t u_int16_t; 137 typedef uint32_t u_int32_t; 138 typedef uint64_t u_int64_t; 139 140 #endif /* __BIT_TYPES_DEFINED__ */ 141 142 #define UNREACHABLE(x) x 143 #define UNUSED_ARGUMENT(x) ((void) x) 144 145 #define RETSIGTYPE void 146 147 #define VOID_RETSIGTYPE 1 148 149 #ifdef VOID_RETSIGTYPE 150 #define SIGRETURN(x) return 151 #else 152 #define SIGRETURN(x) return (RETSIGTYPE)(x) 153 #endif 154 155 #ifndef CPP_ONLY 156 157 typedef int pid_t; 158 159 typedef unsigned int gid_t; 160 161 typedef unsigned int uid_t; 162 163 typedef unsigned short mode_t; 164 165 #endif 166 167 #ifndef __cplusplus 168 #define inline __inline 169 #endif 170 171 #else 172 173 #define UNREACHABLE(x) 174 #define UNUSED_ARGUMENT(x) 175 176 #endif 177 178 #ifdef _AIX 179 struct ether_addr; 180 struct sockaddr_dl; 181 #endif 182 #ifdef HAVE_SYS_PARAM_H 183 #include <sys/param.h> 184 #endif 185 #ifdef HAVE_INTTYPES_H 186 #include <inttypes.h> 187 #endif 188 #ifdef HAVE_SYS_TYPES_H 189 #include <sys/types.h> 190 #endif 191 #ifdef HAVE_SYS_ERRNO_H 192 #include <sys/errno.h> 193 #endif 194 #ifdef HAVE_SYS_BITYPES_H 195 #include <sys/bitypes.h> 196 #endif 197 #ifdef HAVE_BIND_BITYPES_H 198 #include <bind/bitypes.h> 199 #endif 200 #ifdef HAVE_NETINET_IN6_MACHTYPES_H 201 #include <netinet/in6_machtypes.h> 202 #endif 203 #ifdef HAVE_UNISTD_H 204 #include <unistd.h> 205 #endif 206 #ifdef HAVE_SYS_SOCKET_H 207 #include <sys/socket.h> 208 #endif 209 #ifdef HAVE_SYS_UIO_H 210 #include <sys/uio.h> 211 #endif 212 #ifdef HAVE_GRP_H 213 #include <grp.h> 214 #endif 215 #ifdef HAVE_SYS_STAT_H 216 #include <sys/stat.h> 217 #endif 218 #ifdef HAVE_NETINET_IN_H 219 #include <netinet/in.h> 220 #endif 221 #ifdef HAVE_NETINET_IN6_H 222 #include <netinet/in6.h> 223 #endif 224 #ifdef HAVE_NETINET6_IN6_H 225 #include <netinet6/in6.h> 226 #endif 227 #ifdef HAVE_ARPA_INET_H 228 #include <arpa/inet.h> 229 #endif 230 #ifdef HAVE_NETDB_H 231 #include <netdb.h> 232 #endif 233 #ifdef HAVE_ARPA_NAMESER_H 234 #include <arpa/nameser.h> 235 #endif 236 #ifdef HAVE_RESOLV_H 237 #include <resolv.h> 238 #endif 239 #ifdef HAVE_SYSLOG_H 240 #include <syslog.h> 241 #endif 242 #ifdef HAVE_FCNTL_H 243 #include <fcntl.h> 244 #endif 245 #ifdef HAVE_ERRNO_H 246 #include <errno.h> 247 #endif 248 #include <err.h> 249 #ifdef HAVE_TERMIOS_H 250 #include <termios.h> 251 #endif 252 #ifdef HAVE_SYS_IOCTL_H 253 #include <sys/ioctl.h> 254 #endif 255 #ifdef TIME_WITH_SYS_TIME 256 #include <sys/time.h> 257 #include <time.h> 258 #elif defined(HAVE_SYS_TIME_H) 259 #include <sys/time.h> 260 #else 261 #include <time.h> 262 #endif 263 264 #ifdef HAVE_PATHS_H 265 #include <paths.h> 266 #endif 267 268 #ifdef HAVE_DIRENT_H 269 #include <dirent.h> 270 #endif 271 272 #ifdef HAVE_DIRECT_H 273 #include <direct.h> 274 #endif 275 276 #ifdef BACKSLASH_PATH_DELIM 277 #define rk_PATH_DELIM '\\' 278 #endif 279 280 #ifndef HAVE_SSIZE_T 281 #ifndef SSIZE_T_DEFINED 282 #ifdef ssize_t 283 #undef ssize_t 284 #endif 285 #ifdef _WIN64 286 typedef __int64 ssize_t; 287 #else 288 typedef int ssize_t; 289 #endif 290 #define SSIZE_T_DEFINED 291 #endif /* SSIZE_T_DEFINED */ 292 #endif /* HAVE_SSIZE_T */ 293 294 #include <krb5/roken-common.h> 295 296 ROKEN_CPP_START 297 298 #ifdef HAVE_UINTPTR_T 299 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x)) 300 #else 301 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x)) 302 #endif 303 304 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID) 305 #define setsid _setsid 306 #endif 307 308 #ifdef _MSC_VER 309 /* Additional macros for Visual C/C++ runtime */ 310 311 #define close _close 312 313 #define getpid _getpid 314 315 #define open _open 316 317 #define chdir _chdir 318 319 #define fsync _commit 320 321 #define timezone _timezone 322 323 #define tzname _tzname 324 325 #define _PIPE_BUFFER_SZ 8192 326 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY); 327 328 #define ftruncate(fd, sz) _chsize((fd), (sz)) 329 330 #if !defined(HAVE_UCRT) 331 #define snprintf rk_snprintf 332 #define vsnprintf rk_vsnprintf 333 #define vasnprintf rk_vasnprintf 334 #define vasprintf rk_vasprintf 335 #define asnprintf rk_asnprintf 336 #define asprintf rk_asprintf 337 338 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 339 rk_snprintf (char *str, size_t sz, const char *format, ...); 340 341 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 342 rk_asprintf (char **ret, const char *format, ...); 343 344 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 345 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...); 346 347 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 348 rk_vasprintf (char **ret, const char *format, va_list args); 349 350 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 351 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args); 352 353 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 354 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args); 355 #endif /* !defined(HAVE_UCRT) */ 356 357 /* missing stat.h predicates */ 358 359 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG) 360 361 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR) 362 363 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR) 364 365 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO) 366 367 /* The following are not implemented: 368 369 S_ISLNK(m) 370 S_ISSOCK(m) 371 S_ISBLK(m) 372 */ 373 374 /* The following symbolic constants are provided for rk_mkdir mode */ 375 376 #define S_IRWXU 00700 /* user (file owner) has read, write and execute permission */ 377 #define S_IRUSR 00400 /* user has read permission */ 378 #define S_IWUSR 00200 /* user has write permission */ 379 #define S_IXUSR 00100 /* user has execute permission */ 380 #define S_IRWXG 00070 /* group has read, write and execute permission */ 381 #define S_IRGRP 00040 /* group has read permission */ 382 #define S_IWGRP 00020 /* group has write permission */ 383 #define S_IXGRP 00010 /* group has execute permission */ 384 #define S_IRWXO 00007 /* others have read, write and execute permission */ 385 #define S_IROTH 00004 /* others have read permission */ 386 #define S_IWOTH 00002 /* others have write permission */ 387 #define S_IXOTH 00001 /* others have execute permission */ 388 389 #if !defined(ROKEN_NO_DEFINE_ALLOCATORS) 390 /* Ensure that a common memory allocator is used by all */ 391 #define calloc rk_calloc 392 #define free rk_free 393 #define malloc rk_malloc 394 #define realloc rk_realloc 395 #define strdup rk_strdup 396 #define wcsdup rk_wcsdup 397 #endif 398 399 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL 400 rk_calloc(size_t, size_t); 401 402 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 403 rk_free(void *); 404 405 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL 406 rk_malloc(size_t); 407 408 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL 409 rk_realloc(void *, size_t); 410 411 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL 412 rk_strdup(const char *); 413 414 ROKEN_LIB_FUNCTION unsigned short * ROKEN_LIB_CALL 415 rk_wcsdup(const unsigned short *); 416 417 #endif /* _MSC_VER */ 418 419 #ifdef HAVE_WINSOCK 420 421 /* While we are at it, define WinSock specific scatter gather socket 422 I/O. */ 423 424 #define iovec _WSABUF 425 #define iov_base buf 426 #define iov_len len 427 428 struct msghdr { 429 void *msg_name; 430 socklen_t msg_namelen; 431 struct iovec *msg_iov; 432 size_t msg_iovlen; 433 void *msg_control; 434 socklen_t msg_controllen; 435 int msg_flags; 436 }; 437 438 #define sendmsg sendmsg_w32 439 440 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL 441 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags); 442 443 #endif /* HAVE_WINSOCK */ 444 445 #ifndef HAVE_PUTENV 446 #define putenv rk_putenv 447 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *); 448 #endif 449 450 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO) 451 #ifndef HAVE_SETENV 452 #define setenv rk_setenv 453 #endif 454 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int); 455 #endif 456 457 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO) 458 #ifndef HAVE_UNSETENV 459 #define unsetenv rk_unsetenv 460 #endif 461 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *); 462 #endif 463 464 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO) 465 #ifndef HAVE_GETUSERSHELL 466 #define getusershell rk_getusershell 467 #define endusershell rk_endusershell 468 #endif 469 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void); 470 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void); 471 #endif 472 473 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO) 474 #ifndef HAVE_SNPRINTF 475 #define snprintf rk_snprintf 476 #endif 477 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 478 rk_snprintf (char *, size_t, const char *, ...) 479 __attribute__ ((__format__ (__printf__, 3, 4))); 480 #endif 481 482 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO) 483 #ifndef HAVE_VSNPRINTF 484 #define vsnprintf rk_vsnprintf 485 #endif 486 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 487 rk_vsnprintf (char *, size_t, const char *, va_list) 488 __attribute__ ((__format__ (__printf__, 3, 0))); 489 #endif 490 491 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO) 492 #ifndef HAVE_ASPRINTF 493 #define asprintf rk_asprintf 494 #endif 495 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 496 rk_asprintf (char **, const char *, ...) 497 __attribute__ ((__format__ (__printf__, 2, 3))); 498 #endif 499 500 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO) 501 #ifndef HAVE_VASPRINTF 502 #define vasprintf rk_vasprintf 503 #endif 504 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 505 rk_vasprintf (char **, const char *, va_list) 506 __attribute__ ((__format__ (__printf__, 2, 0))); 507 #endif 508 509 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO) 510 #ifndef HAVE_ASNPRINTF 511 #define asnprintf rk_asnprintf 512 #endif 513 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 514 rk_asnprintf (char **, size_t, const char *, ...) 515 __attribute__ ((__format__ (__printf__, 3, 4))); 516 #endif 517 518 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO) 519 #ifndef HAVE_VASNPRINTF 520 #define vasnprintf rk_vasnprintf 521 #endif 522 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 523 vasnprintf (char **, size_t, const char *, va_list) 524 __attribute__ ((__format__ (__printf__, 3, 0))); 525 #endif 526 527 #ifndef HAVE_STRDUP 528 #define strdup rk_strdup 529 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *); 530 #endif 531 532 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO) 533 #ifndef HAVE_STRNDUP 534 #define strndup rk_strndup 535 #endif 536 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t); 537 #endif 538 539 #ifndef HAVE_STRLWR 540 #define strlwr rk_strlwr 541 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *); 542 #endif 543 544 #ifndef HAVE_STRNLEN 545 #define strnlen rk_strnlen 546 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t); 547 #endif 548 549 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO) 550 #ifndef HAVE_STRSEP 551 #define strsep rk_strsep 552 #endif 553 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*); 554 #endif 555 556 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO) 557 #ifndef HAVE_STRSEP_COPY 558 #define strsep_copy rk_strsep_copy 559 #endif 560 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t); 561 #endif 562 563 #ifndef HAVE_STRCASECMP 564 #define strcasecmp rk_strcasecmp 565 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *); 566 #endif 567 568 #ifdef NEED_FCLOSE_PROTO 569 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *); 570 #endif 571 572 #ifdef NEED_STRTOK_R_PROTO 573 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **); 574 #endif 575 576 #ifndef HAVE_STRUPR 577 #define strupr rk_strupr 578 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *); 579 #endif 580 581 #ifndef HAVE_STRLCPY 582 #define strlcpy rk_strlcpy 583 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t); 584 #endif 585 586 #ifndef HAVE_STRLCAT 587 #define strlcat rk_strlcat 588 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t); 589 #endif 590 591 #ifndef HAVE_GETDTABLESIZE 592 #define getdtablesize rk_getdtablesize 593 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void); 594 #endif 595 596 #if !defined(HAVE_STRERROR) && !defined(strerror) 597 #define strerror rk_strerror 598 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int); 599 #endif 600 601 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R)) 602 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t); 603 #else 604 #define rk_strerror_r strerror_r 605 #endif 606 607 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO) 608 #ifndef HAVE_HSTRERROR 609 #define hstrerror rk_hstrerror 610 #endif 611 /* This causes a fatal error under Psoriasis */ 612 #ifndef SunOS 613 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int); 614 #endif 615 #endif 616 617 #if !HAVE_DECL_H_ERRNO 618 extern int h_errno; 619 #endif 620 621 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO) 622 #ifndef HAVE_INET_ATON 623 #define inet_aton rk_inet_aton 624 #endif 625 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *); 626 #endif 627 628 #ifndef HAVE_INET_NTOP 629 #define inet_ntop rk_inet_ntop 630 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL 631 inet_ntop(int af, const void *src, char *dst, size_t size); 632 #endif 633 634 #ifndef HAVE_INET_PTON 635 #define inet_pton rk_inet_pton 636 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 637 inet_pton(int, const char *, void *); 638 #endif 639 640 #ifndef HAVE_GETCWD 641 #define getcwd rk_getcwd 642 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t); 643 #endif 644 645 #ifdef HAVE_PWD_H 646 #include <pwd.h> 647 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *); 648 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t); 649 #endif 650 651 #ifdef POSIX_GETPWNAM_R 652 #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd) 653 #else 654 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 655 rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); 656 #endif 657 658 #ifdef POSIX_GETPWUID_R 659 #define rk_getpwuid_r(_u, _pw, _b, _sz, _pwd) getpwuid_r(_u, _pw, _b, _sz, _pwd) 660 #else 661 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 662 rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); 663 #endif 664 665 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void); 666 667 #ifndef HAVE_SETEUID 668 #define seteuid rk_seteuid 669 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t); 670 #endif 671 672 #ifndef HAVE_SETEGID 673 #define setegid rk_setegid 674 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t); 675 #endif 676 677 #ifndef HAVE_LSTAT 678 #define lstat rk_lstat 679 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *); 680 #endif 681 682 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO) 683 #ifndef HAVE_MKSTEMP 684 #define mkstemp rk_mkstemp 685 #endif 686 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *); 687 #endif 688 689 #ifndef HAVE_CGETENT 690 #define cgetent rk_cgetent 691 #define cgetstr rk_cgetstr 692 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *); 693 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **); 694 #endif 695 696 #ifndef HAVE_INITGROUPS 697 #define initgroups rk_initgroups 698 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t); 699 #endif 700 701 #ifndef HAVE_FCHOWN 702 #define fchown rk_fchown 703 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t); 704 #endif 705 706 #ifdef RENAME_DOES_NOT_UNLINK 707 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *); 708 #else 709 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to) 710 #endif 711 712 #ifdef MKDIR_DOES_NOT_HAVE_MODE 713 #define mkdir rk_mkdir 714 #else 715 #define rk_mkdir(__rk_rn_name, __rk_rn_mode) mkdir(__rk_rn_name,__rk_rn_mode) 716 #endif 717 718 719 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO) 720 #ifndef HAVE_DAEMON 721 #define daemon rk_daemon 722 #endif 723 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int); 724 #endif 725 726 #ifndef HAVE_CHOWN 727 #define chown rk_chown 728 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t); 729 #endif 730 731 #ifndef HAVE_RCMD 732 #define rcmd rk_rcmd 733 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 734 rcmd(char **, unsigned short, const char *, 735 const char *, const char *, int *); 736 #endif 737 738 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO) 739 #ifndef HAVE_INNETGR 740 #define innetgr rk_innetgr 741 #endif 742 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*, 743 const char*, const char*); 744 #endif 745 746 #ifndef HAVE_IRUSEROK 747 #define iruserok rk_iruserok 748 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int, 749 const char *, const char *); 750 #endif 751 752 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO) 753 #ifndef HAVE_GETHOSTNAME 754 #define gethostname rk_gethostname 755 #endif 756 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int); 757 #endif 758 759 #ifndef HAVE_WRITEV 760 #define writev rk_writev 761 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL 762 writev(int, const struct iovec *, int); 763 #endif 764 765 #ifndef HAVE_READV 766 #define readv rk_readv 767 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL 768 readv(int, const struct iovec *, int); 769 #endif 770 771 #ifdef NO_PIDFILES 772 #define rk_pidfile(x) ((void) 0) 773 #else 774 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_pidfile (const char*); 775 #endif 776 777 #ifndef HAVE_BSWAP64 778 #define bswap64 rk_bswap64 779 ROKEN_LIB_FUNCTION uint64_t ROKEN_LIB_CALL bswap64(uint64_t); 780 #endif 781 782 #ifndef HAVE_BSWAP32 783 #define bswap32 rk_bswap32 784 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int); 785 #endif 786 787 #ifndef HAVE_BSWAP16 788 #define bswap16 rk_bswap16 789 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short); 790 #endif 791 792 #ifndef HAVE_FLOCK 793 #ifndef LOCK_SH 794 #define LOCK_SH 1 /* Shared lock */ 795 #endif 796 #ifndef LOCK_EX 797 #define LOCK_EX 2 /* Exclusive lock */ 798 #endif 799 #ifndef LOCK_NB 800 #define LOCK_NB 4 /* Don't block when locking */ 801 #endif 802 #ifndef LOCK_UN 803 #define LOCK_UN 8 /* Unlock */ 804 #endif 805 806 #define flock(_x,_y) rk_flock(_x,_y) 807 int rk_flock(int fd, int operation); 808 #endif /* HAVE_FLOCK */ 809 810 #ifndef HAVE_DIRFD 811 #ifdef HAVE_DIR_DD_FD 812 #define dirfd(x) ((x)->dd_fd) 813 #else 814 #ifndef _WIN32 /* Windows code never calls dirfd */ 815 #error Missing dirfd() and ->dd_fd 816 #endif 817 #endif 818 #endif 819 820 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int); 821 822 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *); 823 824 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...); 825 826 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...); 827 828 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list); 829 830 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL 831 roken_vmconcat (char **, size_t, va_list); 832 833 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_prep(int, char **, char *); 834 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_finish(const char *, int); 835 836 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL 837 net_write (rk_socket_t, const void *, size_t); 838 839 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL 840 net_read (rk_socket_t, void *, size_t); 841 842 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 843 issuid(void); 844 845 #ifndef HAVE_STRUCT_WINSIZE 846 struct winsize { 847 unsigned short ws_row, ws_col; 848 unsigned short ws_xpixel, ws_ypixel; 849 }; 850 #endif 851 852 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *); 853 854 #ifndef HAVE_VSYSLOG 855 #define vsyslog rk_vsyslog 856 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list); 857 #endif 858 859 #ifndef HAVE_GETOPT 860 #define getopt rk_getopt 861 #define optarg rk_optarg 862 #define optind rk_optind 863 #define opterr rk_opterr 864 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 865 getopt(int nargc, char * const *nargv, const char *ostr); 866 #endif 867 868 #if !HAVE_DECL_OPTARG 869 ROKEN_LIB_VARIABLE extern char *optarg; 870 #endif 871 #if !HAVE_DECL_OPTIND 872 ROKEN_LIB_VARIABLE extern int optind; 873 #endif 874 #if !HAVE_DECL_OPTERR 875 ROKEN_LIB_VARIABLE extern int opterr; 876 #endif 877 878 #ifndef HAVE_GETIPNODEBYNAME 879 #define getipnodebyname rk_getipnodebyname 880 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL 881 getipnodebyname (const char *, int, int, int *); 882 #endif 883 884 #ifndef HAVE_GETIPNODEBYADDR 885 #define getipnodebyaddr rk_getipnodebyaddr 886 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL 887 getipnodebyaddr (const void *, size_t, int, int *); 888 #endif 889 890 #ifndef HAVE_FREEHOSTENT 891 #define freehostent rk_freehostent 892 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 893 freehostent (struct hostent *); 894 #endif 895 896 #ifndef HAVE_COPYHOSTENT 897 #define copyhostent rk_copyhostent 898 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL 899 copyhostent (const struct hostent *); 900 #endif 901 902 #ifndef HAVE_SOCKLEN_T 903 typedef int socklen_t; 904 #endif 905 906 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE 907 908 #ifndef HAVE_SA_FAMILY_T 909 typedef unsigned short sa_family_t; 910 #endif 911 912 #ifdef HAVE_IPV6 913 #define _SS_MAXSIZE sizeof(struct sockaddr_in6) 914 #else 915 #define _SS_MAXSIZE sizeof(struct sockaddr_in) 916 #endif 917 918 #define _SS_ALIGNSIZE sizeof(unsigned long) 919 920 #if HAVE_STRUCT_SOCKADDR_SA_LEN 921 922 typedef unsigned char roken_sa_family_t; 923 924 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE) 925 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) 926 927 struct sockaddr_storage { 928 unsigned char ss_len; 929 roken_sa_family_t ss_family; 930 char __ss_pad1[_SS_PAD1SIZE]; 931 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; 932 }; 933 934 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */ 935 936 typedef unsigned short roken_sa_family_t; 937 938 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE) 939 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) 940 941 struct sockaddr_storage { 942 roken_sa_family_t ss_family; 943 char __ss_pad1[_SS_PAD1SIZE]; 944 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; 945 }; 946 947 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ 948 949 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */ 950 951 #ifndef HAVE_STRUCT_ADDRINFO 952 struct addrinfo { 953 int ai_flags; 954 int ai_family; 955 int ai_socktype; 956 int ai_protocol; 957 size_t ai_addrlen; 958 char *ai_canonname; 959 struct sockaddr *ai_addr; 960 struct addrinfo *ai_next; 961 }; 962 #endif 963 964 #ifndef HAVE_GETADDRINFO 965 #define getaddrinfo rk_getaddrinfo 966 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 967 getaddrinfo(const char *, 968 const char *, 969 const struct addrinfo *, 970 struct addrinfo **); 971 #endif 972 973 #ifndef HAVE_GETNAMEINFO 974 #define getnameinfo rk_getnameinfo 975 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 976 getnameinfo(const struct sockaddr *, socklen_t, 977 char *, size_t, 978 char *, size_t, 979 int); 980 #endif 981 982 #ifndef HAVE_FREEADDRINFO 983 #define freeaddrinfo rk_freeaddrinfo 984 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 985 freeaddrinfo(struct addrinfo *); 986 #endif 987 988 #ifndef HAVE_GAI_STRERROR 989 #define gai_strerror rk_gai_strerror 990 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL 991 gai_strerror(int); 992 #endif 993 994 #ifdef NO_SLEEP 995 996 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL 997 sleep(unsigned int seconds); 998 999 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL 1000 usleep(unsigned int useconds); 1001 1002 #endif 1003 1004 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1005 getnameinfo_verified(const struct sockaddr *, socklen_t, 1006 char *, size_t, 1007 char *, size_t, 1008 int); 1009 1010 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1011 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **); 1012 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1013 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **); 1014 1015 #ifndef HAVE_STRFTIME 1016 #define strftime rk_strftime 1017 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL 1018 strftime (char *, size_t, const char *, const struct tm *); 1019 #endif 1020 1021 #ifndef HAVE_STRPTIME 1022 #define strptime rk_strptime 1023 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL 1024 strptime (const char *, const char *, struct tm *); 1025 #endif 1026 1027 #ifndef HAVE_GETTIMEOFDAY 1028 #define gettimeofday rk_gettimeofday 1029 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1030 gettimeofday (struct timeval *, void *); 1031 #endif 1032 1033 #ifndef HAVE_EMALLOC 1034 #define emalloc rk_emalloc 1035 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t); 1036 #endif 1037 #ifndef HAVE_ECALLOC 1038 #define ecalloc rk_ecalloc 1039 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t); 1040 #endif 1041 #ifndef HAVE_EREALLOC 1042 #define erealloc rk_erealloc 1043 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t); 1044 #endif 1045 #ifndef HAVE_ESTRDUP 1046 #define estrdup rk_estrdup 1047 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *); 1048 #endif 1049 1050 /* 1051 * kludges and such 1052 */ 1053 1054 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1055 roken_gethostby_setup(const char*, const char*); 1056 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL 1057 roken_gethostbyname(const char*); 1058 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL 1059 roken_gethostbyaddr(const void*, size_t, int); 1060 1061 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE 1062 #define roken_getservbyname(x,y) getservbyname(x,y) 1063 #else 1064 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y) 1065 #endif 1066 1067 #ifdef OPENLOG_PROTO_COMPATIBLE 1068 #define roken_openlog(a,b,c) openlog(a,b,c) 1069 #else 1070 #define roken_openlog(a,b,c) openlog((char *)a,b,c) 1071 #endif 1072 1073 #ifdef GETSOCKNAME_PROTO_COMPATIBLE 1074 #define roken_getsockname(a,b,c) getsockname(a,b,c) 1075 #else 1076 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c) 1077 #endif 1078 1079 #ifndef HAVE_SETPROGNAME 1080 #define setprogname rk_setprogname 1081 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *); 1082 #endif 1083 1084 #ifndef HAVE_GETPROGNAME 1085 #define getprogname rk_getprogname 1086 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void); 1087 #endif 1088 1089 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME 1090 extern const char *__progname; 1091 #endif 1092 1093 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 1094 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *); 1095 1096 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 1097 mini_inetd (int, rk_socket_t *); 1098 1099 #ifndef HAVE_LOCALTIME_R 1100 #define localtime_r rk_localtime_r 1101 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL 1102 localtime_r(const time_t *, struct tm *); 1103 #endif 1104 1105 #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO) 1106 #ifndef HAVE_STRTOLL 1107 #define strtoll rk_strtoll 1108 #endif 1109 ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL 1110 strtoll(const char * nptr, char ** endptr, int base); 1111 #endif 1112 1113 #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO) 1114 #ifndef HAVE_STRTOULL 1115 #define strtoull rk_strtoull 1116 #endif 1117 ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL 1118 strtoull(const char * nptr, char ** endptr, int base); 1119 #endif 1120 1121 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO) 1122 #ifndef HAVE_STRSVIS 1123 #define strsvis rk_strsvis 1124 #endif 1125 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1126 strsvis(char *, const char *, int, const char *); 1127 #endif 1128 1129 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO) 1130 #ifndef HAVE_STRSVISX 1131 #define strsvisx rk_strsvisx 1132 #endif 1133 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1134 strsvisx(char *, const char *, size_t, int, const char *); 1135 #endif 1136 1137 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO) 1138 #ifndef HAVE_STRUNVIS 1139 #define strunvis rk_strunvis 1140 #endif 1141 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1142 strunvis(char *, const char *); 1143 #endif 1144 1145 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO) 1146 #ifndef HAVE_STRVIS 1147 #define strvis rk_strvis 1148 #endif 1149 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1150 strvis(char *, const char *, int); 1151 #endif 1152 1153 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO) 1154 #ifndef HAVE_STRVISX 1155 #define strvisx rk_strvisx 1156 #endif 1157 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1158 strvisx(char *, const char *, size_t, int); 1159 #endif 1160 1161 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO) 1162 #ifndef HAVE_SVIS 1163 #define svis rk_svis 1164 #endif 1165 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL 1166 svis(char *, int, int, int, const char *); 1167 #endif 1168 1169 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO) 1170 #ifndef HAVE_UNVIS 1171 #define unvis rk_unvis 1172 #endif 1173 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1174 unvis(char *, int, int *, int); 1175 #endif 1176 1177 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO) 1178 #ifndef HAVE_VIS 1179 #define vis rk_vis 1180 #endif 1181 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL 1182 vis(char *, int, int, int); 1183 #endif 1184 1185 #if !defined(HAVE_CLOSEFROM) 1186 #define closefrom rk_closefrom 1187 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 1188 closefrom(int); 1189 #endif 1190 1191 #if !defined(HAVE_TIMEGM) 1192 #define timegm rk_timegm 1193 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL 1194 rk_timegm(struct tm *tm); 1195 #endif 1196 1197 #ifdef NEED_QSORT 1198 #define qsort rk_qsort 1199 void 1200 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 1201 #endif 1202 1203 #ifndef HAVE_MEMSET_S 1204 #define memset_s rk_memset_s 1205 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL memset_s(void *s, size_t smax, 1206 int c, size_t n); 1207 #endif 1208 1209 #if defined(HAVE_ARC4RANDOM) 1210 # define rk_random() arc4random() 1211 #elif defined(HAVE_RANDOM) 1212 # define rk_random() random() 1213 #else 1214 # ifdef HAVE_WIN32_RAND_S 1215 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL 1216 rk_random(void); 1217 # else 1218 # define rk_random() rand() 1219 # endif 1220 #endif 1221 1222 #ifndef HAVE_TDELETE 1223 #define tdelete(a,b,c) rk_tdelete(a,b,c) 1224 #endif 1225 #ifndef HAVE_TFIND 1226 #define tfind(a,b,c) rk_tfind(a,b,c) 1227 #endif 1228 #ifndef HAVE_TSEARCH 1229 #define tsearch(a,b,c) rk_tsearch(a,b,c) 1230 #endif 1231 #ifndef HAVE_TWALK 1232 #define twalk(a,b) rk_twalk(a,b) 1233 #endif 1234 1235 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__) 1236 #undef socket 1237 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot) 1238 int ROKEN_LIB_FUNCTION rk_socket(int, int, int); 1239 #endif 1240 1241 /* Microsoft VC 2010 POSIX definitions */ 1242 #ifndef EAFNOSUPPORT 1243 #define EAFNOSUPPORT 102 1244 #endif 1245 #ifndef EINPROGRESS 1246 #define EINPROGRESS 112 1247 #endif 1248 #ifndef ELOOP 1249 #define ELOOP 114 1250 #endif 1251 #ifndef ENOTSOCK 1252 #define ENOTSOCK 128 1253 #endif 1254 #ifndef ENOTSUP 1255 #define ENOTSUP 129 1256 #endif 1257 #ifndef EOVERFLOW 1258 #define EOVERFLOW 132 1259 #endif 1260 #ifndef ETIMEDOUT 1261 #define ETIMEDOUT 138 1262 #endif 1263 #ifndef EWOULDBLOCK 1264 #define EWOULDBLOCK 140 1265 #endif 1266 1267 1268 #ifdef SOCKET_WRAPPER_REPLACE 1269 #include <socket_wrapper.h> 1270 #endif 1271 1272 ROKEN_CPP_END 1273