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