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 <signal.h>
43
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
60
61 #ifdef HAVE_WINSOCK
62 /* Declarations for Microsoft Windows */
63
64 #include <winsock2.h>
65 #include <ws2tcpip.h>
66
67 /*
68  * error codes for inet_ntop/inet_pton
69  */
70 #define EAFNOSUPPORT WSAEAFNOSUPPORT
71
72 typedef SOCKET rk_socket_t;
73
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()
79
80 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
81
82 #define ETIMEDOUT               WSAETIMEDOUT
83 #define EWOULDBLOCK             WSAEWOULDBLOCK
84 #define ENOTSOCK                WSAENOTSOCK
85
86 #define rk_SOCK_INIT() rk_WSAStartup()
87 #define rk_SOCK_EXIT() rk_WSACleanup()
88
89 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
90 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
91
92 #else  /* not WinSock */
93
94 typedef int rk_socket_t;
95
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)
102
103 #define rk_SOCK_INIT() 0
104 #define rk_SOCK_EXIT() do { } while(0)
105
106 #endif
107
108 #ifdef _MSC_VER
109 /* Declarations for Microsoft Visual C runtime on Windows */
110
111 #include<process.h>
112
113 #include<io.h>
114
115 #ifndef __BIT_TYPES_DEFINED__
116 #define __BIT_TYPES_DEFINED__
117
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;
130
131 #endif  /* __BIT_TYPES_DEFINED__ */
132
133 #define UNREACHABLE(x) x
134 #define UNUSED_ARGUMENT(x) ((void) x)
135
136 #define RETSIGTYPE void
137
138 #define VOID_RETSIGTYPE 1
139
140 #ifdef VOID_RETSIGTYPE
141 #define SIGRETURN(x) return
142 #else
143 #define SIGRETURN(x) return (RETSIGTYPE)(x)
144 #endif
145
146 #ifndef CPP_ONLY
147
148 typedef int pid_t;
149
150 typedef unsigned int gid_t;
151
152 typedef unsigned int uid_t;
153
154 typedef unsigned short mode_t;
155
156 #endif
157
158 #ifndef __cplusplus
159 #define inline __inline
160 #endif
161
162 #else
163
164 #define UNREACHABLE(x)
165 #define UNUSED_ARGUMENT(x)
166
167 #endif
168
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
251
252 #ifdef HAVE_WS2TCPIP_H
253 #include <ws2tcpip.h>
254 #endif
255
256 #ifdef HAVE_PATHS_H
257 #include <paths.h>
258 #endif
259
260 #ifdef HAVE_DIRENT_H
261 #include <dirent.h>
262 #endif
263
264 #ifdef BACKSLASH_PATH_DELIM
265 #define rk_PATH_DELIM '\\'
266 #endif
267
268 #ifndef HAVE_SSIZE_T
269 #ifdef _WIN64
270 typedef __int64 ssize_t;
271 #else
272 typedef int ssize_t;
273 #endif
274 #endif
275
276 #include <roken-common.h>
277
278 ROKEN_CPP_START
279
280 #ifdef HAVE_UINTPTR_T
281 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
282 #else
283 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
284 #endif
285
286 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
287 #define setsid _setsid
288 #endif
289
290 #ifdef _MSC_VER
291 /* Additional macros for Visual C/C++ runtime */
292
293 #define close   _close
294
295 #define getpid  _getpid
296
297 #define open    _open
298
299 #define chdir   _chdir
300
301 #define fsync   _commit
302
303 /* The MSVC implementation of snprintf is not C99 compliant.  */
304 #define snprintf    rk_snprintf
305 #define vsnprintf   rk_vsnprintf
306 #define vasnprintf  rk_vasnprintf
307 #define vasprintf   rk_vasprintf
308 #define asnprintf   rk_asnprintf
309 #define asprintf    rk_asprintf
310
311 #define _PIPE_BUFFER_SZ 8192
312 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
313
314 #define ftruncate(fd, sz) _chsize((fd), (sz))
315
316 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
317 rk_snprintf (char *str, size_t sz, const char *format, ...);
318
319 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
320 rk_asprintf (char **ret, const char *format, ...);
321
322 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
323 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
324
325 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
326 rk_vasprintf (char **ret, const char *format, va_list args);
327
328 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
329 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
330
331 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
332 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
333
334 /* missing stat.h predicates */
335
336 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
337
338 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
339
340 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
341
342 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
343
344 /* The following are not implemented:
345
346  S_ISLNK(m)
347  S_ISSOCK(m)
348  S_ISBLK(m)
349 */
350
351 #endif  /* _MSC_VER */
352
353 #ifdef HAVE_WINSOCK
354
355 /* While we are at it, define WinSock specific scatter gather socket
356    I/O. */
357
358 #define iovec    _WSABUF
359 #define iov_base buf
360 #define iov_len  len
361
362 struct msghdr {
363     void           *msg_name;
364     socklen_t       msg_namelen;
365     struct iovec   *msg_iov;
366     size_t          msg_iovlen;
367     void           *msg_control;
368     socklen_t       msg_controllen;
369     int             msg_flags;
370 };
371
372 #define sendmsg sendmsg_w32
373
374 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
375 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
376
377 #endif  /* HAVE_WINSOCK */
378
379 #ifndef HAVE_PUTENV
380 #define putenv rk_putenv
381 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
382 #endif
383
384 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
385 #ifndef HAVE_SETENV
386 #define setenv rk_setenv
387 #endif
388 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
389 #endif
390
391 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
392 #ifndef HAVE_UNSETENV
393 #define unsetenv rk_unsetenv
394 #endif
395 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
396 #endif
397
398 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
399 #ifndef HAVE_GETUSERSHELL
400 #define getusershell rk_getusershell
401 #define endusershell rk_endusershell
402 #endif
403 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
404 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
405 #endif
406
407 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
408 #ifndef HAVE_SNPRINTF
409 #define snprintf rk_snprintf
410 #endif
411 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
412      rk_snprintf (char *, size_t, const char *, ...)
413      __attribute__ ((format (printf, 3, 4)));
414 #endif
415
416 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
417 #ifndef HAVE_VSNPRINTF
418 #define vsnprintf rk_vsnprintf
419 #endif
420 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
421      rk_vsnprintf (char *, size_t, const char *, va_list)
422      __attribute__((format (printf, 3, 0)));
423 #endif
424
425 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
426 #ifndef HAVE_ASPRINTF
427 #define asprintf rk_asprintf
428 #endif
429 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
430      rk_asprintf (char **, const char *, ...)
431      __attribute__ ((format (printf, 2, 3)));
432 #endif
433
434 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
435 #ifndef HAVE_VASPRINTF
436 #define vasprintf rk_vasprintf
437 #endif
438 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
439     rk_vasprintf (char **, const char *, va_list)
440      __attribute__((format (printf, 2, 0)));
441 #endif
442
443 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
444 #ifndef HAVE_ASNPRINTF
445 #define asnprintf rk_asnprintf
446 #endif
447 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
448     rk_asnprintf (char **, size_t, const char *, ...)
449      __attribute__ ((format (printf, 3, 4)));
450 #endif
451
452 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
453 #ifndef HAVE_VASNPRINTF
454 #define vasnprintf rk_vasnprintf
455 #endif
456 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
457     vasnprintf (char **, size_t, const char *, va_list)
458      __attribute__((format (printf, 3, 0)));
459 #endif
460
461 #ifndef HAVE_STRDUP
462 #define strdup rk_strdup
463 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
464 #endif
465
466 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
467 #ifndef HAVE_STRNDUP
468 #define strndup rk_strndup
469 #endif
470 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
471 #endif
472
473 #ifndef HAVE_STRLWR
474 #define strlwr rk_strlwr
475 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
476 #endif
477
478 #ifndef HAVE_STRNLEN
479 #define strnlen rk_strnlen
480 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
481 #endif
482
483 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
484 #ifndef HAVE_STRSEP
485 #define strsep rk_strsep
486 #endif
487 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
488 #endif
489
490 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
491 #ifndef HAVE_STRSEP_COPY
492 #define strsep_copy rk_strsep_copy
493 #endif
494 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
495 #endif
496
497 #ifndef HAVE_STRCASECMP
498 #define strcasecmp rk_strcasecmp
499 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
500 #endif
501
502 #ifdef NEED_FCLOSE_PROTO
503 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
504 #endif
505
506 #ifdef NEED_STRTOK_R_PROTO
507 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
508 #endif
509
510 #ifndef HAVE_STRUPR
511 #define strupr rk_strupr
512 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
513 #endif
514
515 #ifndef HAVE_STRLCPY
516 #define strlcpy rk_strlcpy
517 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
518 #endif
519
520 #ifndef HAVE_STRLCAT
521 #define strlcat rk_strlcat
522 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
523 #endif
524
525 #ifndef HAVE_GETDTABLESIZE
526 #define getdtablesize rk_getdtablesize
527 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
528 #endif
529
530 #if !defined(HAVE_STRERROR) && !defined(strerror)
531 #define strerror rk_strerror
532 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
533 #endif
534
535 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
536 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
537 #else
538 #define rk_strerror_r strerror_r
539 #endif
540
541 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
542 #ifndef HAVE_HSTRERROR
543 #define hstrerror rk_hstrerror
544 #endif
545 /* This causes a fatal error under Psoriasis */
546 #ifndef SunOS
547 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
548 #endif
549 #endif
550
551 #if !HAVE_DECL_H_ERRNO
552 extern int h_errno;
553 #endif
554
555 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
556 #ifndef HAVE_INET_ATON
557 #define inet_aton rk_inet_aton
558 #endif
559 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
560 #endif
561
562 #ifndef HAVE_INET_NTOP
563 #define inet_ntop rk_inet_ntop
564 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
565 inet_ntop(int af, const void *src, char *dst, size_t size);
566 #endif
567
568 #ifndef HAVE_INET_PTON
569 #define inet_pton rk_inet_pton
570 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
571 inet_pton(int, const char *, void *);
572 #endif
573
574 #ifndef HAVE_GETCWD
575 #define getcwd rk_getcwd
576 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
577 #endif
578
579 #ifdef HAVE_PWD_H
580 #include <pwd.h>
581 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
582 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
583 #endif
584
585 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
586
587 #ifndef HAVE_SETEUID
588 #define seteuid rk_seteuid
589 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
590 #endif
591
592 #ifndef HAVE_SETEGID
593 #define setegid rk_setegid
594 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
595 #endif
596
597 #ifndef HAVE_LSTAT
598 #define lstat rk_lstat
599 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
600 #endif
601
602 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
603 #ifndef HAVE_MKSTEMP
604 #define mkstemp rk_mkstemp
605 #endif
606 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
607 #endif
608
609 #ifndef HAVE_CGETENT
610 #define cgetent rk_cgetent
611 #define cgetstr rk_cgetstr
612 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
613 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
614 #endif
615
616 #ifndef HAVE_INITGROUPS
617 #define initgroups rk_initgroups
618 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
619 #endif
620
621 #ifndef HAVE_FCHOWN
622 #define fchown rk_fchown
623 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
624 #endif
625
626 #ifdef RENAME_DOES_NOT_UNLINK
627 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
628 #else
629 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
630 #endif
631
632 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
633 #ifndef HAVE_DAEMON
634 #define daemon rk_daemon
635 #endif
636 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
637 #endif
638
639 #ifndef HAVE_CHOWN
640 #define chown rk_chown
641 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
642 #endif
643
644 #ifndef HAVE_RCMD
645 #define rcmd rk_rcmd
646 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
647     rcmd(char **, unsigned short, const char *,
648          const char *, const char *, int *);
649 #endif
650
651 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
652 #ifndef HAVE_INNETGR
653 #define innetgr rk_innetgr
654 #endif
655 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
656     const char*, const char*);
657 #endif
658
659 #ifndef HAVE_IRUSEROK
660 #define iruserok rk_iruserok
661 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
662     const char *, const char *);
663 #endif
664
665 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
666 #ifndef HAVE_GETHOSTNAME
667 #define gethostname rk_gethostname
668 #endif
669 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
670 #endif
671
672 #ifndef HAVE_WRITEV
673 #define writev rk_writev
674 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
675 writev(int, const struct iovec *, int);
676 #endif
677
678 #ifndef HAVE_READV
679 #define readv rk_readv
680 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
681 readv(int, const struct iovec *, int);
682 #endif
683
684 #ifndef HAVE_PIDFILE
685 #ifdef NO_PIDFILES
686 #define pidfile(x) ((void) 0)
687 #else
688 #define pidfile rk_pidfile
689 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
690 #endif
691 #endif
692
693 #ifndef HAVE_BSWAP32
694 #define bswap32 rk_bswap32
695 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
696 #endif
697
698 #ifndef HAVE_BSWAP16
699 #define bswap16 rk_bswap16
700 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
701 #endif
702
703 #ifndef HAVE_FLOCK
704 #ifndef LOCK_SH
705 #define LOCK_SH   1             /* Shared lock */
706 #endif
707 #ifndef LOCK_EX
708 #define LOCK_EX   2             /* Exclusive lock */
709 #endif
710 #ifndef LOCK_NB
711 #define LOCK_NB   4             /* Don't block when locking */
712 #endif
713 #ifndef LOCK_UN
714 #define LOCK_UN   8             /* Unlock */
715 #endif
716
717 #define flock(_x,_y) rk_flock(_x,_y)
718 int rk_flock(int fd, int operation);
719 #endif /* HAVE_FLOCK */
720
721 #ifndef HAVE_DIRFD
722 #ifdef HAVE_DIR_DD_FD
723 #define dirfd(x) ((x)->dd_fd)
724 #else
725 #ifndef _WIN32 /* Windows code never calls dirfd */
726 #error Missing dirfd() and ->dd_fd
727 #endif
728 #endif
729 #endif
730
731 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
732
733 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
734
735 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
736
737 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
738
739 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
740
741 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
742     roken_vmconcat (char **, size_t, va_list);
743
744 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
745     net_write (rk_socket_t, const void *, size_t);
746
747 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
748     net_read (rk_socket_t, void *, size_t);
749
750 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
751     issuid(void);
752
753 #ifndef HAVE_STRUCT_WINSIZE
754 struct winsize {
755         unsigned short ws_row, ws_col;
756         unsigned short ws_xpixel, ws_ypixel;
757 };
758 #endif
759
760 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
761
762 #ifndef HAVE_VSYSLOG
763 #define vsyslog rk_vsyslog
764 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
765 #endif
766
767 #ifndef HAVE_GETOPT
768 #define getopt rk_getopt
769 #define optarg rk_optarg
770 #define optind rk_optind
771 #define opterr rk_opterr
772 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
773 getopt(int nargc, char * const *nargv, const char *ostr);
774 #endif
775
776 #if !HAVE_DECL_OPTARG
777 ROKEN_LIB_VARIABLE extern char *optarg;
778 #endif
779 #if !HAVE_DECL_OPTIND
780 ROKEN_LIB_VARIABLE extern int optind;
781 #endif
782 #if !HAVE_DECL_OPTERR
783 ROKEN_LIB_VARIABLE extern int opterr;
784 #endif
785
786 #ifndef HAVE_GETIPNODEBYNAME
787 #define getipnodebyname rk_getipnodebyname
788 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
789 getipnodebyname (const char *, int, int, int *);
790 #endif
791
792 #ifndef HAVE_GETIPNODEBYADDR
793 #define getipnodebyaddr rk_getipnodebyaddr
794 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
795 getipnodebyaddr (const void *, size_t, int, int *);
796 #endif
797
798 #ifndef HAVE_FREEHOSTENT
799 #define freehostent rk_freehostent
800 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
801 freehostent (struct hostent *);
802 #endif
803
804 #ifndef HAVE_COPYHOSTENT
805 #define copyhostent rk_copyhostent
806 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
807 copyhostent (const struct hostent *);
808 #endif
809
810 #ifndef HAVE_SOCKLEN_T
811 typedef int socklen_t;
812 #endif
813
814 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
815
816 #ifndef HAVE_SA_FAMILY_T
817 typedef unsigned short sa_family_t;
818 #endif
819
820 #ifdef HAVE_IPV6
821 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
822 #else
823 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
824 #endif
825
826 #define _SS_ALIGNSIZE   sizeof(unsigned long)
827
828 #if HAVE_STRUCT_SOCKADDR_SA_LEN
829
830 typedef unsigned char roken_sa_family_t;
831
832 #define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
833 #define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
834
835 struct sockaddr_storage {
836     unsigned char       ss_len;
837     roken_sa_family_t   ss_family;
838     char                __ss_pad1[_SS_PAD1SIZE];
839     unsigned long       __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
840 };
841
842 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
843
844 typedef unsigned short roken_sa_family_t;
845
846 #define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
847 #define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
848
849 struct sockaddr_storage {
850     roken_sa_family_t   ss_family;
851     char                __ss_pad1[_SS_PAD1SIZE];
852     unsigned long       __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
853 };
854
855 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
856
857 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
858
859 #ifndef HAVE_STRUCT_ADDRINFO
860 struct addrinfo {
861     int    ai_flags;
862     int    ai_family;
863     int    ai_socktype;
864     int    ai_protocol;
865     size_t ai_addrlen;
866     char  *ai_canonname;
867     struct sockaddr *ai_addr;
868     struct addrinfo *ai_next;
869 };
870 #endif
871
872 #ifndef HAVE_GETADDRINFO
873 #define getaddrinfo rk_getaddrinfo
874 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
875 getaddrinfo(const char *,
876             const char *,
877             const struct addrinfo *,
878             struct addrinfo **);
879 #endif
880
881 #ifndef HAVE_GETNAMEINFO
882 #define getnameinfo rk_getnameinfo
883 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
884 getnameinfo(const struct sockaddr *, socklen_t,
885                 char *, size_t,
886                 char *, size_t,
887                 int);
888 #endif
889
890 #ifndef HAVE_FREEADDRINFO
891 #define freeaddrinfo rk_freeaddrinfo
892 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
893 freeaddrinfo(struct addrinfo *);
894 #endif
895
896 #ifndef HAVE_GAI_STRERROR
897 #define gai_strerror rk_gai_strerror
898 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
899 gai_strerror(int);
900 #endif
901
902 #ifdef NO_SLEEP
903
904 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
905 sleep(unsigned int seconds);
906
907 #endif
908
909 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
910 getnameinfo_verified(const struct sockaddr *, socklen_t,
911                      char *, size_t,
912                      char *, size_t,
913                      int);
914
915 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
916 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
917 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
918 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
919
920 #ifndef HAVE_STRFTIME
921 #define strftime rk_strftime
922 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
923 strftime (char *, size_t, const char *, const struct tm *);
924 #endif
925
926 #ifndef HAVE_STRPTIME
927 #define strptime rk_strptime
928 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
929 strptime (const char *, const char *, struct tm *);
930 #endif
931
932 #ifndef HAVE_GETTIMEOFDAY
933 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
934 gettimeofday (struct timeval *, void *);
935 #endif
936
937 #ifndef HAVE_EMALLOC
938 #define emalloc rk_emalloc
939 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
940 #endif
941 #ifndef HAVE_ECALLOC
942 #define ecalloc rk_ecalloc
943 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
944 #endif
945 #ifndef HAVE_EREALLOC
946 #define erealloc rk_erealloc
947 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
948 #endif
949 #ifndef HAVE_ESTRDUP
950 #define estrdup rk_estrdup
951 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
952 #endif
953
954 /*
955  * kludges and such
956  */
957
958 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
959 roken_gethostby_setup(const char*, const char*);
960 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
961 roken_gethostbyname(const char*);
962 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
963 roken_gethostbyaddr(const void*, size_t, int);
964
965 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
966 #define roken_getservbyname(x,y) getservbyname(x,y)
967 #else
968 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
969 #endif
970
971 #ifdef OPENLOG_PROTO_COMPATIBLE
972 #define roken_openlog(a,b,c) openlog(a,b,c)
973 #else
974 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
975 #endif
976
977 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
978 #define roken_getsockname(a,b,c) getsockname(a,b,c)
979 #else
980 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
981 #endif
982
983 #ifndef HAVE_SETPROGNAME
984 #define setprogname rk_setprogname
985 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
986 #endif
987
988 #ifndef HAVE_GETPROGNAME
989 #define getprogname rk_getprogname
990 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
991 #endif
992
993 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
994 extern const char *__progname;
995 #endif
996
997 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
998 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
999
1000 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1001 mini_inetd (int, rk_socket_t *);
1002
1003 #ifndef HAVE_LOCALTIME_R
1004 #define localtime_r rk_localtime_r
1005 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1006 localtime_r(const time_t *, struct tm *);
1007 #endif
1008
1009 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1010 #ifndef HAVE_STRSVIS
1011 #define strsvis rk_strsvis
1012 #endif
1013 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1014 strsvis(char *, const char *, int, const char *);
1015 #endif
1016
1017 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1018 #ifndef HAVE_STRSVISX
1019 #define strsvisx rk_strsvisx
1020 #endif
1021 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1022 strsvisx(char *, const char *, size_t, int, const char *);
1023 #endif
1024
1025 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1026 #ifndef HAVE_STRUNVIS
1027 #define strunvis rk_strunvis
1028 #endif
1029 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1030 strunvis(char *, const char *);
1031 #endif
1032
1033 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1034 #ifndef HAVE_STRVIS
1035 #define strvis rk_strvis
1036 #endif
1037 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1038 strvis(char *, const char *, int);
1039 #endif
1040
1041 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1042 #ifndef HAVE_STRVISX
1043 #define strvisx rk_strvisx
1044 #endif
1045 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1046 strvisx(char *, const char *, size_t, int);
1047 #endif
1048
1049 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1050 #ifndef HAVE_SVIS
1051 #define svis rk_svis
1052 #endif
1053 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1054 svis(char *, int, int, int, const char *);
1055 #endif
1056
1057 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1058 #ifndef HAVE_UNVIS
1059 #define unvis rk_unvis
1060 #endif
1061 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1062 unvis(char *, int, int *, int);
1063 #endif
1064
1065 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1066 #ifndef HAVE_VIS
1067 #define vis rk_vis
1068 #endif
1069 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1070 vis(char *, int, int, int);
1071 #endif
1072
1073 #if !defined(HAVE_CLOSEFROM)
1074 #define closefrom rk_closefrom
1075 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1076 closefrom(int);
1077 #endif
1078
1079 #if !defined(HAVE_TIMEGM)
1080 #define timegm rk_timegm
1081 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1082 rk_timegm(struct tm *tm);
1083 #endif
1084
1085 #ifdef NEED_QSORT
1086 #define qsort rk_qsort
1087 void
1088 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1089 #endif
1090
1091 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1092 #undef socket
1093 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1094 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1095 #endif
1096
1097 #ifdef SOCKET_WRAPPER_REPLACE
1098 #include <socket_wrapper.h>
1099 #endif
1100
1101 ROKEN_CPP_END