s4:heimdal: import lorikeet-heimdal-201003262338 (commit f4e0dc17709829235f057e0e100d...
[Samba/gebeck_regimport.git] / source4 / heimdal / lib / roken / roken.h.in
blob76b083c7973fcf98d9289e6d7863c517e7c09a0d
1 /* -*- C -*- */
2 /*
3 * Copyright (c) 1995-2005 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdarg.h>
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
41 #include <string.h>
42 #include <signal.h>
44 #ifndef ROKEN_LIB_FUNCTION
45 #ifdef _WIN32
46 #define ROKEN_LIB_FUNCTION
47 #define ROKEN_LIB_CALL __cdecl
48 #else
49 #define ROKEN_LIB_FUNCTION
50 #define ROKEN_LIB_CALL
51 #endif
52 #endif
54 #ifdef HAVE_WINSOCK
55 /* Declarations for Microsoft Windows */
57 #include<ws2tcpip.h>
60 * error codes for inet_ntop/inet_pton
62 #define EAFNOSUPPORT WSAEAFNOSUPPORT
64 typedef SOCKET rk_socket_t;
66 #define rk_closesocket(x) closesocket(x)
67 #define rk_INVALID_SOCKET INVALID_SOCKET
68 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
69 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
70 #define rk_SOCK_ERRNO WSAGetLastError()
71 #define rk_SOCK_IOCTL(s,c,a) ioctlsocket((s),(c),(a))
73 #define ETIMEDOUT WSAETIMEDOUT
74 #define EWOULDBLOCK WSAEWOULDBLOCK
75 #define ENOTSOCK WSAENOTSOCK
77 #define rk_SOCK_INIT() rk_WSAStartup()
78 #define rk_SOCK_EXIT() rk_WSACleanup()
80 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
81 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
83 #else /* not WinSock */
85 typedef int rk_socket_t;
87 #define rk_closesocket(x) close(x)
88 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
89 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
90 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
91 #define rk_SOCK_ERRNO errno
92 #define rk_INVALID_SOCKET (-1)
94 #define rk_SOCK_INIT() 0
95 #define rk_SOCK_EXIT() do { } while(0)
97 #endif
99 #ifdef _MSC_VER
100 /* Declarations for Microsoft Visual C runtime on Windows */
102 #include<process.h>
104 #include<io.h>
106 #ifndef __BIT_TYPES_DEFINED__
107 #define __BIT_TYPES_DEFINED__
109 typedef __int8 int8_t;
110 typedef __int16 int16_t;
111 typedef __int32 int32_t;
112 typedef __int64 int64_t;
113 typedef unsigned __int8 uint8_t;
114 typedef unsigned __int16 uint16_t;
115 typedef unsigned __int32 uint32_t;
116 typedef unsigned __int64 uint64_t;
117 typedef uint8_t u_int8_t;
118 typedef uint16_t u_int16_t;
119 typedef uint32_t u_int32_t;
120 typedef uint64_t u_int64_t;
122 #endif /* __BIT_TYPES_DEFINED__ */
124 #define UNREACHABLE(x) x
125 #define UNUSED_ARGUMENT(x) ((void) x)
127 #else
129 #define UNREACHABLE(x)
130 #define UNUSED_ARGUMENT(x)
132 #endif
134 #ifdef _AIX
135 struct ether_addr;
136 struct sockaddr_dl;
137 #endif
138 #ifdef HAVE_SYS_PARAM_H
139 #include <sys/param.h>
140 #endif
141 #ifdef HAVE_INTTYPES_H
142 #include <inttypes.h>
143 #endif
144 #ifdef HAVE_SYS_TYPES_H
145 #include <sys/types.h>
146 #endif
147 #ifdef HAVE_SYS_BITYPES_H
148 #include <sys/bitypes.h>
149 #endif
150 #ifdef HAVE_BIND_BITYPES_H
151 #include <bind/bitypes.h>
152 #endif
153 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
154 #include <netinet/in6_machtypes.h>
155 #endif
156 #ifdef HAVE_UNISTD_H
157 #include <unistd.h>
158 #endif
159 #ifdef HAVE_SYS_SOCKET_H
160 #include <sys/socket.h>
161 #endif
162 #ifdef HAVE_SYS_UIO_H
163 #include <sys/uio.h>
164 #endif
165 #ifdef HAVE_GRP_H
166 #include <grp.h>
167 #endif
168 #ifdef HAVE_SYS_STAT_H
169 #include <sys/stat.h>
170 #endif
171 #ifdef HAVE_NETINET_IN_H
172 #include <netinet/in.h>
173 #endif
174 #ifdef HAVE_NETINET_IN6_H
175 #include <netinet/in6.h>
176 #endif
177 #ifdef HAVE_NETINET6_IN6_H
178 #include <netinet6/in6.h>
179 #endif
180 #ifdef HAVE_ARPA_INET_H
181 #include <arpa/inet.h>
182 #endif
183 #ifdef HAVE_NETDB_H
184 #include <netdb.h>
185 #endif
186 #ifdef HAVE_ARPA_NAMESER_H
187 #include <arpa/nameser.h>
188 #endif
189 #ifdef HAVE_RESOLV_H
190 #include <resolv.h>
191 #endif
192 #ifdef HAVE_SYSLOG_H
193 #include <syslog.h>
194 #endif
195 #ifdef HAVE_FCNTL_H
196 #include <fcntl.h>
197 #endif
198 #ifdef HAVE_ERRNO_H
199 #include <errno.h>
200 #endif
201 #include <err.h>
202 #ifdef HAVE_TERMIOS_H
203 #include <termios.h>
204 #endif
205 #ifdef HAVE_SYS_IOCTL_H
206 #include <sys/ioctl.h>
207 #endif
208 #ifdef TIME_WITH_SYS_TIME
209 #include <sys/time.h>
210 #include <time.h>
211 #elif defined(HAVE_SYS_TIME_H)
212 #include <sys/time.h>
213 #else
214 #include <time.h>
215 #endif
217 #ifdef HAVE_WS2TCPIP_H
218 #include <ws2tcpip.h>
219 #endif
221 #ifdef HAVE_PATHS_H
222 #include <paths.h>
223 #endif
225 #ifdef HAVE_DIRENT_H
226 #include <dirent.h>
227 #endif
229 #ifdef BACKSLASH_PATH_DELIM
230 #define rk_PATH_DELIM '\\'
231 #endif
233 #ifndef HAVE_SSIZE_T
234 #ifdef _WIN64
235 typedef __int64 ssize_t;
236 #else
237 typedef int ssize_t;
238 #endif
239 #endif
241 #include <roken-common.h>
243 ROKEN_CPP_START
245 #ifdef HAVE_UINTPTR_T
246 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
247 #else
248 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
249 #endif
251 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
252 #define setsid _setsid
253 #endif
255 #ifdef _MSC_VER
256 /* Additional macros for Visual C/C++ runtime */
258 #define close _close
260 #define getpid _getpid
262 #define open _open
264 #define chdir _chdir
266 #define fsync _commit
268 /* The MSVC implementation of snprintf is not C99 compliant. */
269 #define snprintf rk_snprintf
270 #define vsnprintf rk_vsnprintf
271 #define vasnprintf rk_vasnprintf
272 #define vasprintf rk_vasprintf
273 #define asnprintf rk_asnprintf
274 #define asprintf rk_asprintf
276 #define _PIPE_BUFFER_SZ 8192
277 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
279 #define ftruncate(fd, sz) _chsize((fd), (sz))
281 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
282 rk_snprintf (char *str, size_t sz, const char *format, ...);
284 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
285 rk_asprintf (char **ret, const char *format, ...);
287 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
288 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
290 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
291 rk_vasprintf (char **ret, const char *format, va_list args);
293 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
294 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
296 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
297 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
299 /* missing stat.h predicates */
301 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
303 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
305 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
307 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
309 /* The following are not implemented:
311 S_ISLNK(m)
312 S_ISSOCK(m)
313 S_ISBLK(m)
316 #endif /* _MSC_VER */
318 #ifndef HAVE_PUTENV
319 #define putenv rk_putenv
320 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
321 #endif
323 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
324 #ifndef HAVE_SETENV
325 #define setenv rk_setenv
326 #endif
327 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
328 #endif
330 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
331 #ifndef HAVE_UNSETENV
332 #define unsetenv rk_unsetenv
333 #endif
334 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
335 #endif
337 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
338 #ifndef HAVE_GETUSERSHELL
339 #define getusershell rk_getusershell
340 #define endusershell rk_endusershell
341 #endif
342 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
343 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
344 #endif
346 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
347 #ifndef HAVE_SNPRINTF
348 #define snprintf rk_snprintf
349 #endif
350 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
351 rk_snprintf (char *, size_t, const char *, ...)
352 __attribute__ ((format (printf, 3, 4)));
353 #endif
355 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
356 #ifndef HAVE_VSNPRINTF
357 #define vsnprintf rk_vsnprintf
358 #endif
359 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
360 rk_vsnprintf (char *, size_t, const char *, va_list)
361 __attribute__((format (printf, 3, 0)));
362 #endif
364 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
365 #ifndef HAVE_ASPRINTF
366 #define asprintf rk_asprintf
367 #endif
368 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
369 rk_asprintf (char **, const char *, ...)
370 __attribute__ ((format (printf, 2, 3)));
371 #endif
373 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
374 #ifndef HAVE_VASPRINTF
375 #define vasprintf rk_vasprintf
376 #endif
377 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
378 rk_vasprintf (char **, const char *, va_list)
379 __attribute__((format (printf, 2, 0)));
380 #endif
382 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
383 #ifndef HAVE_ASNPRINTF
384 #define asnprintf rk_asnprintf
385 #endif
386 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
387 rk_asnprintf (char **, size_t, const char *, ...)
388 __attribute__ ((format (printf, 3, 4)));
389 #endif
391 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
392 #ifndef HAVE_VASNPRINTF
393 #define vasnprintf rk_vasnprintf
394 #endif
395 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
396 vasnprintf (char **, size_t, const char *, va_list)
397 __attribute__((format (printf, 3, 0)));
398 #endif
400 #ifndef HAVE_STRDUP
401 #define strdup rk_strdup
402 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
403 #endif
405 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
406 #ifndef HAVE_STRNDUP
407 #define strndup rk_strndup
408 #endif
409 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
410 #endif
412 #ifndef HAVE_STRLWR
413 #define strlwr rk_strlwr
414 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
415 #endif
417 #ifndef HAVE_STRNLEN
418 #define strnlen rk_strnlen
419 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
420 #endif
422 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
423 #ifndef HAVE_STRSEP
424 #define strsep rk_strsep
425 #endif
426 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
427 #endif
429 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
430 #ifndef HAVE_STRSEP_COPY
431 #define strsep_copy rk_strsep_copy
432 #endif
433 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
434 #endif
436 #ifndef HAVE_STRCASECMP
437 #define strcasecmp rk_strcasecmp
438 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
439 #endif
441 #ifdef NEED_FCLOSE_PROTO
442 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
443 #endif
445 #ifdef NEED_STRTOK_R_PROTO
446 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
447 #endif
449 #ifndef HAVE_STRUPR
450 #define strupr rk_strupr
451 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
452 #endif
454 #ifndef HAVE_STRLCPY
455 #define strlcpy rk_strlcpy
456 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
457 #endif
459 #ifndef HAVE_STRLCAT
460 #define strlcat rk_strlcat
461 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
462 #endif
464 #ifndef HAVE_GETDTABLESIZE
465 #define getdtablesize rk_getdtablesize
466 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
467 #endif
469 #if !defined(HAVE_STRERROR) && !defined(strerror)
470 #define strerror rk_strerror
471 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
472 #endif
474 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
475 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
476 #else
477 #define rk_strerror_r strerror_r
478 #endif
480 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
481 #ifndef HAVE_HSTRERROR
482 #define hstrerror rk_hstrerror
483 #endif
484 /* This causes a fatal error under Psoriasis */
485 #ifndef SunOS
486 const char * ROKEN_LIB_FUNCTION hstrerror(int);
487 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
488 #endif
489 #endif
491 #if !HAVE_DECL_H_ERRNO
492 extern int h_errno;
493 #endif
495 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
496 #ifndef HAVE_INET_ATON
497 #define inet_aton rk_inet_aton
498 #endif
499 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
500 #endif
502 #ifndef HAVE_INET_NTOP
503 #define inet_ntop rk_inet_ntop
504 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
505 inet_ntop(int af, const void *src, char *dst, size_t size);
506 #endif
508 #ifndef HAVE_INET_PTON
509 #define inet_pton rk_inet_pton
510 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
511 inet_pton(int, const char *, void *);
512 #endif
514 #ifndef HAVE_GETCWD
515 #define getcwd rk_getcwd
516 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
517 #endif
519 #ifdef HAVE_PWD_H
520 #include <pwd.h>
521 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
522 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
523 #endif
525 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
527 #ifndef HAVE_SETEUID
528 #define seteuid rk_seteuid
529 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
530 #endif
532 #ifndef HAVE_SETEGID
533 #define setegid rk_setegid
534 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
535 #endif
537 #ifndef HAVE_LSTAT
538 #define lstat rk_lstat
539 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
540 #endif
542 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
543 #ifndef HAVE_MKSTEMP
544 #define mkstemp rk_mkstemp
545 #endif
546 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
547 #endif
549 #ifndef HAVE_CGETENT
550 #define cgetent rk_cgetent
551 #define cgetstr rk_cgetstr
552 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
553 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
554 #endif
556 #ifndef HAVE_INITGROUPS
557 #define initgroups rk_initgroups
558 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
559 #endif
561 #ifndef HAVE_FCHOWN
562 #define fchown rk_fchown
563 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
564 #endif
566 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
567 #ifndef HAVE_DAEMON
568 #define daemon rk_daemon
569 #endif
570 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
571 #endif
573 #ifndef HAVE_CHOWN
574 #define chown rk_chown
575 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
576 #endif
578 #ifndef HAVE_RCMD
579 #define rcmd rk_rcmd
580 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
581 rcmd(char **, unsigned short, const char *,
582 const char *, const char *, int *);
583 #endif
585 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
586 #ifndef HAVE_INNETGR
587 #define innetgr rk_innetgr
588 #endif
589 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
590 const char*, const char*);
591 #endif
593 #ifndef HAVE_IRUSEROK
594 #define iruserok rk_iruserok
595 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
596 const char *, const char *);
597 #endif
599 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
600 #ifndef HAVE_GETHOSTNAME
601 #define gethostname rk_gethostname
602 #endif
603 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
604 #endif
606 #ifndef HAVE_WRITEV
607 #define writev rk_writev
608 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
609 writev(int, const struct iovec *, int);
610 #endif
612 #ifndef HAVE_READV
613 #define readv rk_readv
614 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
615 readv(int, const struct iovec *, int);
616 #endif
618 #ifndef HAVE_PIDFILE
619 #ifdef NO_PIDFILES
620 #define pidfile(x) ((void) 0)
621 #else
622 #define pidfile rk_pidfile
623 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
624 #endif
625 #endif
627 #ifndef HAVE_BSWAP32
628 #define bswap32 rk_bswap32
629 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
630 #endif
632 #ifndef HAVE_BSWAP16
633 #define bswap16 rk_bswap16
634 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
635 #endif
637 #ifndef HAVE_FLOCK
638 #ifndef LOCK_SH
639 #define LOCK_SH 1 /* Shared lock */
640 #endif
641 #ifndef LOCK_EX
642 #define LOCK_EX 2 /* Exclusive lock */
643 #endif
644 #ifndef LOCK_NB
645 #define LOCK_NB 4 /* Don't block when locking */
646 #endif
647 #ifndef LOCK_UN
648 #define LOCK_UN 8 /* Unlock */
649 #endif
651 #define flock(_x,_y) rk_flock(_x,_y)
652 int rk_flock(int fd, int operation);
653 #endif /* HAVE_FLOCK */
655 #ifndef HAVE_DIRFD
656 #ifdef HAVE_DIR_DD_FD
657 #define dirfd(x) ((x)->dd_fd)
658 #else
659 #ifndef _WIN32 /* Windows code never calls dirfd */
660 #error Missing dirfd() and ->dd_fd
661 #endif
662 #endif
663 #endif
665 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
667 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
669 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
671 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
673 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
675 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
676 roken_vmconcat (char **, size_t, va_list);
678 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
679 net_write (rk_socket_t, const void *, size_t);
681 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
682 net_read (rk_socket_t, void *, size_t);
684 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
685 issuid(void);
687 #ifndef HAVE_STRUCT_WINSIZE
688 struct winsize {
689 unsigned short ws_row, ws_col;
690 unsigned short ws_xpixel, ws_ypixel;
692 #endif
694 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
696 #ifndef HAVE_VSYSLOG
697 #define vsyslog rk_vsyslog
698 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
699 #endif
701 #if !HAVE_DECL_OPTARG
702 extern char *optarg;
703 #endif
704 #if !HAVE_DECL_OPTIND
705 extern int optind;
706 #endif
707 #if !HAVE_DECL_OPTERR
708 extern int opterr;
709 #endif
711 #ifndef HAVE_GETIPNODEBYNAME
712 #define getipnodebyname rk_getipnodebyname
713 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
714 getipnodebyname (const char *, int, int, int *);
715 #endif
717 #ifndef HAVE_GETIPNODEBYADDR
718 #define getipnodebyaddr rk_getipnodebyaddr
719 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
720 getipnodebyaddr (const void *, size_t, int, int *);
721 #endif
723 #ifndef HAVE_FREEHOSTENT
724 #define freehostent rk_freehostent
725 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
726 freehostent (struct hostent *);
727 #endif
729 #ifndef HAVE_COPYHOSTENT
730 #define copyhostent rk_copyhostent
731 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
732 copyhostent (const struct hostent *);
733 #endif
735 #ifndef HAVE_SOCKLEN_T
736 typedef int socklen_t;
737 #endif
739 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
741 #ifndef HAVE_SA_FAMILY_T
742 typedef unsigned short sa_family_t;
743 #endif
745 #ifdef HAVE_IPV6
746 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
747 #else
748 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
749 #endif
751 #define _SS_ALIGNSIZE sizeof(unsigned long)
753 #if HAVE_STRUCT_SOCKADDR_SA_LEN
755 typedef unsigned char roken_sa_family_t;
757 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
758 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
760 struct sockaddr_storage {
761 unsigned char ss_len;
762 roken_sa_family_t ss_family;
763 char __ss_pad1[_SS_PAD1SIZE];
764 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
767 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
769 typedef unsigned short roken_sa_family_t;
771 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
772 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
774 struct sockaddr_storage {
775 roken_sa_family_t ss_family;
776 char __ss_pad1[_SS_PAD1SIZE];
777 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
780 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
782 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
784 #ifndef HAVE_STRUCT_ADDRINFO
785 struct addrinfo {
786 int ai_flags;
787 int ai_family;
788 int ai_socktype;
789 int ai_protocol;
790 size_t ai_addrlen;
791 char *ai_canonname;
792 struct sockaddr *ai_addr;
793 struct addrinfo *ai_next;
795 #endif
797 #ifndef HAVE_GETADDRINFO
798 #define getaddrinfo rk_getaddrinfo
799 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
800 getaddrinfo(const char *,
801 const char *,
802 const struct addrinfo *,
803 struct addrinfo **);
804 #endif
806 #ifndef HAVE_GETNAMEINFO
807 #define getnameinfo rk_getnameinfo
808 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
809 getnameinfo(const struct sockaddr *, socklen_t,
810 char *, size_t,
811 char *, size_t,
812 int);
813 #endif
815 #ifndef HAVE_FREEADDRINFO
816 #define freeaddrinfo rk_freeaddrinfo
817 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
818 freeaddrinfo(struct addrinfo *);
819 #endif
821 #ifndef HAVE_GAI_STRERROR
822 #define gai_strerror rk_gai_strerror
823 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
824 gai_strerror(int);
825 #endif
827 #ifdef HAVE_WINSOCK
829 /* While we are at it, define WinSock specific scatter gather socket
830 I/O. */
832 #define iovec _WSABUF
833 #define iov_base buf
834 #define iov_len len
836 struct msghdr {
837 void *msg_name;
838 socklen_t msg_namelen;
839 struct iovec *msg_iov;
840 size_t msg_iovlen;
841 void *msg_control;
842 socklen_t msg_controllen;
843 int msg_flags;
846 #define sendmsg sendmsg_w32
848 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
849 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
851 #endif
853 #ifdef NO_SLEEP
855 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
856 sleep(unsigned int seconds);
858 #endif
860 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
861 getnameinfo_verified(const struct sockaddr *, socklen_t,
862 char *, size_t,
863 char *, size_t,
864 int);
866 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
867 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
868 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
869 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
871 #ifndef HAVE_STRFTIME
872 #define strftime rk_strftime
873 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
874 strftime (char *, size_t, const char *, const struct tm *);
875 #endif
877 #ifndef HAVE_STRPTIME
878 #define strptime rk_strptime
879 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
880 strptime (const char *, const char *, struct tm *);
881 #endif
883 #ifndef HAVE_GETTIMEOFDAY
884 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
885 gettimeofday (struct timeval *, void *);
886 #endif
888 #ifndef HAVE_EMALLOC
889 #define emalloc rk_emalloc
890 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
891 #endif
892 #ifndef HAVE_ECALLOC
893 #define ecalloc rk_ecalloc
894 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
895 #endif
896 #ifndef HAVE_EREALLOC
897 #define erealloc rk_erealloc
898 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
899 #endif
900 #ifndef HAVE_ESTRDUP
901 #define estrdup rk_estrdup
902 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
903 #endif
906 * kludges and such
909 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
910 roken_gethostby_setup(const char*, const char*);
911 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
912 roken_gethostbyname(const char*);
913 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
914 roken_gethostbyaddr(const void*, size_t, int);
916 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
917 #define roken_getservbyname(x,y) getservbyname(x,y)
918 #else
919 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
920 #endif
922 #ifdef OPENLOG_PROTO_COMPATIBLE
923 #define roken_openlog(a,b,c) openlog(a,b,c)
924 #else
925 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
926 #endif
928 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
929 #define roken_getsockname(a,b,c) getsockname(a,b,c)
930 #else
931 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
932 #endif
934 #ifndef HAVE_SETPROGNAME
935 #define setprogname rk_setprogname
936 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
937 #endif
939 #ifndef HAVE_GETPROGNAME
940 #define getprogname rk_getprogname
941 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
942 #endif
944 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
945 extern const char *__progname;
946 #endif
948 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
949 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
951 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
952 mini_inetd (int, rk_socket_t *);
954 #ifndef HAVE_LOCALTIME_R
955 #define localtime_r rk_localtime_r
956 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
957 localtime_r(const time_t *, struct tm *);
958 #endif
960 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
961 #ifndef HAVE_STRSVIS
962 #define strsvis rk_strsvis
963 #endif
964 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
965 strsvis(char *, const char *, int, const char *);
966 #endif
968 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
969 #ifndef HAVE_STRSVISX
970 #define strsvisx rk_strsvisx
971 #endif
972 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
973 strsvisx(char *, const char *, size_t, int, const char *);
974 #endif
976 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
977 #ifndef HAVE_STRUNVIS
978 #define strunvis rk_strunvis
979 #endif
980 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
981 strunvis(char *, const char *);
982 #endif
984 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
985 #ifndef HAVE_STRVIS
986 #define strvis rk_strvis
987 #endif
988 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
989 strvis(char *, const char *, int);
990 #endif
992 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
993 #ifndef HAVE_STRVISX
994 #define strvisx rk_strvisx
995 #endif
996 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
997 strvisx(char *, const char *, size_t, int);
998 #endif
1000 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1001 #ifndef HAVE_SVIS
1002 #define svis rk_svis
1003 #endif
1004 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1005 svis(char *, int, int, int, const char *);
1006 #endif
1008 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1009 #ifndef HAVE_UNVIS
1010 #define unvis rk_unvis
1011 #endif
1012 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1013 unvis(char *, int, int *, int);
1014 #endif
1016 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1017 #ifndef HAVE_VIS
1018 #define vis rk_vis
1019 #endif
1020 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1021 vis(char *, int, int, int);
1022 #endif
1024 #if !defined(HAVE_CLOSEFROM)
1025 #define closefrom rk_closefrom
1026 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1027 closefrom(int);
1028 #endif
1030 #if !defined(HAVE_TIMEGM)
1031 #define timegm rk_timegm
1032 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1033 rk_timegm(struct tm *tm);
1034 #endif
1036 #ifdef NEED_QSORT
1037 #define qsort rk_qsort
1038 void
1039 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1040 #endif
1042 #if defined(__linux__) && SOCK_CLOEXEC && !defined(SOCKET_WRAPPER_REPLACE)
1043 #undef socket
1044 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1045 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1046 #endif
1048 #ifdef SOCKET_WRAPPER_REPLACE
1049 #include <socket_wrapper.h>
1050 #endif
1052 ROKEN_CPP_END