Imported Upstream version 2.6.1
[debian/amanda] / common-src / amanda.h
index 886e1156ab9766b14946d288470b51c80a1a75fb..ec0653316e75bd3f0c0489bc906c3fcab8c2202b 100644 (file)
 #ifndef AMANDA_H
 #define AMANDA_H
 
-#include <glib.h>
-#include <glib/gprintf.h>
-
-#include "amflock.h"
-
 #ifdef HAVE_CONFIG_H
 /* use a relative path here to avoid conflicting with Perl's config.h. */
 #include "../config/config.h"
 #endif
 
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "amflock.h"
+
 /*
  * Force large file source even if configure guesses wrong.
  */
@@ -71,9 +71,6 @@
  * Also, some systems put key files in different places, so by including 
  * everything here the rest of the system is isolated from such things.
  */
-#ifdef HAVE_ALLOCA_H
-#  include <alloca.h>
-#endif
 
 /* from the autoconf documentation */
 #ifdef HAVE_DIRENT_H
@@ -302,12 +299,6 @@ struct iovec {
 #include <arpa/inet.h>
 #endif
 
-/* Support for missing IPv6 components */
-#ifndef HAVE_SOCKADDR_STORAGE
-#  define sockaddr_storage sockaddr_in
-#  define ss_family sin_family
-#endif
-
 #ifdef WORKING_IPV6
 #define INET6
 #endif
@@ -410,16 +401,26 @@ extern int errno;
 #define DISK_BLOCK_KB          32
 #define DISK_BLOCK_BYTES       (DISK_BLOCK_KB * 1024)
 
-/* Maximum size of a tape block */
-/* MAX_TAPE_BLOCK_KB is defined in config.h */
-/* by configure --with-maxtapeblocksize     */
-#define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
-
 /* Maximum length of tape label, plus one for null-terminator. */
 #define MAX_TAPE_LABEL_LEN (10240)
 #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
 #define MAX_TAPE_LABEL_FMT "%10240s"
 
+/* Unfortunately, the system-level sockaddr_storage definition can lead to
+ * C aliasing errors (where the optimizer doesn't notice that two operations
+ * affect the same datum).  We define our own similar type as a union.
+ */
+typedef union sockaddr_union {
+    struct sockaddr         sa;
+    struct sockaddr_in      sin;
+#ifdef WORKING_IPV6
+    struct sockaddr_in6     sin6;
+#endif
+#ifdef HAVE_SOCKADDR_STORAGE
+    struct sockaddr_storage ss;        /* not used; just here to make the union full-size */
+#endif
+} sockaddr_union;
+
 #include "debug.h"
 #include "file.h"
 
@@ -485,6 +486,7 @@ char *      validate_regexp(const char *regex);
 char * validate_glob(const char *glob);
 char * clean_regex(const char *regex);
 int    match(const char *regex, const char *str);
+int    match_no_newline(const char *regex, const char *str);
 int    match_glob(const char *glob, const char *str);
 char * glob_to_regex(const char *glob);
 int    match_tar(const char *glob, const char *str);
@@ -616,15 +618,15 @@ time_t    unctime(char *timestr);
 #define        NUM_STR_SIZE    128             /* a generic number buffer size */
 
 #define        skip_whitespace(ptr,c) do {                                     \
-    while((c) != '\n' && isspace((int)c)) (c) = *(ptr)++;              \
+    while((c) != '\n' && g_ascii_isspace((int)c)) (c) = *(ptr)++;              \
 } while(0)
 
 #define        skip_non_whitespace(ptr,c) do {                                 \
-    while((c) != '\0' && !isspace((int)c)) (c) = *(ptr)++;             \
+    while((c) != '\0' && !g_ascii_isspace((int)c)) (c) = *(ptr)++;             \
 } while(0)
 
 #define        skip_non_whitespace_cs(ptr,c) do {                              \
-    while((c) != '\0' && (c) != '#' && !isspace((int)c)) (c) = *(ptr)++;\
+    while((c) != '\0' && (c) != '#' && !g_ascii_isspace((int)c)) (c) = *(ptr)++;\
 } while(0)
 
 #define        skip_non_integer(ptr,c) do {                                    \
@@ -638,11 +640,12 @@ time_t    unctime(char *timestr);
 
 #define skip_quoted_string(ptr, c) do {                                        \
     int        iq = 0;                                                         \
