update for autoheader
[heimdal.git] / lib / roken / roken.h.in
blob1ca3c10dc91e18bd6d836e82c0ae5758ba61fd2e
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:
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
32 * SUCH DAMAGE.
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 <signal.h>
44 #ifndef ROKEN_LIB_FUNCTION
45 #ifdef _WIN32
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)
50 # else
51 # define ROKEN_LIB_FUNCTION
52 # define ROKEN_LIB_VARIABLE
53 # endif
54 #else
55 #define ROKEN_LIB_FUNCTION
56 #define ROKEN_LIB_CALL
57 #define ROKEN_LIB_VARIABLE
58 #endif
59 #endif
61 #ifdef HAVE_WINSOCK
62 /* Declarations for Microsoft Windows */
64 #include <winsock2.h>
65 #include <ws2tcpip.h>
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)
106 #endif
108 #ifdef _MSC_VER
109 /* Declarations for Microsoft Visual C runtime on Windows */
111 #include<process.h>
113 #include<io.h>
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
142 #else
143 #define SIGRETURN(x) return (RETSIGTYPE)(x)
144 #endif
146 #ifndef CPP_ONLY
148 typedef int pid_t;
150 typedef unsigned int gid_t;
152 typedef unsigned int uid_t;
154 typedef unsigned short mode_t;
156 #endif
158 #ifndef __cplusplus
159 #define inline __inline
160 #endif
162 #else
164 #define UNREACHABLE(x)
165 #define UNUSED_ARGUMENT(x)
167 #endif
169 #ifdef _AIX
170 struct ether_addr;
171 struct sockaddr_dl;
172 #endif
173 #ifdef HAVE_SYS_PARAM_H
174 #include <sys/param.h>
175 #endif
176 #ifdef HAVE_INTTYPES_H
177 #include <inttypes.h>
178 #endif
179 #ifdef HAVE_SYS_TYPES_H
180 #include <sys/types.h>
181 #endif
182 #ifdef HAVE_SYS_BITYPES_H
183 #include <sys/bitypes.h>
184 #endif
185 #ifdef HAVE_BIND_BITYPES_H
186 #include <bind/bitypes.h>
187 #endif
188 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
189 #include <netinet/in6_machtypes.h>
190 #endif
191 #ifdef HAVE_UNISTD_H
192 #include <unistd.h>
193 #endif
194 #ifdef HAVE_SYS_SOCKET_H
195 #include <sys/socket.h>
196 #endif
197 #ifdef HAVE_SYS_UIO_H
198 #include <sys/uio.h>
199 #endif
200 #ifdef HAVE_GRP_H
201 #include <grp.h>
202 #endif
203 #ifdef HAVE_SYS_STAT_H
204 #include <sys/stat.h>
205 #endif
206 #ifdef HAVE_NETINET_IN_H
207 #include <netinet/in.h>
208 #endif
209 #ifdef HAVE_NETINET_IN6_H
210 #include <netinet/in6.h>
211 #endif
212 #ifdef HAVE_NETINET6_IN6_H
213 #include <netinet6/in6.h>
214 #endif
215 #ifdef HAVE_ARPA_INET_H
216 #include <arpa/inet.h>
217 #endif
218 #ifdef HAVE_NETDB_H
219 #include <netdb.h>
220 #endif
221 #ifdef HAVE_ARPA_NAMESER_H
222 #include <arpa/nameser.h>
223 #endif
224 #ifdef HAVE_RESOLV_H
225 #include <resolv.h>
226 #endif
227 #ifdef HAVE_SYSLOG_H
228 #include <syslog.h>
229 #endif
230 #ifdef HAVE_FCNTL_H
231 #include <fcntl.h>
232 #endif
233 #ifdef HAVE_ERRNO_H
234 #include <errno.h>
235 #endif
236 #include <err.h>
237 #ifdef HAVE_TERMIOS_H
238 #include <termios.h>
239 #endif
240 #ifdef HAVE_SYS_IOCTL_H
241 #include <sys/ioctl.h>
242 #endif
243 #ifdef TIME_WITH_SYS_TIME
244 #include <sys/time.h>
245 #include <time.h>
246 #elif defined(HAVE_SYS_TIME_H)
247 #include <sys/time.h>
248 #else
249 #include <time.h>
250 #endif
252 #ifdef HAVE_PATHS_H
253 #include <paths.h>
254 #endif
256 #ifdef HAVE_DIRENT_H
257 #include <dirent.h>
258 #endif
260 #ifdef BACKSLASH_PATH_DELIM
261 #define rk_PATH_DELIM '\\'
262 #endif
264 #ifndef HAVE_SSIZE_T
265 #ifndef SSIZE_T_DEFINED
266 #ifdef ssize_t
267 #undef ssize_t
268 #endif
269 #ifdef _WIN64
270 typedef __int64 ssize_t;
271 #else
272 typedef int ssize_t;
273 #endif
274 #define SSIZE_T_DEFINED
275 #endif /* SSIZE_T_DEFINED */
276 #endif /* HAVE_SSIZE_T */
278 #include <roken-common.h>
280 ROKEN_CPP_START
282 #ifdef HAVE_UINTPTR_T
283 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
284 #else
285 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
286 #endif
288 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
289 #define setsid _setsid
290 #endif
292 #ifdef _MSC_VER
293 /* Additional macros for Visual C/C++ runtime */
295 #define close _close
297 #define getpid _getpid
299 #define open _open
301 #define chdir _chdir
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:
348 S_ISLNK(m)
349 S_ISSOCK(m)
350 S_ISBLK(m)
353 #endif /* _MSC_VER */
355 #ifdef HAVE_WINSOCK
357 /* While we are at it, define WinSock specific scatter gather socket
358 I/O. */
360 #define iovec _WSABUF
361 #define iov_base buf
362 #define iov_len len
364 struct msghdr {
365 void *msg_name;
366 socklen_t msg_namelen;
367 struct iovec *msg_iov;
368 size_t msg_iovlen;
369 void *msg_control;
370 socklen_t msg_controllen;
371 int msg_flags;
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 */
381 #ifndef HAVE_PUTENV
382 #define putenv rk_putenv
383 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
384 #endif
386 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
387 #ifndef HAVE_SETENV
388 #define setenv rk_setenv
389 #endif
390 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
391 #endif
393 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
394 #ifndef HAVE_UNSETENV
395 #define unsetenv rk_unsetenv
396 #endif
397 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
398 #endif
400 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
401 #ifndef HAVE_GETUSERSHELL
402 #define getusershell rk_getusershell
403 #define endusershell rk_endusershell
404 #endif
405 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
406 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
407 #endif
409 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
410 #ifndef HAVE_SNPRINTF
411 #define snprintf rk_snprintf
412 #endif
413 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
414 rk_snprintf (char *, size_t, const char *, ...)
415 __attribute__ ((format (printf, 3, 4)));
416 #endif
418 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
419 #ifndef HAVE_VSNPRINTF
420 #define vsnprintf rk_vsnprintf
421 #endif
422 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
423 rk_vsnprintf (char *, size_t, const char *, va_list)
424 __attribute__((format (printf, 3, 0)));
425 #endif
427 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
428 #ifndef HAVE_ASPRINTF
429 #define asprintf rk_asprintf
430 #endif
431 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
432 rk_asprintf (char **, const char *, ...)
433 __attribute__ ((format (printf, 2, 3)));
434 #endif
436 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
437 #ifndef HAVE_VASPRINTF
438 #define vasprintf rk_vasprintf
439 #endif
440 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
441 rk_vasprintf (char **, const char *, va_list)
442 __attribute__((format (printf, 2, 0)));
443 #endif
445 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
446 #ifndef HAVE_ASNPRINTF
447 #define asnprintf rk_asnprintf
448 #endif
449 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
450 rk_asnprintf (char **, size_t, const char *, ...)
451 __attribute__ ((format (printf, 3, 4)));
452 #endif
454 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
455 #ifndef HAVE_VASNPRINTF
456 #define vasnprintf rk_vasnprintf
457 #endif
458 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
459 vasnprintf (char **, size_t, const char *, va_list)
460 __attribute__((format (printf, 3, 0)));
461 #endif
463 #ifndef HAVE_STRDUP
464 #define strdup rk_strdup
465 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
466 #endif
468 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
469 #ifndef HAVE_STRNDUP
470 #define strndup rk_strndup
471 #endif
472 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
473 #endif
475 #ifndef HAVE_STRLWR
476 #define strlwr rk_strlwr
477 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
478 #endif
480 #ifndef HAVE_STRNLEN
481 #define strnlen rk_strnlen
482 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
483 #endif
485 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
486 #ifndef HAVE_STRSEP
487 #define strsep rk_strsep
488 #endif
489 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
490 #endif
492 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
493 #ifndef HAVE_STRSEP_COPY
494 #define strsep_copy rk_strsep_copy
495 #endif
496 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
497 #endif
499 #ifndef HAVE_STRCASECMP
500 #define strcasecmp rk_strcasecmp
501 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
502 #endif
504 #ifdef NEED_FCLOSE_PROTO
505 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
506 #endif
508 #ifdef NEED_STRTOK_R_PROTO
509 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
510 #endif
512 #ifndef HAVE_STRUPR
513 #define strupr rk_strupr
514 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
515 #endif
517 #ifndef HAVE_STRLCPY
518 #define strlcpy rk_strlcpy
519 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
520 #endif
522 #ifndef HAVE_STRLCAT
523 #define strlcat rk_strlcat
524 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
525 #endif
527 #ifndef HAVE_GETDTABLESIZE
528 #define getdtablesize rk_getdtablesize
529 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
530 #endif
532 #if !defined(HAVE_STRERROR) && !defined(strerror)
533 #define strerror rk_strerror
534 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
535 #endif
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);
539 #else
540 #define rk_strerror_r strerror_r
541 #endif
543 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
544 #ifndef HAVE_HSTRERROR
545 #define hstrerror rk_hstrerror
546 #endif
547 /* This causes a fatal error under Psoriasis */
548 #ifndef SunOS
549 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
550 #endif
551 #endif
553 #if !HAVE_DECL_H_ERRNO
554 extern int h_errno;
555 #endif
557 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
558 #ifndef HAVE_INET_ATON
559 #define inet_aton rk_inet_aton
560 #endif
561 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
562 #endif
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);
568 #endif
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 *);
574 #endif
576 #ifndef HAVE_GETCWD
577 #define getcwd rk_getcwd
578 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
579 #endif
581 #ifdef HAVE_PWD_H
582 #include <pwd.h>
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);
585 #endif
587 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
589 #ifndef HAVE_SETEUID
590 #define seteuid rk_seteuid
591 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
592 #endif
594 #ifndef HAVE_SETEGID
595 #define setegid rk_setegid
596 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
597 #endif
599 #ifndef HAVE_LSTAT
600 #define lstat rk_lstat
601 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
602 #endif
604 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
605 #ifndef HAVE_MKSTEMP
606 #define mkstemp rk_mkstemp
607 #endif
608 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
609 #endif
611 #ifndef HAVE_CGETENT
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 **);
616 #endif
618 #ifndef HAVE_INITGROUPS
619 #define initgroups rk_initgroups
620 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
621 #endif
623 #ifndef HAVE_FCHOWN
624 #define fchown rk_fchown
625 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
626 #endif
628 #ifdef RENAME_DOES_NOT_UNLINK
629 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
630 #else
631 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
632 #endif
634 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
635 #ifndef HAVE_DAEMON
636 #define daemon rk_daemon
637 #endif
638 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
639 #endif
641 #ifndef HAVE_CHOWN
642 #define chown rk_chown
643 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
644 #endif
646 #ifndef HAVE_RCMD
647 #define rcmd rk_rcmd
648 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
649 rcmd(char **, unsigned short, const char *,
650 const char *, const char *, int *);
651 #endif
653 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
654 #ifndef HAVE_INNETGR
655 #define innetgr rk_innetgr
656 #endif
657 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
658 const char*, const char*);
659 #endif
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 *);
665 #endif
667 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
668 #ifndef HAVE_GETHOSTNAME
669 #define gethostname rk_gethostname
670 #endif
671 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
672 #endif
674 #ifndef HAVE_WRITEV
675 #define writev rk_writev
676 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
677 writev(int, const struct iovec *, int);
678 #endif
680 #ifndef HAVE_READV
681 #define readv rk_readv
682 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
683 readv(int, const struct iovec *, int);
684 #endif
686 #ifndef HAVE_PIDFILE
687 #ifdef NO_PIDFILES
688 #define pidfile(x) ((void) 0)
689 #else
690 #define pidfile rk_pidfile
691 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
692 #endif
693 #endif
695 #ifndef HAVE_BSWAP32
696 #define bswap32 rk_bswap32
697 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
698 #endif
700 #ifndef HAVE_BSWAP16
701 #define bswap16 rk_bswap16
702 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
703 #endif
705 #ifndef HAVE_FLOCK
706 #ifndef LOCK_SH
707 #define LOCK_SH 1 /* Shared lock */
708 #endif
709 #ifndef LOCK_EX
710 #define LOCK_EX 2 /* Exclusive lock */
711 #endif
712 #ifndef LOCK_NB
713 #define LOCK_NB 4 /* Don't block when locking */
714 #endif
715 #ifndef LOCK_UN
716 #define LOCK_UN 8 /* Unlock */
717 #endif
719 #define flock(_x,_y) rk_flock(_x,_y)
720 int rk_flock(int fd, int operation);
721 #endif /* HAVE_FLOCK */
723 #ifndef HAVE_DIRFD
724 #ifdef HAVE_DIR_DD_FD
725 #define dirfd(x) ((x)->dd_fd)
726 #else
727 #ifndef _WIN32 /* Windows code never calls dirfd */
728 #error Missing dirfd() and ->dd_fd
729 #endif
730 #endif
731 #endif
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
753 issuid(void);
755 #ifndef HAVE_STRUCT_WINSIZE
756 struct winsize {
757 unsigned short ws_row, ws_col;
758 unsigned short ws_xpixel, ws_ypixel;
760 #endif
762 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
764 #ifndef HAVE_VSYSLOG
765 #define vsyslog rk_vsyslog
766 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
767 #endif
769 #ifndef HAVE_GETOPT
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);
776 #endif
778 #if !HAVE_DECL_OPTARG
779 ROKEN_LIB_VARIABLE extern char *optarg;
780 #endif
781 #if !HAVE_DECL_OPTIND
782 ROKEN_LIB_VARIABLE extern int optind;
783 #endif
784 #if !HAVE_DECL_OPTERR
785 ROKEN_LIB_VARIABLE extern int opterr;
786 #endif
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 *);
792 #endif
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 *);
798 #endif
800 #ifndef HAVE_FREEHOSTENT
801 #define freehostent rk_freehostent
802 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
803 freehostent (struct hostent *);
804 #endif
806 #ifndef HAVE_COPYHOSTENT
807 #define copyhostent rk_copyhostent
808 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
809 copyhostent (const struct hostent *);
810 #endif
812 #ifndef HAVE_SOCKLEN_T
813 typedef int socklen_t;
814 #endif
816 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
818 #ifndef HAVE_SA_FAMILY_T
819 typedef unsigned short sa_family_t;
820 #endif
822 #ifdef HAVE_IPV6
823 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
824 #else
825 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
826 #endif
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
862 struct addrinfo {
863 int ai_flags;
864 int ai_family;
865 int ai_socktype;
866 int ai_protocol;
867 size_t ai_addrlen;
868 char *ai_canonname;
869 struct sockaddr *ai_addr;
870 struct addrinfo *ai_next;
872 #endif
874 #ifndef HAVE_GETADDRINFO
875 #define getaddrinfo rk_getaddrinfo
876 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
877 getaddrinfo(const char *,
878 const char *,
879 const struct addrinfo *,
880 struct addrinfo **);
881 #endif
883 #ifndef HAVE_GETNAMEINFO
884 #define getnameinfo rk_getnameinfo
885 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
886 getnameinfo(const struct sockaddr *, socklen_t,
887 char *, size_t,
888 char *, size_t,
889 int);
890 #endif
892 #ifndef HAVE_FREEADDRINFO
893 #define freeaddrinfo rk_freeaddrinfo
894 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
895 freeaddrinfo(struct addrinfo *);
896 #endif
898 #ifndef HAVE_GAI_STRERROR
899 #define gai_strerror rk_gai_strerror
900 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
901 gai_strerror(int);
902 #endif
904 #ifdef NO_SLEEP
906 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
907 sleep(unsigned int seconds);
909 #endif
911 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
912 getnameinfo_verified(const struct sockaddr *, socklen_t,
913 char *, size_t,
914 char *, size_t,
915 int);
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 *);
926 #endif
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 *);
932 #endif
934 #ifndef HAVE_GETTIMEOFDAY
935 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
936 gettimeofday (struct timeval *, void *);
937 #endif
939 #ifndef HAVE_EMALLOC
940 #define emalloc rk_emalloc
941 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
942 #endif
943 #ifndef HAVE_ECALLOC
944 #define ecalloc rk_ecalloc
945 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
946 #endif
947 #ifndef HAVE_EREALLOC
948 #define erealloc rk_erealloc
949 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
950 #endif
951 #ifndef HAVE_ESTRDUP
952 #define estrdup rk_estrdup
953 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
954 #endif
957 * kludges and such
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)
969 #else
970 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
971 #endif
973 #ifdef OPENLOG_PROTO_COMPATIBLE
974 #define roken_openlog(a,b,c) openlog(a,b,c)
975 #else
976 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
977 #endif
979 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
980 #define roken_getsockname(a,b,c) getsockname(a,b,c)
981 #else
982 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
983 #endif
985 #ifndef HAVE_SETPROGNAME
986 #define setprogname rk_setprogname
987 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
988 #endif
990 #ifndef HAVE_GETPROGNAME
991 #define getprogname rk_getprogname
992 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
993 #endif
995 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
996 extern const char *__progname;
997 #endif
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 *);
1009 #endif
1011 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1012 #ifndef HAVE_STRSVIS
1013 #define strsvis rk_strsvis
1014 #endif
1015 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1016 strsvis(char *, const char *, int, const char *);
1017 #endif
1019 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1020 #ifndef HAVE_STRSVISX
1021 #define strsvisx rk_strsvisx
1022 #endif
1023 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1024 strsvisx(char *, const char *, size_t, int, const char *);
1025 #endif
1027 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1028 #ifndef HAVE_STRUNVIS
1029 #define strunvis rk_strunvis
1030 #endif
1031 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1032 strunvis(char *, const char *);
1033 #endif
1035 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1036 #ifndef HAVE_STRVIS
1037 #define strvis rk_strvis
1038 #endif
1039 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1040 strvis(char *, const char *, int);
1041 #endif
1043 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1044 #ifndef HAVE_STRVISX
1045 #define strvisx rk_strvisx
1046 #endif
1047 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1048 strvisx(char *, const char *, size_t, int);
1049 #endif
1051 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1052 #ifndef HAVE_SVIS
1053 #define svis rk_svis
1054 #endif
1055 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1056 svis(char *, int, int, int, const char *);
1057 #endif
1059 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1060 #ifndef HAVE_UNVIS
1061 #define unvis rk_unvis
1062 #endif
1063 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1064 unvis(char *, int, int *, int);
1065 #endif
1067 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1068 #ifndef HAVE_VIS
1069 #define vis rk_vis
1070 #endif
1071 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1072 vis(char *, int, int, int);
1073 #endif
1075 #if !defined(HAVE_CLOSEFROM)
1076 #define closefrom rk_closefrom
1077 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1078 closefrom(int);
1079 #endif
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);
1085 #endif
1087 #ifdef NEED_QSORT
1088 #define qsort rk_qsort
1089 void
1090 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1091 #endif
1093 #if defined(HAVE_ARC4RANDOM)
1094 #define rk_random() arc4random()
1095 #elif defined(HAVE_RANDOM)
1096 #define rk_random() random()
1097 #else
1098 #define rk_random() rand()
1099 #endif
1102 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1103 #undef socket
1104 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1105 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1106 #endif
1108 #ifdef SOCKET_WRAPPER_REPLACE
1109 #include <socket_wrapper.h>
1110 #endif
1112 ROKEN_CPP_END