count number of enctypes too
[heimdal.git] / lib / roken / roken.h.in
bloba6299aee8e551fcc6cd44148918a4a53909bc173
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 #ifndef IN_LOOPBACKNET
109 #define IN_LOOPBACKNET 127
110 #endif
112 #ifdef _MSC_VER
113 /* Declarations for Microsoft Visual C runtime on Windows */
115 #include<process.h>
117 #include<io.h>
119 #ifndef __BIT_TYPES_DEFINED__
120 #define __BIT_TYPES_DEFINED__
122 typedef __int8 int8_t;
123 typedef __int16 int16_t;
124 typedef __int32 int32_t;
125 typedef __int64 int64_t;
126 typedef unsigned __int8 uint8_t;
127 typedef unsigned __int16 uint16_t;
128 typedef unsigned __int32 uint32_t;
129 typedef unsigned __int64 uint64_t;
130 typedef uint8_t u_int8_t;
131 typedef uint16_t u_int16_t;
132 typedef uint32_t u_int32_t;
133 typedef uint64_t u_int64_t;
135 #endif /* __BIT_TYPES_DEFINED__ */
137 #define UNREACHABLE(x) x
138 #define UNUSED_ARGUMENT(x) ((void) x)
140 #define RETSIGTYPE void
142 #define VOID_RETSIGTYPE 1
144 #ifdef VOID_RETSIGTYPE
145 #define SIGRETURN(x) return
146 #else
147 #define SIGRETURN(x) return (RETSIGTYPE)(x)
148 #endif
150 #ifndef CPP_ONLY
152 typedef int pid_t;
154 typedef unsigned int gid_t;
156 typedef unsigned int uid_t;
158 typedef unsigned short mode_t;
160 #endif
162 #ifndef __cplusplus
163 #define inline __inline
164 #endif
166 #else
168 #define UNREACHABLE(x)
169 #define UNUSED_ARGUMENT(x)
171 #endif
173 #ifdef _AIX
174 struct ether_addr;
175 struct sockaddr_dl;
176 #endif
177 #ifdef HAVE_SYS_PARAM_H
178 #include <sys/param.h>
179 #endif
180 #ifdef HAVE_INTTYPES_H
181 #include <inttypes.h>
182 #endif
183 #ifdef HAVE_SYS_TYPES_H
184 #include <sys/types.h>
185 #endif
186 #ifdef HAVE_SYS_BITYPES_H
187 #include <sys/bitypes.h>
188 #endif
189 #ifdef HAVE_BIND_BITYPES_H
190 #include <bind/bitypes.h>
191 #endif
192 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
193 #include <netinet/in6_machtypes.h>
194 #endif
195 #ifdef HAVE_UNISTD_H
196 #include <unistd.h>
197 #endif
198 #ifdef HAVE_SYS_SOCKET_H
199 #include <sys/socket.h>
200 #endif
201 #ifdef HAVE_SYS_UIO_H
202 #include <sys/uio.h>
203 #endif
204 #ifdef HAVE_GRP_H
205 #include <grp.h>
206 #endif
207 #ifdef HAVE_SYS_STAT_H
208 #include <sys/stat.h>
209 #endif
210 #ifdef HAVE_NETINET_IN_H
211 #include <netinet/in.h>
212 #endif
213 #ifdef HAVE_NETINET_IN6_H
214 #include <netinet/in6.h>
215 #endif
216 #ifdef HAVE_NETINET6_IN6_H
217 #include <netinet6/in6.h>
218 #endif
219 #ifdef HAVE_ARPA_INET_H
220 #include <arpa/inet.h>
221 #endif
222 #ifdef HAVE_NETDB_H
223 #include <netdb.h>
224 #endif
225 #ifdef HAVE_ARPA_NAMESER_H
226 #include <arpa/nameser.h>
227 #endif
228 #ifdef HAVE_RESOLV_H
229 #include <resolv.h>
230 #endif
231 #ifdef HAVE_SYSLOG_H
232 #include <syslog.h>
233 #endif
234 #ifdef HAVE_FCNTL_H
235 #include <fcntl.h>
236 #endif
237 #ifdef HAVE_ERRNO_H
238 #include <errno.h>
239 #endif
240 #include <err.h>
241 #ifdef HAVE_TERMIOS_H
242 #include <termios.h>
243 #endif
244 #ifdef HAVE_SYS_IOCTL_H
245 #include <sys/ioctl.h>
246 #endif
247 #ifdef TIME_WITH_SYS_TIME
248 #include <sys/time.h>
249 #include <time.h>
250 #elif defined(HAVE_SYS_TIME_H)
251 #include <sys/time.h>
252 #else
253 #include <time.h>
254 #endif
256 #ifdef HAVE_PATHS_H
257 #include <paths.h>
258 #endif
260 #ifdef HAVE_DIRENT_H
261 #include <dirent.h>
262 #endif
264 #ifdef BACKSLASH_PATH_DELIM
265 #define rk_PATH_DELIM '\\'
266 #endif
268 #ifndef HAVE_SSIZE_T
269 #ifndef SSIZE_T_DEFINED
270 #ifdef ssize_t
271 #undef ssize_t
272 #endif
273 #ifdef _WIN64
274 typedef __int64 ssize_t;
275 #else
276 typedef int ssize_t;
277 #endif
278 #define SSIZE_T_DEFINED
279 #endif /* SSIZE_T_DEFINED */
280 #endif /* HAVE_SSIZE_T */
282 #include <roken-common.h>
284 ROKEN_CPP_START
286 #ifdef HAVE_UINTPTR_T
287 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
288 #else
289 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
290 #endif
292 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
293 #define setsid _setsid
294 #endif
296 #ifdef _MSC_VER
297 /* Additional macros for Visual C/C++ runtime */
299 #define close _close
301 #define getpid _getpid
303 #define open _open
305 #define chdir _chdir
307 #define fsync _commit
309 /* The MSVC implementation of snprintf is not C99 compliant. */
310 #define snprintf rk_snprintf
311 #define vsnprintf rk_vsnprintf
312 #define vasnprintf rk_vasnprintf
313 #define vasprintf rk_vasprintf
314 #define asnprintf rk_asnprintf
315 #define asprintf rk_asprintf
317 #define _PIPE_BUFFER_SZ 8192
318 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
320 #define ftruncate(fd, sz) _chsize((fd), (sz))
322 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
323 rk_snprintf (char *str, size_t sz, const char *format, ...);
325 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
326 rk_asprintf (char **ret, const char *format, ...);
328 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
329 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
331 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
332 rk_vasprintf (char **ret, const char *format, va_list args);
334 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
335 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
337 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
338 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
340 /* missing stat.h predicates */
342 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
344 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
346 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
348 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
350 /* The following are not implemented:
352 S_ISLNK(m)
353 S_ISSOCK(m)
354 S_ISBLK(m)
357 #endif /* _MSC_VER */
359 #ifdef HAVE_WINSOCK
361 /* While we are at it, define WinSock specific scatter gather socket
362 I/O. */
364 #define iovec _WSABUF
365 #define iov_base buf
366 #define iov_len len
368 struct msghdr {
369 void *msg_name;
370 socklen_t msg_namelen;
371 struct iovec *msg_iov;
372 size_t msg_iovlen;
373 void *msg_control;
374 socklen_t msg_controllen;
375 int msg_flags;
378 #define sendmsg sendmsg_w32
380 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
381 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
383 #endif /* HAVE_WINSOCK */
385 #ifndef HAVE_PUTENV
386 #define putenv rk_putenv
387 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
388 #endif
390 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
391 #ifndef HAVE_SETENV
392 #define setenv rk_setenv
393 #endif
394 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
395 #endif
397 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
398 #ifndef HAVE_UNSETENV
399 #define unsetenv rk_unsetenv
400 #endif
401 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
402 #endif
404 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
405 #ifndef HAVE_GETUSERSHELL
406 #define getusershell rk_getusershell
407 #define endusershell rk_endusershell
408 #endif
409 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
410 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
411 #endif
413 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
414 #ifndef HAVE_SNPRINTF
415 #define snprintf rk_snprintf
416 #endif
417 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
418 rk_snprintf (char *, size_t, const char *, ...)
419 __attribute__ ((format (printf, 3, 4)));
420 #endif
422 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
423 #ifndef HAVE_VSNPRINTF
424 #define vsnprintf rk_vsnprintf
425 #endif
426 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
427 rk_vsnprintf (char *, size_t, const char *, va_list)
428 __attribute__((format (printf, 3, 0)));
429 #endif
431 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
432 #ifndef HAVE_ASPRINTF
433 #define asprintf rk_asprintf
434 #endif
435 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
436 rk_asprintf (char **, const char *, ...)
437 __attribute__ ((format (printf, 2, 3)));
438 #endif
440 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
441 #ifndef HAVE_VASPRINTF
442 #define vasprintf rk_vasprintf
443 #endif
444 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
445 rk_vasprintf (char **, const char *, va_list)
446 __attribute__((format (printf, 2, 0)));
447 #endif
449 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
450 #ifndef HAVE_ASNPRINTF
451 #define asnprintf rk_asnprintf
452 #endif
453 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
454 rk_asnprintf (char **, size_t, const char *, ...)
455 __attribute__ ((format (printf, 3, 4)));
456 #endif
458 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
459 #ifndef HAVE_VASNPRINTF
460 #define vasnprintf rk_vasnprintf
461 #endif
462 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
463 vasnprintf (char **, size_t, const char *, va_list)
464 __attribute__((format (printf, 3, 0)));
465 #endif
467 #ifndef HAVE_STRDUP
468 #define strdup rk_strdup
469 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
470 #endif
472 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
473 #ifndef HAVE_STRNDUP
474 #define strndup rk_strndup
475 #endif
476 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
477 #endif
479 #ifndef HAVE_STRLWR
480 #define strlwr rk_strlwr
481 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
482 #endif
484 #ifndef HAVE_STRNLEN
485 #define strnlen rk_strnlen
486 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
487 #endif
489 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
490 #ifndef HAVE_STRSEP
491 #define strsep rk_strsep
492 #endif
493 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
494 #endif
496 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
497 #ifndef HAVE_STRSEP_COPY
498 #define strsep_copy rk_strsep_copy
499 #endif
500 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
501 #endif
503 #ifndef HAVE_STRCASECMP
504 #define strcasecmp rk_strcasecmp
505 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
506 #endif
508 #ifdef NEED_FCLOSE_PROTO
509 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
510 #endif
512 #ifdef NEED_STRTOK_R_PROTO
513 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
514 #endif
516 #ifndef HAVE_STRUPR
517 #define strupr rk_strupr
518 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
519 #endif
521 #ifndef HAVE_STRLCPY
522 #define strlcpy rk_strlcpy
523 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
524 #endif
526 #ifndef HAVE_STRLCAT
527 #define strlcat rk_strlcat
528 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
529 #endif
531 #ifndef HAVE_GETDTABLESIZE
532 #define getdtablesize rk_getdtablesize
533 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
534 #endif
536 #if !defined(HAVE_STRERROR) && !defined(strerror)
537 #define strerror rk_strerror
538 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
539 #endif
541 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
542 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
543 #else
544 #define rk_strerror_r strerror_r
545 #endif
547 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
548 #ifndef HAVE_HSTRERROR
549 #define hstrerror rk_hstrerror
550 #endif
551 /* This causes a fatal error under Psoriasis */
552 #ifndef SunOS
553 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
554 #endif
555 #endif
557 #if !HAVE_DECL_H_ERRNO
558 extern int h_errno;
559 #endif
561 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
562 #ifndef HAVE_INET_ATON
563 #define inet_aton rk_inet_aton
564 #endif
565 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
566 #endif
568 #ifndef HAVE_INET_NTOP
569 #define inet_ntop rk_inet_ntop
570 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
571 inet_ntop(int af, const void *src, char *dst, size_t size);
572 #endif
574 #ifndef HAVE_INET_PTON
575 #define inet_pton rk_inet_pton
576 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
577 inet_pton(int, const char *, void *);
578 #endif
580 #ifndef HAVE_GETCWD
581 #define getcwd rk_getcwd
582 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
583 #endif
585 #ifdef HAVE_PWD_H
586 #include <pwd.h>
587 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
588 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
589 #endif
591 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
593 #ifndef HAVE_SETEUID
594 #define seteuid rk_seteuid
595 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
596 #endif
598 #ifndef HAVE_SETEGID
599 #define setegid rk_setegid
600 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
601 #endif
603 #ifndef HAVE_LSTAT
604 #define lstat rk_lstat
605 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
606 #endif
608 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
609 #ifndef HAVE_MKSTEMP
610 #define mkstemp rk_mkstemp
611 #endif
612 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
613 #endif
615 #ifndef HAVE_CGETENT
616 #define cgetent rk_cgetent
617 #define cgetstr rk_cgetstr
618 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
619 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
620 #endif
622 #ifndef HAVE_INITGROUPS
623 #define initgroups rk_initgroups
624 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
625 #endif
627 #ifndef HAVE_FCHOWN
628 #define fchown rk_fchown
629 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
630 #endif
632 #ifdef RENAME_DOES_NOT_UNLINK
633 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
634 #else
635 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
636 #endif
638 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
639 #ifndef HAVE_DAEMON
640 #define daemon rk_daemon
641 #endif
642 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
643 #endif
645 #ifndef HAVE_CHOWN
646 #define chown rk_chown
647 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
648 #endif
650 #ifndef HAVE_RCMD
651 #define rcmd rk_rcmd
652 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
653 rcmd(char **, unsigned short, const char *,
654 const char *, const char *, int *);
655 #endif
657 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
658 #ifndef HAVE_INNETGR
659 #define innetgr rk_innetgr
660 #endif
661 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
662 const char*, const char*);
663 #endif
665 #ifndef HAVE_IRUSEROK
666 #define iruserok rk_iruserok
667 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
668 const char *, const char *);
669 #endif
671 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
672 #ifndef HAVE_GETHOSTNAME
673 #define gethostname rk_gethostname
674 #endif
675 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
676 #endif
678 #ifndef HAVE_WRITEV
679 #define writev rk_writev
680 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
681 writev(int, const struct iovec *, int);
682 #endif
684 #ifndef HAVE_READV
685 #define readv rk_readv
686 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
687 readv(int, const struct iovec *, int);
688 #endif
690 #ifndef HAVE_PIDFILE
691 #ifdef NO_PIDFILES
692 #define pidfile(x) ((void) 0)
693 #else
694 #define pidfile rk_pidfile
695 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
696 #endif
697 #endif
699 #ifndef HAVE_BSWAP32
700 #define bswap32 rk_bswap32
701 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
702 #endif
704 #ifndef HAVE_BSWAP16
705 #define bswap16 rk_bswap16
706 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
707 #endif
709 #ifndef HAVE_FLOCK
710 #ifndef LOCK_SH
711 #define LOCK_SH 1 /* Shared lock */
712 #endif
713 #ifndef LOCK_EX
714 #define LOCK_EX 2 /* Exclusive lock */
715 #endif
716 #ifndef LOCK_NB
717 #define LOCK_NB 4 /* Don't block when locking */
718 #endif
719 #ifndef LOCK_UN
720 #define LOCK_UN 8 /* Unlock */
721 #endif
723 #define flock(_x,_y) rk_flock(_x,_y)
724 int rk_flock(int fd, int operation);
725 #endif /* HAVE_FLOCK */
727 #ifndef HAVE_DIRFD
728 #ifdef HAVE_DIR_DD_FD
729 #define dirfd(x) ((x)->dd_fd)
730 #else
731 #ifndef _WIN32 /* Windows code never calls dirfd */
732 #error Missing dirfd() and ->dd_fd
733 #endif
734 #endif
735 #endif
737 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
739 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
741 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
743 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
745 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
747 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
748 roken_vmconcat (char **, size_t, va_list);
750 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
751 net_write (rk_socket_t, const void *, size_t);
753 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
754 net_read (rk_socket_t, void *, size_t);
756 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
757 issuid(void);
759 #ifndef HAVE_STRUCT_WINSIZE
760 struct winsize {
761 unsigned short ws_row, ws_col;
762 unsigned short ws_xpixel, ws_ypixel;
764 #endif
766 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *);
768 #ifndef HAVE_VSYSLOG
769 #define vsyslog rk_vsyslog
770 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
771 #endif
773 #ifndef HAVE_GETOPT
774 #define getopt rk_getopt
775 #define optarg rk_optarg
776 #define optind rk_optind
777 #define opterr rk_opterr
778 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
779 getopt(int nargc, char * const *nargv, const char *ostr);
780 #endif
782 #if !HAVE_DECL_OPTARG
783 ROKEN_LIB_VARIABLE extern char *optarg;
784 #endif
785 #if !HAVE_DECL_OPTIND
786 ROKEN_LIB_VARIABLE extern int optind;
787 #endif
788 #if !HAVE_DECL_OPTERR
789 ROKEN_LIB_VARIABLE extern int opterr;
790 #endif
792 #ifndef HAVE_GETIPNODEBYNAME
793 #define getipnodebyname rk_getipnodebyname
794 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
795 getipnodebyname (const char *, int, int, int *);
796 #endif
798 #ifndef HAVE_GETIPNODEBYADDR
799 #define getipnodebyaddr rk_getipnodebyaddr
800 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
801 getipnodebyaddr (const void *, size_t, int, int *);
802 #endif
804 #ifndef HAVE_FREEHOSTENT
805 #define freehostent rk_freehostent
806 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
807 freehostent (struct hostent *);
808 #endif
810 #ifndef HAVE_COPYHOSTENT
811 #define copyhostent rk_copyhostent
812 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
813 copyhostent (const struct hostent *);
814 #endif
816 #ifndef HAVE_SOCKLEN_T
817 typedef int socklen_t;
818 #endif
820 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
822 #ifndef HAVE_SA_FAMILY_T
823 typedef unsigned short sa_family_t;
824 #endif
826 #ifdef HAVE_IPV6
827 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
828 #else
829 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
830 #endif
832 #define _SS_ALIGNSIZE sizeof(unsigned long)
834 #if HAVE_STRUCT_SOCKADDR_SA_LEN
836 typedef unsigned char roken_sa_family_t;
838 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
839 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
841 struct sockaddr_storage {
842 unsigned char ss_len;
843 roken_sa_family_t ss_family;
844 char __ss_pad1[_SS_PAD1SIZE];
845 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
848 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
850 typedef unsigned short roken_sa_family_t;
852 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
853 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
855 struct sockaddr_storage {
856 roken_sa_family_t ss_family;
857 char __ss_pad1[_SS_PAD1SIZE];
858 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
861 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
863 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
865 #ifndef HAVE_STRUCT_ADDRINFO
866 struct addrinfo {
867 int ai_flags;
868 int ai_family;
869 int ai_socktype;
870 int ai_protocol;
871 size_t ai_addrlen;
872 char *ai_canonname;
873 struct sockaddr *ai_addr;
874 struct addrinfo *ai_next;
876 #endif
878 #ifndef HAVE_GETADDRINFO
879 #define getaddrinfo rk_getaddrinfo
880 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
881 getaddrinfo(const char *,
882 const char *,
883 const struct addrinfo *,
884 struct addrinfo **);
885 #endif
887 #ifndef HAVE_GETNAMEINFO
888 #define getnameinfo rk_getnameinfo
889 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
890 getnameinfo(const struct sockaddr *, socklen_t,
891 char *, size_t,
892 char *, size_t,
893 int);
894 #endif
896 #ifndef HAVE_FREEADDRINFO
897 #define freeaddrinfo rk_freeaddrinfo
898 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
899 freeaddrinfo(struct addrinfo *);
900 #endif
902 #ifndef HAVE_GAI_STRERROR
903 #define gai_strerror rk_gai_strerror
904 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
905 gai_strerror(int);
906 #endif
908 #ifdef NO_SLEEP
910 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
911 sleep(unsigned int seconds);
913 #endif
915 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
916 getnameinfo_verified(const struct sockaddr *, socklen_t,
917 char *, size_t,
918 char *, size_t,
919 int);
921 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
922 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
923 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
924 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
926 #ifndef HAVE_STRFTIME
927 #define strftime rk_strftime
928 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
929 strftime (char *, size_t, const char *, const struct tm *);
930 #endif
932 #ifndef HAVE_STRPTIME
933 #define strptime rk_strptime
934 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
935 strptime (const char *, const char *, struct tm *);
936 #endif
938 #ifndef HAVE_GETTIMEOFDAY
939 #define gettimeofday rk_gettimeofday
940 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
941 gettimeofday (struct timeval *, void *);
942 #endif
944 #ifndef HAVE_EMALLOC
945 #define emalloc rk_emalloc
946 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
947 #endif
948 #ifndef HAVE_ECALLOC
949 #define ecalloc rk_ecalloc
950 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
951 #endif
952 #ifndef HAVE_EREALLOC
953 #define erealloc rk_erealloc
954 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
955 #endif
956 #ifndef HAVE_ESTRDUP
957 #define estrdup rk_estrdup
958 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
959 #endif
962 * kludges and such
965 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
966 roken_gethostby_setup(const char*, const char*);
967 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
968 roken_gethostbyname(const char*);
969 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
970 roken_gethostbyaddr(const void*, size_t, int);
972 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
973 #define roken_getservbyname(x,y) getservbyname(x,y)
974 #else
975 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
976 #endif
978 #ifdef OPENLOG_PROTO_COMPATIBLE
979 #define roken_openlog(a,b,c) openlog(a,b,c)
980 #else
981 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
982 #endif
984 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
985 #define roken_getsockname(a,b,c) getsockname(a,b,c)
986 #else
987 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
988 #endif
990 #ifndef HAVE_SETPROGNAME
991 #define setprogname rk_setprogname
992 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
993 #endif
995 #ifndef HAVE_GETPROGNAME
996 #define getprogname rk_getprogname
997 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
998 #endif
1000 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1001 extern const char *__progname;
1002 #endif
1004 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1005 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1007 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1008 mini_inetd (int, rk_socket_t *);
1010 #ifndef HAVE_LOCALTIME_R
1011 #define localtime_r rk_localtime_r
1012 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1013 localtime_r(const time_t *, struct tm *);
1014 #endif
1016 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1017 #ifndef HAVE_STRSVIS
1018 #define strsvis rk_strsvis
1019 #endif
1020 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1021 strsvis(char *, const char *, int, const char *);
1022 #endif
1024 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1025 #ifndef HAVE_STRSVISX
1026 #define strsvisx rk_strsvisx
1027 #endif
1028 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1029 strsvisx(char *, const char *, size_t, int, const char *);
1030 #endif
1032 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1033 #ifndef HAVE_STRUNVIS
1034 #define strunvis rk_strunvis
1035 #endif
1036 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1037 strunvis(char *, const char *);
1038 #endif
1040 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1041 #ifndef HAVE_STRVIS
1042 #define strvis rk_strvis
1043 #endif
1044 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1045 strvis(char *, const char *, int);
1046 #endif
1048 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1049 #ifndef HAVE_STRVISX
1050 #define strvisx rk_strvisx
1051 #endif
1052 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1053 strvisx(char *, const char *, size_t, int);
1054 #endif
1056 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1057 #ifndef HAVE_SVIS
1058 #define svis rk_svis
1059 #endif
1060 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1061 svis(char *, int, int, int, const char *);
1062 #endif
1064 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1065 #ifndef HAVE_UNVIS
1066 #define unvis rk_unvis
1067 #endif
1068 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1069 unvis(char *, int, int *, int);
1070 #endif
1072 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1073 #ifndef HAVE_VIS
1074 #define vis rk_vis
1075 #endif
1076 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1077 vis(char *, int, int, int);
1078 #endif
1080 #if !defined(HAVE_CLOSEFROM)
1081 #define closefrom rk_closefrom
1082 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1083 closefrom(int);
1084 #endif
1086 #if !defined(HAVE_TIMEGM)
1087 #define timegm rk_timegm
1088 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1089 rk_timegm(struct tm *tm);
1090 #endif
1092 #ifdef NEED_QSORT
1093 #define qsort rk_qsort
1094 void
1095 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1096 #endif
1098 #if defined(HAVE_ARC4RANDOM)
1099 #define rk_random() arc4random()
1100 #elif defined(HAVE_RANDOM)
1101 #define rk_random() random()
1102 #else
1103 #define rk_random() rand()
1104 #endif
1106 #ifndef HAVE_TDELETE
1107 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1108 #endif
1109 #ifndef HAVE_TFIND
1110 #define tfind(a,b,c) rk_tfind(a,b,c)
1111 #endif
1112 #ifndef HAVE_TSEARCH
1113 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1114 #endif
1115 #ifndef HAVE_TWALK
1116 #define twalk(a,b) rk_twalk(a,b)
1117 #endif
1119 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1120 #undef socket
1121 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1122 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1123 #endif
1125 #ifdef SOCKET_WRAPPER_REPLACE
1126 #include <socket_wrapper.h>
1127 #endif
1129 ROKEN_CPP_END