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