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 const char * ROKEN_LIB_FUNCTION hstrerror(int);
548 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
549 #endif
550 #endif
551
552 #if !HAVE_DECL_H_ERRNO
553 extern int h_errno;
554 #endif
555
556 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
557 #ifndef HAVE_INET_ATON
558 #define inet_aton rk_inet_aton
559 #endif
560 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
561 #endif
562
563 #ifndef HAVE_INET_NTOP
564 #define inet_ntop rk_inet_ntop
565 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
566 inet_ntop(int af, const void *src, char *dst, size_t size);
567 #endif
568
569 #ifndef HAVE_INET_PTON
570 #define inet_pton rk_inet_pton
571 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
572 inet_pton(int, const char *, void *);
573 #endif
574
575 #ifndef HAVE_GETCWD
576 #define getcwd rk_getcwd
577 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
578 #endif
579
580 #ifdef HAVE_PWD_H
581 #include <pwd.h>
582 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
583 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
584 #endif
585
586 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
587
588 #ifndef HAVE_SETEUID
589 #define seteuid rk_seteuid
590 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
591 #endif
592
593 #ifndef HAVE_SETEGID
594 #define setegid rk_setegid
595 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
596 #endif
597
598 #ifndef HAVE_LSTAT
599 #define lstat rk_lstat
600 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
601 #endif
602
603 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
604 #ifndef HAVE_MKSTEMP
605 #define mkstemp rk_mkstemp
606 #endif
607 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
608 #endif
609
610 #ifndef HAVE_CGETENT
611 #define cgetent rk_cgetent
612 #define cgetstr rk_cgetstr
613 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
614 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
615 #endif
616
617 #ifndef HAVE_INITGROUPS
618 #define initgroups rk_initgroups
619 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
620 #endif
621
622 #ifndef HAVE_FCHOWN
623 #define fchown rk_fchown
624 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
625 #endif
626
627 #ifdef RENAME_DOES_NOT_UNLINK
628 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
629 #else
630 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
631 #endif
632
633 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
634 #ifndef HAVE_DAEMON
635 #define daemon rk_daemon
636 #endif
637 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
638 #endif
639
640 #ifndef HAVE_CHOWN
641 #define chown rk_chown
642 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
643 #endif
644
645 #ifndef HAVE_RCMD
646 #define rcmd rk_rcmd
647 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
648     rcmd(char **, unsigned short, const char *,
649          const char *, const char *, int *);
650 #endif
651
652 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
653 #ifndef HAVE_INNETGR
654 #define innetgr rk_innetgr
655 #endif
656 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
657     const char*, const char*);
658 #endif
659
660 #ifndef HAVE_IRUSEROK
661 #define iruserok rk_iruserok
662 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
663     const char *, const char *);
664 #endif
665
666 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
667 #ifndef HAVE_GETHOSTNAME
668 #define gethostname rk_gethostname
669 #endif
670 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
671 #endif
672
673 #ifndef HAVE_WRITEV
674 #define writev rk_writev
675 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
676 writev(int, const struct iovec *, int);
677 #endif
678
679 #ifndef HAVE_READV
680 #define readv rk_readv
681 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
682 readv(int, const struct iovec *, int);
683 #endif
684
685 #ifndef HAVE_PIDFILE
686 #ifdef NO_PIDFILES
687 #define pidfile(x) ((void) 0)
688 #else
689 #define pidfile rk_pidfile
690 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
691 #endif
692 #endif
693
694 #ifndef HAVE_BSWAP32
695 #define bswap32 rk_bswap32
696 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
697 #endif
698
699 #ifndef HAVE_BSWAP16
700 #define bswap16 rk_bswap16
701 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
702 #endif
703
704 #ifndef HAVE_FLOCK
705 #ifndef LOCK_SH
706 #define LOCK_SH   1             /* Shared lock */
707 #endif
708 #ifndef LOCK_EX
709 #define LOCK_EX   2             /* Exclusive lock */
710 #endif
711 #ifndef LOCK_NB
712 #define LOCK_NB   4             /* Don't block when locking */
713 #endif
714 #ifndef LOCK_UN
715 #define LOCK_UN   8             /* Unlock */
716 #endif
717
718 #define flock(_x,_y) rk_flock(_x,_y)
719 int rk_flock(int fd, int operation);
720 #endif /* HAVE_FLOCK */
721
722 #ifndef HAVE_DIRFD
723 #ifdef HAVE_DIR_DD_FD
724 #define dirfd(x) ((x)->dd_fd)
725 #else
726 #ifndef _WIN32 /* Windows code never calls dirfd */
727 #error Missing dirfd() and ->dd_fd
728 #endif
729 #endif
730 #endif
731
732 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
733
734 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
735
736 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
737
738 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
739
740 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
741
742 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
743     roken_vmconcat (char **, size_t, va_list);
744
745 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
746     net_write (rk_socket_t, const void *, size_t);
747
748 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
749     net_read (rk_socket_t, void *, size_t);
750
751 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
752     issuid(void);
753
754 #ifndef HAVE_STRUCT_WINSIZE
755 struct winsize {
756         unsigned short ws_row, ws_col;
757         unsigned short ws_xpixel, ws_ypixel;
758 };
759 #endif
760
761 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
762
763 #ifndef HAVE_VSYSLOG
764 #define vsyslog rk_vsyslog
765 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
766 #endif
767
768 #if !HAVE_DECL_OPTARG
769 ROKEN_LIB_VARIABLE extern char *optarg;
770 #endif
771 #if !HAVE_DECL_OPTIND
772 ROKEN_LIB_VARIABLE extern int optind;
773 #endif
774 #if !HAVE_DECL_OPTERR
775 ROKEN_LIB_VARIABLE extern int opterr;
776 #endif
777
778 #ifndef HAVE_GETIPNODEBYNAME
779 #define getipnodebyname rk_getipnodebyname
780 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
781 getipnodebyname (const char *, int, int, int *);
782 #endif
783
784 #ifndef HAVE_GETIPNODEBYADDR
785 #define getipnodebyaddr rk_getipnodebyaddr
786 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
787 getipnodebyaddr (const void *, size_t, int, int *);
788 #endif
789
790 #ifndef HAVE_FREEHOSTENT
791 #define freehostent rk_freehostent
792 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
793 freehostent (struct hostent *);
794 #endif
795
796 #ifndef HAVE_COPYHOSTENT
797 #define copyhostent rk_copyhostent
798 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
799 copyhostent (const struct hostent *);
800 #endif
801
802 #ifndef HAVE_SOCKLEN_T
803 typedef int socklen_t;
804 #endif
805
806 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
807
808 #ifndef HAVE_SA_FAMILY_T
809 typedef unsigned short sa_family_t;
810 #endif
811
812 #ifdef HAVE_IPV6
813 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
814 #else
815 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
816 #endif
817
818 #define _SS_ALIGNSIZE   sizeof(unsigned long)
819
820 #if HAVE_STRUCT_SOCKADDR_SA_LEN
821
822 typedef unsigned char roken_sa_family_t;
823
824 #define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
825 #define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
826
827 struct sockaddr_storage {
828     unsigned char       ss_len;
829     roken_sa_family_t   ss_family;
830     char                __ss_pad1[_SS_PAD1SIZE];
831     unsigned long       __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
832 };
833
834 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
835
836 typedef unsigned short roken_sa_family_t;
837
838 #define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
839 #define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
840
841 struct sockaddr_storage {
842     roken_sa_family_t   ss_family;
843     char                __ss_pad1[_SS_PAD1SIZE];
844     unsigned long       __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
845 };
846
847 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
848
849 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
850
851 #ifndef HAVE_STRUCT_ADDRINFO
852 struct addrinfo {
853     int    ai_flags;
854     int    ai_family;
855     int    ai_socktype;
856     int    ai_protocol;
857     size_t ai_addrlen;
858     char  *ai_canonname;
859     struct sockaddr *ai_addr;
860     struct addrinfo *ai_next;
861 };
862 #endif
863
864 #ifndef HAVE_GETADDRINFO
865 #define getaddrinfo rk_getaddrinfo
866 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
867 getaddrinfo(const char *,
868             const char *,
869             const struct addrinfo *,
870             struct addrinfo **);
871 #endif
872
873 #ifndef HAVE_GETNAMEINFO
874 #define getnameinfo rk_getnameinfo
875 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
876 getnameinfo(const struct sockaddr *, socklen_t,
877                 char *, size_t,
878                 char *, size_t,
879                 int);
880 #endif
881
882 #ifndef HAVE_FREEADDRINFO
883 #define freeaddrinfo rk_freeaddrinfo
884 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
885 freeaddrinfo(struct addrinfo *);
886 #endif
887
888 #ifndef HAVE_GAI_STRERROR
889 #define gai_strerror rk_gai_strerror
890 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
891 gai_strerror(int);
892 #endif
893
894 #ifdef NO_SLEEP
895
896 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
897 sleep(unsigned int seconds);
898
899 #endif
900
901 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
902 getnameinfo_verified(const struct sockaddr *, socklen_t,
903                      char *, size_t,
904                      char *, size_t,
905                      int);
906
907 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
908 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
909 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
910 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
911
912 #ifndef HAVE_STRFTIME
913 #define strftime rk_strftime
914 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
915 strftime (char *, size_t, const char *, const struct tm *);
916 #endif
917
918 #ifndef HAVE_STRPTIME
919 #define strptime rk_strptime
920 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
921 strptime (const char *, const char *, struct tm *);
922 #endif
923
924 #ifndef HAVE_GETTIMEOFDAY
925 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
926 gettimeofday (struct timeval *, void *);
927 #endif
928
929 #ifndef HAVE_EMALLOC
930 #define emalloc rk_emalloc
931 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
932 #endif
933 #ifndef HAVE_ECALLOC
934 #define ecalloc rk_ecalloc
935 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
936 #endif
937 #ifndef HAVE_EREALLOC
938 #define erealloc rk_erealloc
939 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
940 #endif
941 #ifndef HAVE_ESTRDUP
942 #define estrdup rk_estrdup
943 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
944 #endif
945
946 /*
947  * kludges and such
948  */
949
950 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
951 roken_gethostby_setup(const char*, const char*);
952 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
953 roken_gethostbyname(const char*);
954 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
955 roken_gethostbyaddr(const void*, size_t, int);
956
957 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
958 #define roken_getservbyname(x,y) getservbyname(x,y)
959 #else
960 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
961 #endif
962
963 #ifdef OPENLOG_PROTO_COMPATIBLE
964 #define roken_openlog(a,b,c) openlog(a,b,c)
965 #else
966 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
967 #endif
968
969 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
970 #define roken_getsockname(a,b,c) getsockname(a,b,c)
971 #else
972 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
973 #endif
974
975 #ifndef HAVE_SETPROGNAME
976 #define setprogname rk_setprogname
977 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
978 #endif
979
980 #ifndef HAVE_GETPROGNAME
981 #define getprogname rk_getprogname
982 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
983 #endif
984
985 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
986 extern const char *__progname;
987 #endif
988
989 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
990 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
991
992 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
993 mini_inetd (int, rk_socket_t *);
994
995 #ifndef HAVE_LOCALTIME_R
996 #define localtime_r rk_localtime_r
997 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
998 localtime_r(const time_t *, struct tm *);
999 #endif
1000
1001 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1002 #ifndef HAVE_STRSVIS
1003 #define strsvis rk_strsvis
1004 #endif
1005 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1006 strsvis(char *, const char *, int, const char *);
1007 #endif
1008
1009 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1010 #ifndef HAVE_STRSVISX
1011 #define strsvisx rk_strsvisx
1012 #endif
1013 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1014 strsvisx(char *, const char *, size_t, int, const char *);
1015 #endif
1016
1017 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1018 #ifndef HAVE_STRUNVIS
1019 #define strunvis rk_strunvis
1020 #endif
1021 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1022 strunvis(char *, const char *);
1023 #endif
1024
1025 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1026 #ifndef HAVE_STRVIS
1027 #define strvis rk_strvis
1028 #endif
1029 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1030 strvis(char *, const char *, int);
1031 #endif
1032
1033 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1034 #ifndef HAVE_STRVISX
1035 #define strvisx rk_strvisx
1036 #endif
1037 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1038 strvisx(char *, const char *, size_t, int);
1039 #endif
1040
1041 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1042 #ifndef HAVE_SVIS
1043 #define svis rk_svis
1044 #endif
1045 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1046 svis(char *, int, int, int, const char *);
1047 #endif
1048
1049 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1050 #ifndef HAVE_UNVIS
1051 #define unvis rk_unvis
1052 #endif
1053 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1054 unvis(char *, int, int *, int);
1055 #endif
1056
1057 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1058 #ifndef HAVE_VIS
1059 #define vis rk_vis
1060 #endif
1061 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1062 vis(char *, int, int, int);
1063 #endif
1064
1065 #if !defined(HAVE_CLOSEFROM)
1066 #define closefrom rk_closefrom
1067 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1068 closefrom(int);
1069 #endif
1070
1071 #if !defined(HAVE_TIMEGM)
1072 #define timegm rk_timegm
1073 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1074 rk_timegm(struct tm *tm);
1075 #endif
1076
1077 #ifdef NEED_QSORT
1078 #define qsort rk_qsort
1079 void
1080 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1081 #endif
1082
1083 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1084 #undef socket
1085 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1086 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1087 #endif
1088
1089 #ifdef SOCKET_WRAPPER_REPLACE
1090 #include <socket_wrapper.h>
1091 #endif
1092
1093 ROKEN_CPP_END