Windows: Pull required declarations into roken.h.in
[heimdal.git] / lib / roken / roken.h.in
blob561257fffcc3858e0efd4ce9df9ca1fd1684ce21
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 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
620 #ifndef HAVE_DAEMON
621 #define daemon rk_daemon
622 #endif
623 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
624 #endif
626 #ifndef HAVE_CHOWN
627 #define chown rk_chown
628 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
629 #endif
631 #ifndef HAVE_RCMD
632 #define rcmd rk_rcmd
633 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
634 rcmd(char **, unsigned short, const char *,
635 const char *, const char *, int *);
636 #endif
638 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
639 #ifndef HAVE_INNETGR
640 #define innetgr rk_innetgr
641 #endif
642 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
643 const char*, const char*);
644 #endif
646 #ifndef HAVE_IRUSEROK
647 #define iruserok rk_iruserok
648 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
649 const char *, const char *);
650 #endif
652 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
653 #ifndef HAVE_GETHOSTNAME
654 #define gethostname rk_gethostname
655 #endif
656 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
657 #endif
659 #ifndef HAVE_WRITEV
660 #define writev rk_writev
661 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
662 writev(int, const struct iovec *, int);
663 #endif
665 #ifndef HAVE_READV
666 #define readv rk_readv
667 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
668 readv(int, const struct iovec *, int);
669 #endif
671 #ifndef HAVE_PIDFILE
672 #ifdef NO_PIDFILES
673 #define pidfile(x) ((void) 0)
674 #else
675 #define pidfile rk_pidfile
676 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
677 #endif
678 #endif
680 #ifndef HAVE_BSWAP32
681 #define bswap32 rk_bswap32
682 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
683 #endif
685 #ifndef HAVE_BSWAP16
686 #define bswap16 rk_bswap16
687 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
688 #endif
690 #ifndef HAVE_FLOCK
691 #ifndef LOCK_SH
692 #define LOCK_SH 1 /* Shared lock */
693 #endif
694 #ifndef LOCK_EX
695 #define LOCK_EX 2 /* Exclusive lock */
696 #endif
697 #ifndef LOCK_NB
698 #define LOCK_NB 4 /* Don't block when locking */
699 #endif
700 #ifndef LOCK_UN
701 #define LOCK_UN 8 /* Unlock */
702 #endif
704 #define flock(_x,_y) rk_flock(_x,_y)
705 int rk_flock(int fd, int operation);
706 #endif /* HAVE_FLOCK */
708 #ifndef HAVE_DIRFD
709 #ifdef HAVE_DIR_DD_FD
710 #define dirfd(x) ((x)->dd_fd)
711 #else
712 #ifndef _WIN32 /* Windows code never calls dirfd */
713 #error Missing dirfd() and ->dd_fd
714 #endif
715 #endif
716 #endif
718 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
720 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
722 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
724 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
726 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
728 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
729 roken_vmconcat (char **, size_t, va_list);
731 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
732 net_write (rk_socket_t, const void *, size_t);
734 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
735 net_read (rk_socket_t, void *, size_t);
737 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
738 issuid(void);
740 #ifndef HAVE_STRUCT_WINSIZE
741 struct winsize {
742 unsigned short ws_row, ws_col;
743 unsigned short ws_xpixel, ws_ypixel;
745 #endif
747 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *);
749 #ifndef HAVE_VSYSLOG
750 #define vsyslog rk_vsyslog
751 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
752 #endif
754 #if !HAVE_DECL_OPTARG
755 extern char *optarg;
756 #endif
757 #if !HAVE_DECL_OPTIND
758 extern int optind;
759 #endif
760 #if !HAVE_DECL_OPTERR
761 extern int opterr;
762 #endif
764 #ifndef HAVE_GETIPNODEBYNAME
765 #define getipnodebyname rk_getipnodebyname
766 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
767 getipnodebyname (const char *, int, int, int *);
768 #endif
770 #ifndef HAVE_GETIPNODEBYADDR
771 #define getipnodebyaddr rk_getipnodebyaddr
772 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
773 getipnodebyaddr (const void *, size_t, int, int *);
774 #endif
776 #ifndef HAVE_FREEHOSTENT
777 #define freehostent rk_freehostent
778 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
779 freehostent (struct hostent *);
780 #endif
782 #ifndef HAVE_COPYHOSTENT
783 #define copyhostent rk_copyhostent
784 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
785 copyhostent (const struct hostent *);
786 #endif
788 #ifndef HAVE_SOCKLEN_T
789 typedef int socklen_t;
790 #endif
792 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
794 #ifndef HAVE_SA_FAMILY_T
795 typedef unsigned short sa_family_t;
796 #endif
798 #ifdef HAVE_IPV6
799 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
800 #else
801 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
802 #endif
804 #define _SS_ALIGNSIZE sizeof(unsigned long)
806 #if HAVE_STRUCT_SOCKADDR_SA_LEN
808 typedef unsigned char roken_sa_family_t;
810 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
811 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
813 struct sockaddr_storage {
814 unsigned char ss_len;
815 roken_sa_family_t ss_family;
816 char __ss_pad1[_SS_PAD1SIZE];
817 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
820 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
822 typedef unsigned short roken_sa_family_t;
824 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
825 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
827 struct sockaddr_storage {
828 roken_sa_family_t ss_family;
829 char __ss_pad1[_SS_PAD1SIZE];
830 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
833 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
835 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
837 #ifndef HAVE_STRUCT_ADDRINFO
838 struct addrinfo {
839 int ai_flags;
840 int ai_family;
841 int ai_socktype;
842 int ai_protocol;
843 size_t ai_addrlen;
844 char *ai_canonname;
845 struct sockaddr *ai_addr;
846 struct addrinfo *ai_next;
848 #endif
850 #ifndef HAVE_GETADDRINFO
851 #define getaddrinfo rk_getaddrinfo
852 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
853 getaddrinfo(const char *,
854 const char *,
855 const struct addrinfo *,
856 struct addrinfo **);
857 #endif
859 #ifndef HAVE_GETNAMEINFO
860 #define getnameinfo rk_getnameinfo
861 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
862 getnameinfo(const struct sockaddr *, socklen_t,
863 char *, size_t,
864 char *, size_t,
865 int);
866 #endif
868 #ifndef HAVE_FREEADDRINFO
869 #define freeaddrinfo rk_freeaddrinfo
870 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
871 freeaddrinfo(struct addrinfo *);
872 #endif
874 #ifndef HAVE_GAI_STRERROR
875 #define gai_strerror rk_gai_strerror
876 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
877 gai_strerror(int);
878 #endif
880 #ifdef NO_SLEEP
882 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
883 sleep(unsigned int seconds);
885 #endif
887 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
888 getnameinfo_verified(const struct sockaddr *, socklen_t,
889 char *, size_t,
890 char *, size_t,
891 int);
893 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
894 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
895 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
896 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
898 #ifndef HAVE_STRFTIME
899 #define strftime rk_strftime
900 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
901 strftime (char *, size_t, const char *, const struct tm *);
902 #endif
904 #ifndef HAVE_STRPTIME
905 #define strptime rk_strptime
906 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
907 strptime (const char *, const char *, struct tm *);
908 #endif
910 #ifndef HAVE_GETTIMEOFDAY
911 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
912 gettimeofday (struct timeval *, void *);
913 #endif
915 #ifndef HAVE_EMALLOC
916 #define emalloc rk_emalloc
917 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
918 #endif
919 #ifndef HAVE_ECALLOC
920 #define ecalloc rk_ecalloc
921 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
922 #endif
923 #ifndef HAVE_EREALLOC
924 #define erealloc rk_erealloc
925 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
926 #endif
927 #ifndef HAVE_ESTRDUP
928 #define estrdup rk_estrdup
929 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
930 #endif
933 * kludges and such
936 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
937 roken_gethostby_setup(const char*, const char*);
938 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
939 roken_gethostbyname(const char*);
940 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
941 roken_gethostbyaddr(const void*, size_t, int);
943 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
944 #define roken_getservbyname(x,y) getservbyname(x,y)
945 #else
946 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
947 #endif
949 #ifdef OPENLOG_PROTO_COMPATIBLE
950 #define roken_openlog(a,b,c) openlog(a,b,c)
951 #else
952 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
953 #endif
955 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
956 #define roken_getsockname(a,b,c) getsockname(a,b,c)
957 #else
958 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
959 #endif
961 #ifndef HAVE_SETPROGNAME
962 #define setprogname rk_setprogname
963 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
964 #endif
966 #ifndef HAVE_GETPROGNAME
967 #define getprogname rk_getprogname
968 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
969 #endif
971 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
972 extern const char *__progname;
973 #endif
975 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
976 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
978 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
979 mini_inetd (int, rk_socket_t *);
981 #ifndef HAVE_LOCALTIME_R
982 #define localtime_r rk_localtime_r
983 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
984 localtime_r(const time_t *, struct tm *);
985 #endif
987 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
988 #ifndef HAVE_STRSVIS
989 #define strsvis rk_strsvis
990 #endif
991 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
992 strsvis(char *, const char *, int, const char *);
993 #endif
995 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
996 #ifndef HAVE_STRSVISX
997 #define strsvisx rk_strsvisx
998 #endif
999 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1000 strsvisx(char *, const char *, size_t, int, const char *);
1001 #endif
1003 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1004 #ifndef HAVE_STRUNVIS
1005 #define strunvis rk_strunvis
1006 #endif
1007 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1008 strunvis(char *, const char *);
1009 #endif
1011 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1012 #ifndef HAVE_STRVIS
1013 #define strvis rk_strvis
1014 #endif
1015 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1016 strvis(char *, const char *, int);
1017 #endif
1019 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1020 #ifndef HAVE_STRVISX
1021 #define strvisx rk_strvisx
1022 #endif
1023 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1024 strvisx(char *, const char *, size_t, int);
1025 #endif
1027 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1028 #ifndef HAVE_SVIS
1029 #define svis rk_svis
1030 #endif
1031 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1032 svis(char *, int, int, int, const char *);
1033 #endif
1035 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1036 #ifndef HAVE_UNVIS
1037 #define unvis rk_unvis
1038 #endif
1039 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1040 unvis(char *, int, int *, int);
1041 #endif
1043 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1044 #ifndef HAVE_VIS
1045 #define vis rk_vis
1046 #endif
1047 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1048 vis(char *, int, int, int);
1049 #endif
1051 #if !defined(HAVE_CLOSEFROM)
1052 #define closefrom rk_closefrom
1053 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1054 closefrom(int);
1055 #endif
1057 #if !defined(HAVE_TIMEGM)
1058 #define timegm rk_timegm
1059 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1060 rk_timegm(struct tm *tm);
1061 #endif
1063 #ifdef NEED_QSORT
1064 #define qsort rk_qsort
1065 void
1066 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1067 #endif
1069 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE)
1070 #undef socket
1071 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1072 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1073 #endif
1075 #ifdef SOCKET_WRAPPER_REPLACE
1076 #include <socket_wrapper.h>
1077 #endif
1079 ROKEN_CPP_END