2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amanda.h,v 1.131 2006/07/25 18:27:56 martinea Exp $
29 * the central header file included by all amanda sources
35 #include <glib/gprintf.h>
40 /* use a relative path here to avoid conflicting with Perl's config.h. */
41 #include "../config/config.h"
45 * Force large file source even if configure guesses wrong.
47 #ifndef _LARGE_FILE_SOURCE
48 #define _LARGE_FILES 1
51 #ifndef _LARGEFILE64_SOURCE
52 #define _LARGEFILE64_SOURCE 1
55 #ifndef _FILE_OFFSET_BITS
56 #define _FILE_OFFSET_BITS 64
59 #ifdef HAVE_SYS_TYPES_H
60 # include <sys/types.h>
63 /* gnulib creates this header locally if the system doesn't provide it */
67 * I would prefer that each Amanda module include only those system headers
68 * that are locally needed, but on most Unixes the system header files are not
69 * protected against multiple inclusion, so this can lead to problems.
71 * Also, some systems put key files in different places, so by including
72 * everything here the rest of the system is isolated from such things.
78 /* from the autoconf documentation */
81 # define NAMLEN(dirent) strlen((dirent)->d_name)
83 # define dirent direct
84 # define NAMLEN(dirent) (dirent)->d_namlen
86 # include <sys/ndir.h>
99 # define plural(String1, String2, Count) \
100 (((Count) == 1) ? (String1) : (String2))
102 # define plural(String1, String2, Count) \
103 (((Count) == 1) ? (String1) : (String2))
104 # define setlocale(Which, Locale)
105 # define textdomain(Domain)
106 # define bindtextdomain(Package, Directory)
107 # define gettext(String) String
108 # define dgettext(Domain, String) String
109 # define dcgettext(Domain, String, Catagory) String
110 # define ngettext(String1, String2, Count) \
111 plural((String1), (String2), (Count))
112 # define dngettext(Domain, String1, String2, Count) \
113 plural((String1), (String2), (Count))
114 # define dcngettext(Domain, String1, String2, Count, Catagory) \
115 plural((String1), (String2), (Count))
117 #define T_(String) String
118 #ifndef SWIG /* TODO: make this go away */
119 #define _(String) dgettext("amanda", (String))
130 #if defined(USE_DB_H)
133 #if defined(USE_DBM_H)
136 #if defined(USE_GDBM_H)
139 #if defined(USE_NDBM_H)
150 #ifdef TIME_WITH_SYS_TIME
151 # include <sys/time.h>
154 # ifdef HAVE_SYS_TIME_H
155 # include <sys/time.h>
177 #ifdef HAVE_STRINGS_H
178 # include <strings.h>
189 #ifdef HAVE_SYS_FILE_H
190 # include <sys/file.h>
193 #ifdef HAVE_SYS_IOCTL_H
194 # include <sys/ioctl.h>
201 #ifdef HAVE_SYS_PARAM_H
202 # include <sys/param.h>
205 #if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SHM_H)
206 # include <sys/ipc.h>
207 # include <sys/shm.h>
209 # ifdef HAVE_SYS_MMAN_H
210 # include <sys/mman.h>
214 #ifdef HAVE_SYS_SELECT_H
215 # include <sys/select.h>
218 #ifdef HAVE_SYS_STAT_H
219 # include <sys/stat.h>
222 #ifdef HAVE_SYS_UIO_H
223 # include <sys/uio.h>
235 #ifdef HAVE_SYS_WAIT_H
236 # include <sys/wait.h>
244 typedef int amwait_t;
246 # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
249 # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
252 # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
255 # ifdef WAIT_USES_UNION
256 typedef union wait amwait_t;
258 # define WEXITSTATUS(stat_val) (((amwait_t*)&(stat_val))->w_retcode)
261 # define WTERMSIG(stat_val) (((amwait_t*)&(stat_val))->w_termsig)
264 # define WIFEXITED(stat_val) (WTERMSIG(stat_val) == 0)
267 typedef int amwait_t;
269 # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
272 # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
275 # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
281 # define WIFSIGNALED(stat_val) (WTERMSIG(stat_val) != 0)
288 #ifdef HAVE_NETINET_IN_H
289 # include <netinet/in.h>
298 #include <sys/resource.h>
299 #include <sys/socket.h>
301 #ifdef HAVE_ARPA_INET_H
302 #include <arpa/inet.h>
305 /* Support for missing IPv6 components */
306 #ifndef HAVE_SOCKADDR_STORAGE
307 # define sockaddr_storage sockaddr_in
308 # define ss_family sin_family
315 #ifndef INET_ADDRSTRLEN
316 #define INET_ADDRSTRLEN 16
319 #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC)
320 /* quick'n'dirty hack for NextStep31 */
321 # define sa_flags sv_flags
322 # define sa_handler sv_handler
323 # define sa_mask sv_mask
324 # define sigaction sigvec
325 # define sigemptyset(mask) /* no way to clear pending signals */
329 * Most Unixen declare errno in <errno.h>, some don't. Some multithreaded
330 * systems have errno as a per-thread macro. So, we have to be careful.
337 * Some compilers have int for type of sizeof() some use size_t.
338 * size_t is the one we want...
340 #define SIZEOF(x) (size_t)sizeof(x)
344 * Some older BSD systems don't have these FD_ macros, so if not, provide them.
346 #if !defined(FD_SET) || defined(LINT) || defined(__lint)
348 # define FD_SETSIZE (int)(SIZEOF(fd_set) * CHAR_BIT)
351 # define FD_SET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] |= (int)((1 << ((n) % WORD_BIT))))
354 # define FD_CLR(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] &= (int)(~(1 << ((n) % WORD_BIT))))
357 # define FD_ISSET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] & (1 << ((n) % WORD_BIT)))
360 # define FD_ZERO(p) memset((p), 0, SIZEOF(*(p)))
364 # define FD_COPY(p, q) memcpy((q), (p), SIZEOF(*(p)))
369 * Define MAX_HOSTNAME_LENGTH as the size of arrays to hold hostname's.
371 #undef MAX_HOSTNAME_LENGTH
372 #define MAX_HOSTNAME_LENGTH 1025
375 * If void is broken, substitute char.
381 #define stringize(x) #x
382 #define stringconcat(x, y) x ## y
384 /* amanda #days calculation, with roundoff */
386 #define SECS_PER_DAY (24*60*60)
387 #define days_diff(a, b) (int)(((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
389 /* Global constants. */
390 #ifndef AMANDA_SERVICE_NAME
391 #define AMANDA_SERVICE_NAME "amanda"
393 #ifndef KAMANDA_SERVICE_NAME
394 #define KAMANDA_SERVICE_NAME "kamanda"
396 #ifndef SERVICE_SUFFIX
397 #define SERVICE_SUFFIX ""
399 #ifndef AMANDA_SERVICE_DEFAULT
400 #define AMANDA_SERVICE_DEFAULT ((in_port_t)10080)
402 #ifndef KAMANDA_SERVICE_DEFAULT
403 #define KAMANDA_SERVICE_DEFAULT ((in_port_t)10081)
406 #define am_round(v,u) ((((v) + (u) - 1) / (u)) * (u))
407 #define am_floor(v,u) (((v) / (u)) * (u))
409 /* Holding disk block size. Do not even think about changint this! :-) */
410 #define DISK_BLOCK_KB 32
411 #define DISK_BLOCK_BYTES (DISK_BLOCK_KB * 1024)
413 /* Maximum size of a tape block */
414 /* MAX_TAPE_BLOCK_KB is defined in config.h */
415 /* by configure --with-maxtapeblocksize */
416 #define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
418 /* Maximum length of tape label, plus one for null-terminator. */
419 #define MAX_TAPE_LABEL_LEN (10240)
420 #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
421 #define MAX_TAPE_LABEL_FMT "%10240s"
426 void *debug_alloc(const char *file, int line, size_t size);
427 void *debug_newalloc(const char *file, int line, void *old, size_t size);
428 char *debug_stralloc(const char *file, int line, const char *str);
429 char *debug_newstralloc(const char *file, int line,
430 char *oldstr, const char *newstr);
431 char *debug_vstralloc(const char *file, int line, const char *str, ...);
432 char *debug_newvstralloc(const char *file, int line,
433 char *oldstr, const char *str, ...);
434 char *debug_vstrallocf(const char *file, int line, const char *fmt,
435 ...) G_GNUC_PRINTF(3, 4);
436 char *debug_newvstrallocf(const char *file, int line, char *oldstr,
437 const char *fmt, ...) G_GNUC_PRINTF(4, 5);
439 /* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing
440 * string, or allocates a brand new one. */
441 char *debug_vstrextend(const char *file, int line, char **oldstr, ...);
443 #define alloc(s) debug_alloc(__FILE__, __LINE__, (s))
444 #define newalloc(p,s) debug_newalloc(__FILE__, __LINE__, (p), (s))
445 #define stralloc(s) debug_stralloc(__FILE__, __LINE__, (s))
446 #define newstralloc(p,s) debug_newstralloc(__FILE__, __LINE__, (p), (s))
447 #define vstralloc(...) debug_vstralloc(__FILE__,__LINE__,__VA_ARGS__)
448 #define newvstralloc(...) debug_newvstralloc(__FILE__,__LINE__,__VA_ARGS__)
449 #define vstrallocf(...) debug_vstrallocf(__FILE__,__LINE__,__VA_ARGS__)
450 #define newvstrallocf(...) debug_newvstrallocf(__FILE__,__LINE__,__VA_ARGS__)
451 #define vstrextend(...) debug_vstrextend(__FILE__,__LINE__,__VA_ARGS__)
453 #define stralloc2(s1,s2) vstralloc((s1),(s2),NULL)
454 #define newstralloc2(p,s1,s2) newvstralloc((p),(s1),(s2),NULL)
456 #define vstrallocf(...) debug_vstrallocf(__FILE__,__LINE__,__VA_ARGS__)
458 /*@only@*/ /*@null@*/ char *debug_agets(const char *file, int line, FILE *f);
459 /*@only@*/ /*@null@*/ char *debug_areads(const char *file, int line, int fd);
460 #define agets(f) debug_agets(__FILE__,__LINE__,(f))
461 #define areads(f) debug_areads(__FILE__,__LINE__,(f))
463 extern int debug_amtable_alloc(const char *file,
470 void (*init_func)(void *));
472 #define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__, \
481 extern void amtable_free(void **, size_t *);
483 char ** safe_env(void);
484 char * validate_regexp(const char *regex);
485 char * validate_glob(const char *glob);
486 char * clean_regex(const char *regex);
487 int match(const char *regex, const char *str);
488 int match_glob(const char *glob, const char *str);
489 char * glob_to_regex(const char *glob);
490 int match_tar(const char *glob, const char *str);
491 char * tar_to_regex(const char *glob);
492 int match_host(const char *glob, const char *host);
493 int match_disk(const char *glob, const char *disk);
494 int match_datestamp(const char *dateexp, const char *datestamp);
495 int match_level(const char *levelexp, const char *level);
496 time_t unctime(char *timestr);
499 * amfree(ptr) -- if allocated, release space and set ptr to NULL.
501 * In general, this should be called instead of just free(), unless
502 * the very next source line sets the pointer to a new value.
505 #define amfree(ptr) do { \
506 if((ptr) != NULL) { \
507 int e__errno = errno; \
511 (void)(ptr); /* Fix value never used warning at end of routines */ \
515 #define strappend(s1,s2) do { \
516 char *t_t_t = (s1) ? stralloc2((s1),(s2)) : stralloc((s2)); \
522 * Return the number of elements in an array.
524 #define am_countof(a) (int)(SIZEOF(a) / SIZEOF((a)[0]))
527 * min/max. Don't do something like
531 * because the increment will be duplicated.
535 #define min(a, b) ((a) < (b) ? (a) : (b))
536 #define max(a, b) ((a) > (b) ? (a) : (b))
539 * Utility bitmask manipulation macros.
541 #define SET(t, f) ((t) |= (f))
542 #define CLR(t, f) ((t) &= ~((unsigned)(f)))
543 #define ISSET(t, f) ((t) & (f))
546 * Utility string macros. All assume a variable holds the current
547 * character and the string pointer points to the next character to
548 * be processed. Typical setup is:
552 * skip_whitespace(s, ch);
555 * If you advance the pointer "by hand" to skip over something, do
561 * Note that ch has the character at the end of the just skipped field.
562 * It is often useful to terminate a string, make a copy, then restore
563 * the input like this:
565 * skip_whitespace(s, ch);
566 * fp = s-1; ## save the start
567 * skip_nonwhitespace(s, ch); ## find the end
568 * p[-1] = '\0'; ## temporary terminate
569 * field = stralloc(fp); ## make a copy
570 * p[-1] = ch; ## restore the input
572 * The scanning macros are:
574 * skip_whitespace (ptr, var)
575 * -- skip whitespace, but stops at a newline
576 * skip_non_whitespace (ptr, var)
577 * -- skip non whitespace
578 * skip_non_whitespace_cs (ptr, var)
579 * -- skip non whitespace, stop at comment
580 * skip_integer (ptr, var)
581 * -- skip an integer field
582 * skip_line (ptr, var)
583 * -- skip just past the next newline
584 * strncmp_const (str, const_str)
585 * -- compare str to const_str, a string constant
586 * strncmp_const_skip (str, const_var, ptr, var)
587 * -- like strncmp_const, but skip the string if a match is
588 * found; this macro only tests for equality, discarding
589 * ordering information.
593 * ptr -- string pointer
594 * var -- current character
596 * These macros copy a non-whitespace field to a new buffer, and should
597 * only be used if dynamic allocation is impossible (fixed size buffers
598 * are asking for trouble):
600 * copy_string (ptr, var, field, len, fldptr)
601 * -- copy a non-whitespace field
602 * copy_string_cs (ptr, var, field, len, fldptr)
603 * -- copy a non-whitespace field, stop at comment
607 * ptr -- string pointer
608 * var -- current character
609 * field -- area to copy to
610 * len -- length of area (needs room for null byte)
611 * fldptr -- work pointer used in move
612 * if NULL on exit, the field was too small for the input
615 #define STR_SIZE 4096 /* a generic string buffer size */
616 #define NUM_STR_SIZE 128 /* a generic number buffer size */
618 #define skip_whitespace(ptr,c) do { \
619 while((c) != '\n' && isspace((int)c)) (c) = *(ptr)++; \
622 #define skip_non_whitespace(ptr,c) do { \
623 while((c) != '\0' && !isspace((int)c)) (c) = *(ptr)++; \
626 #define skip_non_whitespace_cs(ptr,c) do { \
627 while((c) != '\0' && (c) != '#' && !isspace((int)c)) (c) = *(ptr)++;\
630 #define skip_non_integer(ptr,c) do { \
631 while((c) != '\0' && !isdigit(c)) (c) = *(ptr)++; \
634 #define skip_integer(ptr,c) do { \
635 if((c) == '+' || (c) == '-') (c) = *(ptr)++; \
636 while(isdigit(c)) (c) = *(ptr)++; \
639 #define skip_quoted_string(ptr, c) do { \
641 while (((c) != '\0') && !((iq == 0) && isspace((int)c))) { \
644 } else if (((c) == '\\') && (*(ptr) == '"')) { \
651 #define skip_quoted_line(ptr, c) do { \
653 while((c) && !((iq == 0) && ((c) == '\n'))) { \
662 #define skip_line(ptr,c) do { \
663 while((c) && (c) != '\n') \
669 #define copy_string(ptr,c,f,l,fp) do { \
671 while((c) != '\0' && !isspace((int)c)) { \
672 if((fp) >= (f) + (l) - 1) { \
675 (void)(fp); /* Fix value never used warning at end of routines */ \
685 #define copy_string_cs(ptr,c,f,l,fp) do { \
687 while((c) != '\0' && (c) != '#' && !isspace((int)c)) { \
688 if((fp) >= (f) + (l) - 1) { \
699 #define is_dot_or_dotdot(s) \
702 || ((s)[1] == '.' && (s)[2] == '\0')))
704 #define strncmp_const(str, cnst) \
705 strncmp((str), (cnst), sizeof((cnst))-1)
707 /* (have to roll this up in an expression, so it can be used in if()) */
708 #define strncmp_const_skip(str, cnst, ptr, var) \
709 ((strncmp((str), (cnst), sizeof((cnst))-1) == 0)? \
710 ((ptr)+=sizeof((cnst))-1, (var)=(ptr)[-1], 0) \
713 /* from old bsd-security.c */
715 extern int check_security(struct sockaddr_storage *, char *, unsigned long, char **);
718 * Handle functions which are not always declared on all systems. This
719 * stops gcc -Wall and lint from complaining.
722 /* AIX #defines accept, and provides a prototype for the alternate name */
723 #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
724 extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
727 #ifndef HAVE_ATOF_DECL
728 extern double atof(const char *ptr);
732 # define bcopy(from,to,n) ((void)memmove((to), (from), (n)))
734 # ifndef HAVE_BCOPY_DECL
735 extern void bcopy(const void *s1, void *s2, size_t n);
739 #ifndef HAVE_BIND_DECL
740 extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
744 #define bzero(s,n) ((void)memset((s),0,(n)))
746 # ifndef HAVE_BZERO_DECL
747 extern void bzero(void *s, size_t n);
751 #ifndef HAVE_CLOSELOG_DECL
752 extern void closelog(void);
755 #ifndef HAVE_CONNECT_DECL
756 extern int connect(int s, struct sockaddr *name, socklen_t namelen);
759 #ifndef HAVE_FCLOSE_DECL
760 extern int fclose(FILE *stream);
763 #ifndef HAVE_FFLUSH_DECL
764 extern int fflush(FILE *stream);
767 #ifndef HAVE_FPRINTF_DECL
768 extern int fprintf(FILE *stream, const char *format, ...);
771 #ifndef HAVE_FPUTC_DECL
772 extern int fputc(int c, FILE *stream);
775 #ifndef HAVE_FPUTS_DECL
776 extern int fputs(const char *s, FILE *stream);
779 #ifndef HAVE_FREAD_DECL
780 extern size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
783 #ifndef HAVE_FSEEK_DECL
784 extern int fseek(FILE *stream, long offset, int ptrname);
787 #ifndef HAVE_FWRITE_DECL
788 extern size_t fwrite(const void *ptr, size_t size, size_t nitems,
792 #ifndef HAVE_GETHOSTNAME_DECL
793 extern int gethostname(char *name, int namelen);
796 #ifndef HAVE_GETOPT_DECL
798 extern int getopt(int argc, char * const *argv, const char *optstring);
801 /* AIX #defines getpeername, and provides a prototype for the alternate name */
802 #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
803 extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
806 /* AIX #defines getsockname, and provides a prototype for the alternate name */
807 #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
808 extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
811 #ifndef HAVE_GETSOCKOPT_DECL
812 extern int getsockopt(int s, int level, int optname, char *optval,
816 #ifndef HAVE_INITGROUPS
817 # define initgroups(name,basegid) 0
819 # ifndef HAVE_INITGROUPS_DECL
820 extern int initgroups(const char *name, gid_t basegid);
824 #ifndef HAVE_IOCTL_DECL
825 extern int ioctl(int fildes, int request, ...);
829 #ifndef HAVE_ISNORMAL
830 #define isnormal(f) (((f) < 0.0) || ((f) > 0.0))
834 #ifndef HAVE_LISTEN_DECL
835 extern int listen(int s, int backlog);
838 #ifndef HAVE_LSTAT_DECL
839 extern int lstat(const char *path, struct stat *buf);
842 #ifndef HAVE_MALLOC_DECL
843 extern void *malloc (size_t size);
846 #ifndef HAVE_MEMMOVE_DECL
848 extern void *memmove(void *to, const void *from, size_t n);
850 extern char *memmove(char *to, /*const*/ char *from, size_t n);
854 #ifndef HAVE_MEMSET_DECL
855 extern void *memset(void *s, int c, size_t n);
858 #ifndef HAVE_MKTEMP_DECL
859 extern char *mktemp(char *template);
862 #ifndef HAVE_MKSTEMP_DECL
863 extern int mkstemp(char *template);
866 #ifndef HAVE_MKTIME_DECL
867 extern time_t mktime(struct tm *timeptr);
870 #ifndef HAVE_OPENLOG_DECL
872 extern void openlog(const char *ident, int logopt, int facility);
874 extern void openlog(const char *ident, int logopt);
878 #ifndef HAVE_PCLOSE_DECL
879 extern int pclose(FILE *stream);
882 #ifndef HAVE_PERROR_DECL
883 extern void perror(const char *s);
886 #ifndef HAVE_PRINTF_DECL
887 extern int printf(const char *format, ...);
890 #ifndef HAVE_PUTS_DECL
891 extern int puts(const char *s);
894 #ifndef HAVE_REALLOC_DECL
895 extern void *realloc(void *ptr, size_t size);
898 /* AIX #defines recvfrom, and provides a prototype for the alternate name */
899 #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
900 extern int recvfrom(int s, char *buf, int len, int flags,
901 struct sockaddr *from, socklen_t *fromlen);
904 #ifndef HAVE_REMOVE_DECL
905 extern int remove(const char *path);
908 #ifndef HAVE_RENAME_DECL
909 extern int rename(const char *old, const char *new);
912 #ifndef HAVE_REWIND_DECL
913 extern void rewind(FILE *stream);
916 #ifndef HAVE_RUSEROK_DECL
917 extern int ruserok(const char *rhost, int suser,
918 const char *ruser, const char *luser);
921 #ifndef HAVE_SELECT_DECL
922 extern int select(int nfds,
923 SELECT_ARG_TYPE *readfds,
924 SELECT_ARG_TYPE *writefds,
925 SELECT_ARG_TYPE *exceptfds,
926 struct timeval *timeout);
929 #ifndef HAVE_SENDTO_DECL
930 extern int sendto(int s, const char *msg, int len, int flags,
931 const struct sockaddr *to, int tolen);
934 #ifdef HAVE_SETRESGID
935 #define setegid(x) setresgid((gid_t)-1,(x),(gid_t)-1)
936 #ifndef HAVE_SETRESGID_DECL
937 extern int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
940 #ifndef HAVE_SETEGID_DECL
941 extern int setegid(gid_t egid);
945 #ifdef HAVE_SETRESUID
946 #define seteuid(x) setresuid((uid_t)-1,(x),(uid_t)-1)
947 #ifndef HAVE_SETRESUID_DECL
948 extern int setresuid(uid_t ruid, uid_t euid, uid_t suid);
951 #ifndef HAVE_SETEUID_DECL
952 extern int seteuid(uid_t euid);
956 #ifndef HAVE_SETPGID_DECL
958 extern int setpgid(pid_t pid, pid_t pgid);
962 #ifndef HAVE_SETPGRP_DECL
964 extern pid_t setpgrp(void);
966 extern pid_t setpgrp(pid_t pgrp, pid_t pid);
970 #ifndef HAVE_SETSOCKOPT_DECL
971 extern int setsockopt(int s, int level, int optname,
972 const char *optval, int optlen);
976 #ifndef HAVE_SHMAT_DECL
977 extern void *shmat(int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg);
980 #ifndef HAVE_SHMCTL_DECL
981 extern int shmctl(int shmid, int cmd, struct shmid_ds *buf);
984 #ifndef HAVE_SHMDT_DECL
985 extern int shmdt(SHM_ARG_TYPE *shaddr);
988 #ifndef HAVE_SHMGET_DECL
989 extern int shmget(key_t key, size_t size, int shmflg);
993 #ifndef HAVE_SNPRINTF_DECL
995 int snprintf(char *buf, size_t len, const char *format,...)
998 #ifndef HAVE_VSNPRINTF_DECL
1000 int vsnprintf(char *buf, size_t len, const char *format, va_list ap);
1003 #ifndef HAVE_SOCKET_DECL
1004 extern int socket(int domain, int type, int protocol);
1007 #ifndef HAVE_SOCKETPAIR_DECL
1008 extern int socketpair(int domain, int type, int protocol, int sv[2]);
1011 #ifndef HAVE_SSCANF_DECL
1012 extern int sscanf(const char *s, const char *format, ...);
1015 #ifndef HAVE_STRCASECMP_DECL
1016 extern int strcasecmp(const char *s1, const char *s2);
1019 #ifndef HAVE_STRERROR_DECL
1020 extern char *strerror(int errnum);
1023 #ifndef HAVE_STRFTIME_DECL
1024 extern size_t strftime(char *s, size_t maxsize, const char *format,
1025 const struct tm *timeptr);
1028 #ifndef HAVE_STRNCASECMP_DECL
1029 extern int strncasecmp(const char *s1, const char *s2, int n);
1032 #ifndef HAVE_SYSLOG_DECL
1033 extern void syslog(int priority, const char *logstring, ...)
1037 #ifndef HAVE_SYSTEM_DECL
1038 extern int system(const char *string);
1041 #ifndef HAVE_TIME_DECL
1042 extern time_t time(time_t *tloc);
1045 #ifndef HAVE_TOLOWER_DECL
1046 extern int tolower(int c);
1049 #ifndef HAVE_TOUPPER_DECL
1050 extern int toupper(int c);
1053 #ifndef HAVE_UNGETC_DECL
1054 extern int ungetc(int c, FILE *stream);
1057 #ifndef HAVE_VFPRINTF_DECL
1058 #include "arglist.h"
1059 extern int vfprintf(FILE *stream, const char *format, va_list ap);
1062 #ifndef HAVE_VPRINTF_DECL
1063 #include "arglist.h"
1064 extern int vprintf(const char *format, va_list ap);
1067 /* gnulib-only includes (hence "" instead of <>) */
1068 #include "getaddrinfo.h"
1069 #include "inet_ntop.h"
1071 #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
1072 #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
1075 #if !defined(S_ISREG) && defined(_S_IFREG) && defined(_S_IFMT)
1076 #define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
1079 #ifndef HAVE_WAITPID
1081 #define waitpid(pid,status,options) wait4(pid,status,options,0)
1083 extern pid_t waitpid(pid_t pid, amwait_t *stat_loc, int options);
1087 #ifndef HAVE_WRITEV_DECL
1088 extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
1091 #ifndef STDIN_FILENO
1092 #define STDIN_FILENO 0
1095 #ifndef STDOUT_FILENO
1096 #define STDOUT_FILENO 1
1099 #ifndef STDERR_FILENO
1100 #define STDERR_FILENO 2
1103 /* S_ISDIR is not defined on Nextstep */
1105 #if defined(_S_IFMT) && defined(_S_IFDIR)
1106 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
1108 #error Don t know how to define S_ISDIR
1112 #if SIZEOF_SIZE_T == SIZEOF_INT
1113 # define SIZE_T_ATOI (size_t)atoi
1115 # define SIZE_MAX G_MAXUINT
1118 # define SIZE_T_ATOI (size_t)atol
1120 # define SIZE_MAX ULONG_MAX
1124 #if SIZEOF_SSIZE_T == SIZEOF_INT
1125 # define SSIZE_T_ATOI (ssize_t)atoi
1127 # define SSIZE_MAX INT_MAX
1130 # define SSIZE_MIN INT_MIN
1133 # define SSIZE_T_ATOI (ssize_t)atol
1135 # define SSIZE_MAX LONG_MAX
1138 # define SSIZE_MIN LONG_MIN
1142 #if SIZEOF_TIME_T == SIZEOF_INT
1143 # define TIME_T_ATOI (time_t)atoi
1145 # define TIME_MAX G_MAXUINT
1148 # define TIME_T_ATOI (time_t)atol
1150 # define TIME_MAX ULONG_MAX
1154 #if SIZEOF_OFF_T > SIZEOF_LONG
1156 # define OFF_T_ATOI (off_t)atoll
1158 # define OFF_T_ATOI (off_t)atol
1160 # ifdef HAVE_STRTOLL
1161 # define OFF_T_STRTOL (off_t)strtoll
1163 # define OFF_T_STRTOL (off_t)strtol
1166 # if SIZEOF_OFF_T == SIZEOF_LONG
1167 # define OFF_T_ATOI (off_t)atol
1168 # define OFF_T_STRTOL (off_t)strtol
1170 # define OFF_T_ATOI (off_t)atoi
1171 # define OFF_T_STRTOL (off_t)strtol
1175 #if SIZEOF_OFF_T == 8
1177 # define AM64_MAX (off_t)(OFF_MAX)
1179 # define AM64_MAX (off_t)(9223372036854775807LL)
1182 # define AM64_MIN (off_t)(OFF_MIN)
1184 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1187 #if SIZEOF_LONG == 8
1189 # define AM64_MAX (off_t)(LONG_MAX)
1191 # define AM64_MAX (off_t)9223372036854775807L
1194 # define AM64_MIN (off_t)(LONG_MIN)
1196 # define AM64_MIN (off_t)(-9223372036854775807L -1L)
1199 #if SIZEOF_LONG_LONG == 8
1200 # ifdef LONG_LONG_MAX
1201 # define AM64_MAX (off_t)(LONG_LONG_MAX)
1203 # define AM64_MAX (off_t)9223372036854775807LL
1205 # ifdef LONG_LONG_MIN
1206 # define AM64_MIN (off_t)(LONG_LONG_MIN)
1208 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1211 #if SIZEOF_INTMAX_T == 8
1213 # define AM64_MAX (off_t)(INTMAX_MAX)
1215 # define AM64_MAX (off_t)9223372036854775807LL
1218 # define AM64_MIN (off_t)(INTMAX_MIN)
1220 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1222 #else /* no 64 bits type found, use long. */
1224 # define AM64_MAX (off_t)(LONG_MAX)
1226 # define AM64_MAX (off_t)2147483647
1229 # define AM64_MIN (off_t)(LONG_MIN)
1231 # define AM64_MIN (off_t)(-2147483647 -1)
1238 #define BIND_CYCLE_RETRIES 120 /* Total of 30 minutes */
1240 #define MAX_DUMPERS 63
1243 #define NI_MAXHOST 1025
1247 KENCRYPT_NONE, /* krb5 encryption not enabled */
1248 KENCRYPT_WILL_DO, /* krb5 encryption will be enabled once amanda
1249 protocol stream is closed */
1250 KENCRYPT_YES /* krb5 encryption enabled on all stream */
1253 #endif /* !AMANDA_H */