-    while (((c) != '\0') && !((iq == 0) && isspace((int)c))) {         \
+    while (((c) != '\0') && !((iq == 0) && g_ascii_isspace((int)c))) {         \
        if ((c) == '"') {                                               \
            iq = !iq;                                                   \
-       } else if (((c) == '\\') && (*(ptr) == '"')) {                  \
-           (ptr)++;                                                    \
+       } else if ((c) == '\\') {                                       \
+           if (*ptr)   /* not last character */                        \
+               (ptr)++;                                                \
        }                                                               \
        (c) = *(ptr)++;                                                 \
     }                                                                  \
@@ -668,7 +671,7 @@ time_t      unctime(char *timestr);
 
 #define        copy_string(ptr,c,f,l,fp) do {                                  \
     (fp) = (f);                                                                \
-    while((c) != '\0' && !isspace((int)c)) {                           \
+    while((c) != '\0' && !g_ascii_isspace((int)c)) {                           \
        if((fp) >= (f) + (l) - 1) {                                     \
            *(fp) = '\0';                                               \
            (fp) = NULL;                                                \
@@ -684,7 +687,7 @@ time_t      unctime(char *timestr);
 
 #define        copy_string_cs(ptr,c,f,l,fp) do {                               \
     (fp) = (f);                                                                \
-    while((c) != '\0' && (c) != '#' && !isspace((int)c)) {             \
+    while((c) != '\0' && (c) != '#' && !g_ascii_isspace((int)c)) {             \
        if((fp) >= (f) + (l) - 1) {                                     \
            *(fp) = '\0';                                               \
            (fp) = NULL;                                                \
@@ -712,7 +715,7 @@ time_t      unctime(char *timestr);
 
 /* from old bsd-security.c */
 extern int debug;
-extern int check_security(struct sockaddr_storage *, char *, unsigned long, char **);
+extern int check_security(sockaddr_union *, char *, unsigned long, char **);
 
 /*
  * Handle functions which are not always declared on all systems.  This
@@ -721,7 +724,7 @@ extern int check_security(struct sockaddr_storage *, char *, unsigned long, char
 
 /* AIX #defines accept, and provides a prototype for the alternate name */
 #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
-extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+extern int accept(int s, struct sockaddr *addr, socklen_t_equiv *addrlen);
 #endif
 
 #ifndef HAVE_ATOF_DECL
@@ -737,7 +740,7 @@ extern void bcopy(const void *s1, void *s2, size_t n);
 #endif
 
 #ifndef HAVE_BIND_DECL
-extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
+extern int bind(int s, const struct sockaddr *name, socklen_t_equiv namelen);
 #endif
 
 #ifndef HAVE_BZERO
@@ -753,7 +756,7 @@ extern void closelog(void);
 #endif
 
 #ifndef HAVE_CONNECT_DECL
-extern int connect(int s, struct sockaddr *name, socklen_t namelen);
+extern int connect(int s, struct sockaddr *name, socklen_t_equiv namelen);
 #endif
 
 #ifndef HAVE_FCLOSE_DECL
@@ -800,17 +803,17 @@ extern int getopt(int argc, char * const *argv, const char *optstring);
 
 /* AIX #defines getpeername, and provides a prototype for the alternate name */
 #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
-extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
+extern int getpeername(int s, struct sockaddr *name, socklen_t_equiv *namelen);
 #endif
 
 /* AIX #defines getsockname, and provides a prototype for the alternate name */
 #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
-extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
+extern int getsockname(int s, struct sockaddr *name, socklen_t_equiv *namelen);
 #endif
 
 #ifndef HAVE_GETSOCKOPT_DECL
 extern int getsockopt(int s, int level, int optname, char *optval,
-                        socklen_t *optlen);
+                        socklen_t_equiv *optlen);
 #endif
 
 #ifndef HAVE_INITGROUPS
@@ -898,7 +901,7 @@ extern void *realloc(void *ptr, size_t size);
 /* AIX #defines recvfrom, and provides a prototype for the alternate name */
 #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
 extern int recvfrom(int s, char *buf, int len, int flags,
-                      struct sockaddr *from, socklen_t *fromlen);
+                      struct sockaddr *from, socklen_t_equiv *fromlen);
 #endif
 
 #ifndef HAVE_REMOVE_DECL
@@ -1067,6 +1070,9 @@ extern int vprintf(const char *format, va_list ap);
 /* gnulib-only includes (hence "" instead of <>) */
 #include "getaddrinfo.h"
 #include "inet_ntop.h"
+#include "safe-read.h"
+#include "full-read.h"
+#include "full-write.h"
 
 #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
 #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
@@ -1172,68 +1178,6 @@ extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
 #  endif
 #endif
 
-#if SIZEOF_OFF_T == 8
-#  ifdef OFF_MAX
-#    define AM64_MAX (off_t)(OFF_MAX)
-#  else
-#    define AM64_MAX (off_t)(9223372036854775807LL)
-#  endif
-#  ifdef OFF_MIN
-#    define AM64_MIN (off_t)(OFF_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else
-#if SIZEOF_LONG == 8
-#  ifdef LONG_MAX
-#    define AM64_MAX (off_t)(LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807L
-#  endif
-#  ifdef LONG_MIN
-#    define AM64_MIN (off_t)(LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807L -1L)
-#  endif
-#else
-#if SIZEOF_LONG_LONG == 8
-#  ifdef LONG_LONG_MAX
-#    define AM64_MAX (off_t)(LONG_LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807LL
-#  endif
-#  ifdef LONG_LONG_MIN
-#    define AM64_MIN (off_t)(LONG_LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else
-#if SIZEOF_INTMAX_T == 8
-#  ifdef INTMAX_MAX
-#    define AM64_MAX (off_t)(INTMAX_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807LL
-#  endif
-#  ifdef INTMAX_MIN
-#    define AM64_MIN (off_t)(INTMAX_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else  /* no 64 bits type found, use long. */
-#  ifdef LONG_MAX
-#    define AM64_MAX (off_t)(LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)2147483647
-#  endif
-#  ifdef LONG_MIN
-#    define AM64_MIN (off_t)(LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-2147483647 -1)
-#  endif
-#endif
-#endif
-#endif
-#endif
 
 #define BIND_CYCLE_RETRIES     120             /* Total of 30 minutes */