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