Imported Upstream version 2.5.1
[debian/amanda] / common-src / amanda.h
index 66cff1d624c1f288cc9cfdb805ab280376f2d9b7..ccea1758adfdc7577902b03dc76e730112c0a5a3 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: amanda.h,v 1.123 2006/03/03 15:05:15 vectro Exp $
+ * $Id: amanda.h,v 1.131 2006/07/25 18:27:56 martinea Exp $
  *
  * the central header file included by all amanda sources
  */
 #include "config.h"
 #endif
 
+/*
+ * Force large file source even if configure guesses wrong.
+ */
+#ifndef _LARGE_FILE_SOURCE
+#define _LARGE_FILES 1
+#endif
+
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE 1
+#endif
+
+#ifndef  _FILE_OFFSET_BITS
+#define        _FILE_OFFSET_BITS 64
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+
 /*
  * I would prefer that each Amanda module include only those system headers
  * that are locally needed, but on most Unixes the system header files are not
 #  include <alloca.h>
 #endif
 
-#if 0
-/* an explanation for this is available in the CHANGES file for
-   amanda-2.4.0b5 */
-#ifdef HAVE_ASM_BYTEORDER_H
-#  include <asm/byteorder.h>
-#endif
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-
 /* from the autoconf documentation */
 #ifdef HAVE_DIRENT_H
 #  include <dirent.h>
 #  include <stdlib.h>
 #endif
 
+#ifdef HAVE_LIBGEN_H
+#  include <libgen.h>
+#endif
+
 #ifdef HAVE_STRING_H
 #  include <string.h>
 #endif
 #  include <syslog.h>
 #endif
 
+#ifdef HAVE_MATH_H
+#  include <math.h>
+#endif
+
 #ifdef HAVE_SYS_FILE_H
 #  include <sys/file.h>
 #endif
@@ -186,6 +201,10 @@ struct iovec {
 #  include <sys/wait.h>
 #endif
 
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
 #ifdef WAIT_USES_INT
   typedef int amwait_t;
 # ifndef WEXITSTATUS
@@ -275,12 +294,12 @@ struct iovec {
 #ifdef USE_DBMALLOC
 #include "dbmalloc.h"
 #else
-#define        malloc_enter(func)
-#define        malloc_leave(func)
-#define        malloc_mark(ptr)
-#define        malloc_chain_check()
-#define        malloc_dump(fd)
-#define        malloc_list(a,b,c)
+#define        malloc_enter(func)              ((void)0)
+#define        malloc_leave(func)              ((void)0)
+#define        malloc_mark(ptr)                ((void)0)
+#define        malloc_chain_check()            ((void)0)
+#define        malloc_dump(fd)                 ((void)0)
+#define        malloc_list(a,b,c)              ((void)0)
 #define        malloc_inuse(hist)              (*(hist) = 0, 0)
 #define        dbmalloc_caller_loc(x,y)        (x)
 #endif
@@ -302,20 +321,35 @@ struct iovec {
 extern int errno;
 #endif
 
+/*
+ * Some compilers have int for type of sizeof() some use size_t.
+ * size_t is the one we want...
+ */
+#define        SIZEOF(x)       (size_t)sizeof(x)
+
 
 /*
  * Some older BSD systems don't have these FD_ macros, so if not, provide them.
  */
-#ifndef FD_SET
-#  define FD_SETSIZE      (sizeof(fd_set) * 8)
-#  define FD_SET(n, p)    (((fd_set *) (p))->fds_bits[0] |= (1 << ((n) % 32)))
-#  define FD_CLR(n, p)    (((fd_set *) (p))->fds_bits[0] &= ~(1 << ((n) % 32)))
-#  define FD_ISSET(n, p)  (((fd_set *) (p))->fds_bits[0] & (1 << ((n) % 32)))
-#  define FD_ZERO(p)      memset((p), 0, sizeof(*(p)))
+#if !defined(FD_SET) || defined(LINT) || defined(__lint)
+#  undef FD_SETSIZE
+#  define FD_SETSIZE      (int)(SIZEOF(fd_set) * CHAR_BIT)
+
+#  undef FD_SET
+#  define FD_SET(n, p)    (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] |= (int)((1 << ((n) % WORD_BIT))))
+
+#  undef FD_CLR
+#  define FD_CLR(n, p)    (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] &= (int)(~(1 << ((n) % WORD_BIT))))
+
+#  undef FD_ISSET
+#  define FD_ISSET(n, p)  (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] & (1 << ((n) % WORD_BIT)))
+
+#  undef FD_ZERO
+#  define FD_ZERO(p)      memset((p), 0, SIZEOF(*(p)))
 #endif
 
 #ifndef FD_COPY
-#  define FD_COPY(p, q)   memcpy((q), (p), sizeof(fd_set))
+#  define FD_COPY(p, q)   memcpy((q), (p), SIZEOF(*(p)))
 #endif
 
 
@@ -332,30 +366,16 @@ extern int errno;
 #  define void char
 #endif
 
-/*
- * Macros to allow code to adapt to both ANSI and class C environments.
- *
- * P(): prototype argument macro - removes arguments from prototypes in
- *      class C environments
- * stringize(): turn a bare word or words into a quoted string
- * stringconcat(): turn two quoted strings into one
- */
-#if STDC_HEADERS
-#  define P(parms)     parms
-#  define stringize(x) #x
-#  define stringconcat(x, y) x ## y
-#else
-#  define P(parms)     ()
-#  define stringize(x) "x"
-#  define stringconcat(x, y) x/**/y
-#endif
+#define stringize(x) #x
+#define stringconcat(x, y) x ## y
 
 /*
  * So that we can use GNUC attributes (such as to get -Wall warnings
  * for printf-like functions).  Only do this in gcc 2.7 or later ...
  * it may work on earlier stuff, but why chance it.
  */
-#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 7
+#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 7 || defined(S_SPLINT_S) || defined(LINT) || defined(__lint)
+#undef __attribute__
 #define __attribute__(__x)
 #endif
 
@@ -373,6 +393,7 @@ extern int errno;
        onerror(abort);                                                 \
        error("assert: %s false, file %s, line %d",                     \
           stringize(exp), __FILE__, __LINE__);                         \
+        /*NOTREACHED*/                                                 \
     }                                                                  \
 } while (0)
 
@@ -383,27 +404,29 @@ extern int errno;
  */
 
 #ifdef DEBUG_CODE                                                      /* { */
-#   define dbopen()    debug_open()
+#   define dbopen(a)   debug_open(a)
 #   define dbreopen(a,b) debug_reopen(a,b)
+#   define dbrename(a,b) debug_rename(a,b)
 #   define dbclose()   debug_close()
-#   define dbprintf(p) (debug? (debug_printf p, 0) : 0)
+#   define dbprintf(p) (debug_printf p)
 #   define dbfd()      debug_fd()
 #   define dbfp()      debug_fp()
 #   define dbfn()      debug_fn()
 
-extern void debug_open P((void));
-extern void debug_reopen P((char *file, char *notation));
-extern void debug_close P((void));
-extern void debug_printf P((const char *format, ...))
+extern void debug_open(char *subdir);
+extern void debug_reopen(char *file, char *notation);
+extern void debug_rename(char *config, char *subdir);
+extern void debug_close(void);
+extern void debug_printf(const char *format, ...)
     __attribute__ ((format (printf, 1, 2)));
-extern int  debug_fd P((void));
-extern FILE *  debug_fp P((void));
-extern char *  debug_fn P((void));
-extern void set_debug_prefix_pid P((pid_t));
-extern char *debug_prefix P((char *));
-extern char *debug_prefix_time P((char *));
+extern int  debug_fd(void);
+extern FILE *  debug_fp(void);
+extern char *  debug_fn(void);
+extern void set_debug_prefix_pid(pid_t);
+extern char *debug_prefix(char *);
+extern char *debug_prefix_time(char *);
 #else                                                                  /* }{ */
-#   define dbopen()
+#   define dbopen(a)
 #   define dbreopen(a,b)
 #   define dbclose()
 #   define dbprintf(p)
@@ -418,7 +441,7 @@ extern char *debug_prefix_time P((char *));
 /* amanda #days calculation, with roundoff */
 
 #define SECS_PER_DAY   (24*60*60)
-#define days_diff(a, b)        (((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
+#define days_diff(a, b)        (int)(((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
 
 /* Global constants.  */
 #ifndef AMANDA_SERVICE_NAME
@@ -431,10 +454,10 @@ extern char *debug_prefix_time P((char *));
 #define SERVICE_SUFFIX ""
 #endif
 #ifndef AMANDA_SERVICE_DEFAULT
-#define AMANDA_SERVICE_DEFAULT 10080
+#define AMANDA_SERVICE_DEFAULT ((in_port_t)10080)
 #endif
 #ifndef KAMANDA_SERVICE_DEFAULT
-#define KAMANDA_SERVICE_DEFAULT        10081
+#define KAMANDA_SERVICE_DEFAULT        ((in_port_t)10081)
 #endif
 
 #define am_round(v,u)  ((((v) + (u) - 1) / (u)) * (u))
@@ -452,30 +475,31 @@ extern char *debug_prefix_time P((char *));
 /* 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"
 
 /* Define miscellaneous amanda functions.  */
 #define ERR_INTERACTIVE        1
 #define ERR_SYSLOG     2
 #define ERR_AMANDALOG  4
 
-extern void   set_logerror P((void (*f)(char *)));
-extern void   set_pname P((char *pname));
-extern char  *get_pname P((void));
+extern void   set_logerror(void (*f)(char *));
+extern void   set_pname(char *pname);
+extern char  *get_pname(void);
 extern int    erroutput_type;
-extern void   error     P((const char *format, ...))
+extern void   error(const char *format, ...)
     __attribute__ ((format (printf, 1, 2), noreturn));
-extern void   errordump P((const char *format, ...))
+extern void   errordump(const char *format, ...)
     __attribute__ ((format (printf, 1, 2), noreturn));
-extern int    onerror         P((void (*errf)(void)));
+extern int    onerror(void (*errf)(void));
 
-extern void *debug_alloc P((const char *c, int l, size_t size));
-extern void *debug_newalloc P((const char *c, int l, void *old, size_t size));
-extern char *debug_stralloc P((const char *c, int l, const char *str));
-extern char *debug_newstralloc P((const char *c, int l, char *oldstr,
-    const char *newstr));
-extern const char *debug_caller_loc P((const char *file, int line));
-extern int debug_alloc_push P((char *file, int line));
-extern void debug_alloc_pop P((void));
+extern void *debug_alloc      (const char *c, int l, size_t size);
+extern void *debug_newalloc   (const char *c, int l, void *old, size_t size);
+extern char *debug_stralloc   (const char *c, int l, const char *str);
+extern char *debug_newstralloc(const char *c, int l, char *oldstr,
+                              const char *newstr);
+extern const char *debug_caller_loc (const char *file, int line);
+extern int debug_alloc_push (char *file, int line);
+extern void debug_alloc_pop (void);
 
 #define        alloc(s)                debug_alloc(__FILE__, __LINE__, (s))
 #define        newalloc(p,s)           debug_newalloc(__FILE__, __LINE__, (p), (s))
@@ -515,29 +539,30 @@ extern void debug_alloc_pop P((void));
 #define vstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_vstralloc
 #define newvstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_newvstralloc
 
-extern char  *debug_vstralloc       P((const char *str, ...));
-extern char  *debug_newvstralloc    P((char *oldstr, const char *newstr, ...));
+extern char  *debug_vstralloc(const char *str, ...);
+extern char  *debug_newvstralloc(char *oldstr, const char *newstr, ...);
 
 #define        stralloc2(s1,s2)      vstralloc((s1),(s2),NULL)
 #define        newstralloc2(p,s1,s2) newvstralloc((p),(s1),(s2),NULL)
 
 /* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing 
  * string, or allocates a brand new one. */
-extern char *vstrextend P((char **oldstr, ...));
+extern char *vstrextend(char **oldstr, ...);
 
-extern char  *debug_agets   P((const char *c, int l, FILE *file));
-extern char  *debug_areads  P((const char *c, int l, int fd));
+extern /*@only@*/ /*@null@*/ char *debug_agets(const char *c, int l, FILE *file);
+extern /*@only@*/ /*@null@*/ char *debug_areads(const char *c, int l, int fd);
 #define agets(f)             debug_agets(__FILE__,__LINE__,(f))
 #define areads(f)            debug_areads(__FILE__,__LINE__,(f))
 
-extern int debug_amtable_alloc P((const char *file,
+extern int debug_amtable_alloc(const char *file,
                                  int line,
                                  void **table,
-                                 int *current,
+                                 size_t *current,
                                  size_t elsize,
-                                 int count,
+                                 size_t count,
                                  int bump,
-                                 void (*init_func)(void *)));
+                                 void (*init_func)(void *));
+
 #define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__,      \
                                                     __LINE__,        \
                                                     (t),             \
@@ -547,29 +572,30 @@ extern int debug_amtable_alloc P((const char *file,
                                                     (b),             \
                                                     (f))
 
-extern void amtable_free      P((void **table, int *current));
+extern void amtable_free(void **table, size_t *current);
 
 extern uid_t  client_uid;
 extern gid_t  client_gid;
-extern void   safe_fd         P((int fd_start, int fd_count));
-extern void   safe_cd         P((void));
-extern void   save_core       P((void));
-extern char **safe_env        P((void));
-extern char  *validate_regexp P((char *regex));
-extern char  *validate_glob   P((char *glob));
-extern char  *clean_regex     P((char *regex));
-extern int    match           P((char *regex, char *str));
-extern int    match_glob      P((char *glob, char *str));
-extern char  *glob_to_regex   P((char *glob));
-extern int    match_tar       P((char *glob, char *str));
-extern char  *tar_to_regex    P((char *glob));
-extern int    match_host      P((char *glob, char *host));
-extern int    match_disk      P((char *glob, char *disk));
-extern int    match_datestamp P((char *dateexp, char *datestamp));
-extern int    match_level     P((char *levelexp, char *level));
-extern time_t unctime         P((char *timestr));
-extern ssize_t  areads_dataready  P((int fd));
-extern void     areads_relbuf     P((int fd));
+
+void   safe_fd(int fd_start, int fd_count);
+void   safe_cd(void);
+void   save_core(void);
+char **        safe_env(void);
+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_glob(const char *glob, const char *str);
+char * glob_to_regex(const char *glob);
+int    match_tar(const char *glob, const char *str);
+char * tar_to_regex(const char *glob);
+int    match_host(const char *glob, const char *host);
+int    match_disk(const char *glob, const char *disk);
+int    match_datestamp(const char *dateexp, const char *datestamp);
+int    match_level(const char *levelexp, const char *level);
+time_t unctime(char *timestr);
+ssize_t        areads_dataready(int fd);
+void   areads_relbuf(int fd);
 
 /*
  * amfree(ptr) -- if allocated, release space and set ptr to NULL.
@@ -579,13 +605,14 @@ extern void     areads_relbuf     P((int fd));
  */
 
 #define        amfree(ptr) do {                                                \
-    if(ptr) {                                                          \
+    if((ptr) != NULL) {                                                        \
        int e__errno = errno;                                           \
        free(ptr);                                                      \
        (ptr) = NULL;                                                   \
        errno = e__errno;                                               \
+       (void)(ptr);  /* Fix value never used warning at end of routines */ \
     }                                                                  \
-} while(0)
+} while (0)
 
 #define strappend(s1,s2) do {                                          \
     char *t_t_t = (s1) ? stralloc2((s1),(s2)) : stralloc((s2));                \
@@ -620,26 +647,29 @@ extern void     areads_relbuf     P((int fd));
        areads_relbuf(fd);                                              \
     }                                                                  \
     (fd) = -1;                                                         \
+    (void)(fd);  /* Fix value never used warning at end of routines */ \
 } while(0)
 
 #define afclose(f) do {                                                        \
     if((f) != NULL) {                                                  \
        fclose(f);                                                      \
+       (f) = NULL;                                                     \
+       (void)(f);  /* Fix value never used warning at end of routines */ \
     }                                                                  \
-    (f) = NULL;                                                                \
 } while(0)
 
 #define apclose(p) do {                                                        \
     if((p) != NULL) {                                                  \
        pclose(p);                                                      \
+       (p) = NULL;                                                     \
+       (void)(p);  /* Fix value never used warning at end of routines */ \
     }                                                                  \
-    (p) = NULL;                                                                \
 } while(0)
 
 /*
  * Return the number of elements in an array.
  */
-#define am_countof(a)  (sizeof(a) / sizeof((a)[0]))
+#define am_countof(a)  (int)(SIZEOF(a) / SIZEOF((a)[0]))
 
 /*
  * min/max.  Don't do something like
@@ -725,7 +755,7 @@ extern void     areads_relbuf     P((int fd));
  */
 
 #define        STR_SIZE        4096            /* a generic string buffer size */
-#define        NUM_STR_SIZE    32              /* a generic number buffer size */
+#define        NUM_STR_SIZE    128             /* a generic number buffer size */
 
 #define        skip_whitespace(ptr,c) do {                                     \
     while((c) != '\n' && isspace(c)) (c) = *(ptr)++;                   \
@@ -748,9 +778,34 @@ extern void     areads_relbuf     P((int fd));
     while(isdigit(c)) (c) = *(ptr)++;                                  \
 } while(0)
 
+#define skip_quoted_string(ptr, c) do {                                        \
+    int        iq = 0;                                                         \
+    while (((c) != '\0') && !((iq == 0) && isspace(c))) {              \
+       if ((c) == '"') {                                               \
+           iq = !iq;                                                   \
+       } else if (((c) == '\\') && (*(ptr) == '"')) {                  \
+           (ptr)++;                                                    \
+       }                                                               \
+       (c) = *(ptr)++;                                                 \
+    }                                                                  \
+} while (0)
+
+#define        skip_quoted_line(ptr, c) do {                                   \
+    int        iq = 0;                                                         \
+    while((c) && !((iq == 0) && ((c) == '\n'))) {                      \
+       if ((c) == '"')                                                 \
+           iq = !iq;                                                   \
+       (c) = *(ptr)++;                                                 \
+    }                                                                  \
+    if(c)                                                              \
+       (c) = *(ptr)++;                                                 \
+} while(0)
+
 #define        skip_line(ptr,c) do {                                           \
-    while((c) && (c) != '\n') (c) = *(ptr)++;                          \
-    if(c) (c) = *(ptr)++;                                              \
+    while((c) && (c) != '\n')                                          \
+       (c) = *(ptr)++;                                                 \
+    if(c)                                                              \
+       (c) = *(ptr)++;                                                 \
 } while(0)
 
 #define        copy_string(ptr,c,f,l,fp) do {                                  \
@@ -759,12 +814,14 @@ extern void     areads_relbuf     P((int fd));
        if((fp) >= (f) + (l) - 1) {                                     \
            *(fp) = '\0';                                               \
            (fp) = NULL;                                                \
+           (void)(fp);  /* Fix value never used warning at end of routines */ \
            break;                                                      \
        }                                                               \
        *(fp)++ = (c);                                                  \
        (c) = *(ptr)++;                                                 \
     }                                                                  \
-    if(fp) *fp = '\0';                                                 \
+    if(fp)                                                             \
+       *fp = '\0';                                                     \
 } while(0)
 
 #define        copy_string_cs(ptr,c,f,l,fp) do {                               \
@@ -787,27 +844,18 @@ extern void     areads_relbuf     P((int fd));
         || ((s)[1] == '.' && (s)[2] == '\0')))
 
 /* from amflock.c */
-extern int    amflock   P((int fd, char *resource));
-extern int    amroflock P((int fd, char *resource));
-extern int    amfunlock P((int fd, char *resource));
+extern int    amflock(int fd, char *resource);
+extern int    amroflock(int fd, char *resource);
+extern int    amfunlock(int fd, char *resource);
 
 /* from file.c */
-extern int    mkpdir    P((char *file, int mode, uid_t uid, gid_t gid));
-extern int    rmpdir    P((char *file, char *topdir));
-extern char  *sanitise_filename P((char *inp));
-
-/* from bsd-security.c */
-extern char  *check_user_ruserok     P((const char *host,
-                                       struct passwd *pwd,
-                                       const char *user));
-extern char  *check_user_amandahosts P((const char *host,
-                                       struct passwd *pwd,
-                                       const char *user));
+extern int    mkpdir(char *file, mode_t mode, uid_t uid, gid_t gid);
+extern int    rmpdir(char *file, char *topdir);
+extern char  *sanitise_filename(char *inp);
 
+/* from old bsd-security.c */
 extern int debug;
-extern int check_security P((struct sockaddr_in *, char *, unsigned long,
-                             char **));
-
+extern int check_security(struct sockaddr_in *, char *, unsigned long, char **);
 
 /*
  * Handle functions which are not always declared on all systems.  This
@@ -816,39 +864,39 @@ extern int check_security P((struct sockaddr_in *, char *, unsigned long,
 
 /* AIX #defines accept, and provides a prototype for the alternate name */
 #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
-extern int accept P((int s, struct sockaddr *addr, int *addrlen));
+extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 #endif
 
 #ifndef HAVE_ATOF_DECL
-extern double atof P((const char *ptr));
+extern double atof(const char *ptr);
 #endif
 
 #ifndef HAVE_BCOPY
 # define bcopy(from,to,n) ((void)memmove((to), (from), (n)))
 #else
 # ifndef HAVE_BCOPY_DECL
-extern void bcopy P((const void *s1, void *s2, size_t n));
+extern void bcopy(const void *s1, void *s2, size_t n);
 # endif
 #endif
 
 #ifndef HAVE_BIND_DECL
-extern int bind P((int s, const struct sockaddr *name, int namelen));
+extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
 #endif
 
 #ifndef HAVE_BZERO
 #define bzero(s,n) ((void)memset((s),0,(n)))
 #else
 # ifndef HAVE_BZERO_DECL
-extern void bzero P((void *s, size_t n));
+extern void bzero(void *s, size_t n);
 # endif
 #endif
 
 #ifndef HAVE_CLOSELOG_DECL
-extern void closelog P((void));
+extern void closelog(void);
 #endif
 
 #ifndef HAVE_CONNECT_DECL
-extern int connect P((int s, struct sockaddr *name, int namelen));
+extern int connect(int s, struct sockaddr *name, socklen_t namelen);
 #endif
 
 #if !defined(TEXTDB) && !defined(HAVE_DBM_OPEN_DECL)
@@ -869,77 +917,77 @@ extern int connect P((int s, struct sockaddr *name, int namelen));
     } datum;
 #endif
 
-    extern DBM   *dbm_open     P((char *file, int flags, int mode));
-    extern void   dbm_close    P((DBM *db));
-    extern datum  dbm_fetch    P((DBM *db, datum key));
-    extern datum  dbm_firstkey P((DBM *db));
-    extern datum  dbm_nextkey  P((DBM *db));
-    extern int    dbm_delete   P((DBM *db, datum key));
-    extern int    dbm_store    P((DBM *db, datum key, datum content, int flg));
+    extern DBM   *dbm_open(char *file, int flags, int mode);
+    extern void   dbm_close(DBM *db);
+    extern datum  dbm_fetch(DBM *db, datum key);
+    extern datum  dbm_firstkey(DBM *db);
+    extern datum  dbm_nextkey(DBM *db);
+    extern int    dbm_delete(DBM *db, datum key);
+    extern int    dbm_store(DBM *db, datum key, datum content, int flg);
 #endif
 
 #ifndef HAVE_FCLOSE_DECL
-extern int fclose P((FILE *stream));
+extern int fclose(FILE *stream);
 #endif
 
 #ifndef HAVE_FFLUSH_DECL
-extern int fflush P((FILE *stream));
+extern int fflush(FILE *stream);
 #endif
 
 #ifndef HAVE_FPRINTF_DECL
-extern int fprintf P((FILE *stream, const char *format, ...));
+extern int fprintf(FILE *stream, const char *format, ...);
 #endif
 
 #ifndef HAVE_FPUTC_DECL
-extern int fputc P((int c, FILE *stream));
+extern int fputc(int c, FILE *stream);
 #endif
 
 #ifndef HAVE_FPUTS_DECL
-extern int fputs P((const char *s, FILE *stream));
+extern int fputs(const char *s, FILE *stream);
 #endif
 
 #ifndef HAVE_FREAD_DECL
-extern size_t fread P((void *ptr, size_t size, size_t nitems, FILE *stream));
+extern size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
 #endif
 
 #ifndef HAVE_FSEEK_DECL
-extern int fseek P((FILE *stream, long offset, int ptrname));
+extern int fseek(FILE *stream, long offset, int ptrname);
 #endif
 
 #ifndef HAVE_FWRITE_DECL
-extern size_t fwrite P((const void *ptr, size_t size, size_t nitems,
-                       FILE *stream));
+extern size_t fwrite(const void *ptr, size_t size, size_t nitems,
+                       FILE *stream);
 #endif
 
 #ifndef HAVE_GETHOSTNAME_DECL
-extern int gethostname P((char *name, int namelen));
+extern int gethostname(char *name, int namelen);
 #endif
 
 #ifndef HAVE_GETOPT_DECL
 extern char *optarg;
-extern int getopt P((int argc, char * const *argv, const char *optstring));
+extern int getopt(int argc, char * const *argv, const char *optstring);
 #endif
 
 /* AIX #defines getpeername, and provides a prototype for the alternate name */
 #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
-extern int getpeername P((int s, struct sockaddr *name, int *namelen));
+extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
 #endif
 
 /* AIX #defines getsockname, and provides a prototype for the alternate name */
 #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
-extern int getsockname P((int s, struct sockaddr *name, int *namelen));
+extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
 #endif
 
 #ifndef HAVE_GETSOCKOPT_DECL
-extern int getsockopt P((int s, int level, int optname, char *optval,
-                        int *optlen));
+extern int getsockopt(int s, int level, int optname, char *optval,
+                        socklen_t *optlen);
 #endif
 
 #ifndef HAVE_GETTIMEOFDAY_DECL
 # ifdef HAVE_TWO_ARG_GETTIMEOFDAY
-extern int gettimeofday P((struct timeval *tp, struct timezone *tzp));
+extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
 # else
-extern int gettimeofday P((struct timeval *tp));
+extern int gettimeofday(struct timeval *tp);
 # endif
 #endif
 
@@ -947,245 +995,251 @@ extern int gettimeofday P((struct timeval *tp));
 # define initgroups(name,basegid) 0
 #else
 # ifndef HAVE_INITGROUPS_DECL
-extern int initgroups P((const char *name, gid_t basegid));
+extern int initgroups(const char *name, gid_t basegid);
 # endif
 #endif
 
 #ifndef HAVE_IOCTL_DECL
-extern int ioctl P((int fildes, int request, ...));
+extern int ioctl(int fildes, int request, ...);
+#endif
+
+#ifndef isnormal
+#ifndef HAVE_ISNORMAL
+#define        isnormal(f) (((f) < 0.0) || ((f) > 0.0))
+#endif
 #endif
 
 #ifndef HAVE_LISTEN_DECL
-extern int listen P((int s, int backlog));
+extern int listen(int s, int backlog);
 #endif
 
 #ifndef HAVE_LSTAT_DECL
-extern int lstat P((const char *path, struct stat *buf));
+extern int lstat(const char *path, struct stat *buf);
 #endif
 
 #ifndef HAVE_MALLOC_DECL
-extern void *malloc P((size_t size));
+extern void *malloc (size_t size);
 #endif
 
 #ifndef HAVE_MEMMOVE_DECL
 #ifdef HAVE_MEMMOVE
-extern void *memmove P((void *to, const void *from, size_t n));
+extern void *memmove(void *to, const void *from, size_t n);
 #else
-extern char *memmove P((char *to, /*const*/ char *from, size_t n));
+extern char *memmove(char *to, /*const*/ char *from, size_t n);
 #endif
 #endif
 
 #ifndef HAVE_MEMSET_DECL
-extern void *memset P((void *s, int c, size_t n));
+extern void *memset(void *s, int c, size_t n);
 #endif
 
 #ifndef HAVE_MKTEMP_DECL
-extern char *mktemp P((char *template));
+extern char *mktemp(char *template);
 #endif
 
 #ifndef HAVE_MKSTEMP_DECL
-extern int mkstemp P((char *template));
+extern int mkstemp(char *template);
 #endif
 
 #ifndef HAVE_MKTIME_DECL
-extern time_t mktime P((struct tm *timeptr));
+extern time_t mktime(struct tm *timeptr);
 #endif
 
 #ifndef HAVE_OPENLOG_DECL
 #ifdef LOG_AUTH
-extern void openlog P((const char *ident, int logopt, int facility));
+extern void openlog(const char *ident, int logopt, int facility);
 #else
-extern void openlog P((const char *ident, int logopt));
+extern void openlog(const char *ident, int logopt);
 #endif
 #endif
 
 #ifndef HAVE_PCLOSE_DECL
-extern int pclose P((FILE *stream));
+extern int pclose(FILE *stream);
 #endif
 
 #ifndef HAVE_PERROR_DECL
-extern void perror P((const char *s));
+extern void perror(const char *s);
 #endif
 
 #ifndef HAVE_PRINTF_DECL
-extern int printf P((const char *format, ...));
+extern int printf(const char *format, ...);
 #endif
 
 #ifndef HAVE_PUTS_DECL
-extern int puts P((const char *s));
+extern int puts(const char *s);
 #endif
 
 #ifndef HAVE_REALLOC_DECL
-extern void *realloc P((void *ptr, size_t size));
+extern void *realloc(void *ptr, size_t size);
 #endif
 
 /* AIX #defines recvfrom, and provides a prototype for the alternate name */
 #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
-extern int recvfrom P((int s, char *buf, int len, int flags,
-                      struct sockaddr *from, int *fromlen));
+extern int recvfrom(int s, char *buf, int len, int flags,
+                      struct sockaddr *from, socklen_t *fromlen);
 #endif
 
 #ifndef HAVE_REMOVE_DECL
-extern int remove P((const char *path));
+extern int remove(const char *path);
 #endif
 
 #ifndef HAVE_RENAME_DECL
-extern int rename P((const char *old, const char *new));
+extern int rename(const char *old, const char *new);
 #endif
 
 #ifndef HAVE_REWIND_DECL
-extern void rewind P((FILE *stream));
+extern void rewind(FILE *stream);
 #endif
 
 #ifndef HAVE_RUSEROK_DECL
-extern int ruserok P((const char *rhost, int suser,
-                     const char *ruser, const char *luser));
+extern int ruserok(const char *rhost, int suser,
+                     const char *ruser, const char *luser);
 #endif
 
 #ifndef HAVE_SELECT_DECL
-extern int select P((int nfds,
+extern int select(int nfds,
                     SELECT_ARG_TYPE *readfds,
                     SELECT_ARG_TYPE *writefds,
                     SELECT_ARG_TYPE *exceptfds,
-                    struct timeval *timeout));
+                    struct timeval *timeout);
 #endif
 
 #ifndef HAVE_SENDTO_DECL
-extern int sendto P((int s, const char *msg, int len, int flags,
-                    const struct sockaddr *to, int tolen));
+extern int sendto(int s, const char *msg, int len, int flags,
+                    const struct sockaddr *to, int tolen);
 #endif
 
 #ifdef HAVE_SETRESGID
-#define        setegid(x)      setresgid(-1,(x),-1)
+#define        setegid(x)      setresgid((gid_t)-1,(x),(gid_t)-1)
 #ifndef HAVE_SETRESGID_DECL
-extern int setresgid P((gid_t rgid, gid_t egid, gid_t sgid));
+extern int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
 #endif
 #else
 #ifndef HAVE_SETEGID_DECL
-extern int setegid P((gid_t egid));
+extern int setegid(gid_t egid);
 #endif
 #endif
 
 #ifdef HAVE_SETRESUID
-#define        seteuid(x)      setresuid(-1,(x),-1)
+#define        seteuid(x)      setresuid((uid_t)-1,(x),(uid_t)-1)
 #ifndef HAVE_SETRESUID_DECL
-extern int setresuid P((uid_t ruid, uid_t euid, uid_t suid));
+extern int setresuid(uid_t ruid, uid_t euid, uid_t suid);
 #endif
 #else
 #ifndef HAVE_SETEUID_DECL
-extern int seteuid P((uid_t euid));
+extern int seteuid(uid_t euid);
 #endif
 #endif
 
 #ifndef HAVE_SETPGID_DECL
 #ifdef HAVE_SETPGID
-extern int setpgid P((int pid, int pgid));
+extern int setpgid(pid_t pid, pid_t pgid);
 #endif
 #endif
 
 #ifndef HAVE_SETPGRP_DECL
 #ifdef SETPGRP_VOID
-extern pid_t setpgrp P((void));
+extern pid_t setpgrp(void);
 #else
-extern pid_t setpgrp P((int pgrp, int pid));
+extern pid_t setpgrp(pid_t pgrp, pid_t pid);
 #endif
 #endif
 
 #ifndef HAVE_SETSOCKOPT_DECL
-extern int setsockopt P((int s, int level, int optname,
-                        const char *optval, int optlen));
+extern int setsockopt(int s, int level, int optname,
+                        const char *optval, int optlen);
 #endif
 
 #ifdef HAVE_SHMGET
 #ifndef HAVE_SHMAT_DECL
-extern void *shmat P((int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg));
+extern void *shmat(int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg);
 #endif
 
 #ifndef HAVE_SHMCTL_DECL
-extern int shmctl P((int shmid, int cmd, struct shmid_ds *buf));
+extern int shmctl(int shmid, int cmd, struct shmid_ds *buf);
 #endif
 
 #ifndef HAVE_SHMDT_DECL
-extern int shmdt P((SHM_ARG_TYPE *shaddr));
+extern int shmdt(SHM_ARG_TYPE *shaddr);
 #endif
 
 #ifndef HAVE_SHMGET_DECL
-extern int shmget P((key_t key, size_t size, int shmflg));
+extern int shmget(key_t key, size_t size, int shmflg);
 #endif
 #endif
 
 #ifndef HAVE_SNPRINTF_DECL
 #include "arglist.h"
-int snprintf  P((char *buf, size_t len, const char *format,...))
+int snprintf(char *buf, size_t len, const char *format,...)
                    __attribute__((format(printf,3,4)));
 #endif
 #ifndef HAVE_VSNPRINTF_DECL
 #include "arglist.h"
-int vsnprintf P((char *buf, size_t len, const char *format, va_list ap));
+int vsnprintf(char *buf, size_t len, const char *format, va_list ap);
 #endif
 
 #ifndef HAVE_SOCKET_DECL
-extern int socket P((int domain, int type, int protocol));
+extern int socket(int domain, int type, int protocol);
 #endif
 
 #ifndef HAVE_SOCKETPAIR_DECL
-extern int socketpair P((int domain, int type, int protocol, int sv[2]));
+extern int socketpair(int domain, int type, int protocol, int sv[2]);
 #endif
 
 #ifndef HAVE_SSCANF_DECL
-extern int sscanf P((const char *s, const char *format, ...));
+extern int sscanf(const char *s, const char *format, ...);
 #endif
 
 #ifndef HAVE_STRCASECMP_DECL
-extern int strcasecmp P((const char *s1, const char *s2));
+extern int strcasecmp(const char *s1, const char *s2);
 #endif
 
 #ifndef HAVE_STRERROR_DECL
-extern char *strerror P((int errnum));
+extern char *strerror(int errnum);
 #endif
 
 #ifndef HAVE_STRFTIME_DECL
-extern size_t strftime P((char *s, size_t maxsize, const char *format,
-                         const struct tm *timeptr));
+extern size_t strftime(char *s, size_t maxsize, const char *format,
+                         const struct tm *timeptr);
 #endif
 
 #ifndef HAVE_STRNCASECMP_DECL
-extern int strncasecmp P((const char *s1, const char *s2, int n));
+extern int strncasecmp(const char *s1, const char *s2, int n);
 #endif
 
 #ifndef HAVE_SYSLOG_DECL
-extern void syslog P((int priority, const char *logstring, ...))
+extern void syslog(int priority, const char *logstring, ...)
     __attribute__ ((format (printf, 2, 3)));
 #endif
 
 #ifndef HAVE_SYSTEM_DECL
-extern int system P((const char *string));
+extern int system(const char *string);
 #endif
 
 #ifndef HAVE_TIME_DECL
-extern time_t time P((time_t *tloc));
+extern time_t time(time_t *tloc);
 #endif
 
 #ifndef HAVE_TOLOWER_DECL
-extern int tolower P((int c));
+extern int tolower(int c);
 #endif
 
 #ifndef HAVE_TOUPPER_DECL
-extern int toupper P((int c));
+extern int toupper(int c);
 #endif
 
 #ifndef HAVE_UNGETC_DECL
-extern int ungetc P((int c, FILE *stream));
+extern int ungetc(int c, FILE *stream);
 #endif
 
 #ifndef HAVE_VFPRINTF_DECL
 #include "arglist.h"
-extern int vfprintf P((FILE *stream, const char *format, va_list ap));
+extern int vfprintf(FILE *stream, const char *format, va_list ap);
 #endif
 
 #ifndef HAVE_VPRINTF_DECL
 #include "arglist.h"
-extern int vprintf P((const char *format, va_list ap));
+extern int vprintf(const char *format, va_list ap);
 #endif
 
 #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
@@ -1200,12 +1254,12 @@ extern int vprintf P((const char *format, va_list ap));
 #ifdef HAVE_WAIT4
 #define waitpid(pid,status,options) wait4(pid,status,options,0)
 #else
-extern pid_t waitpid P((pid_t pid, amwait_t *stat_loc, int options));
+extern pid_t waitpid(pid_t pid, amwait_t *stat_loc, int options);
 #endif
 #endif
 
 #ifndef HAVE_WRITEV_DECL
-extern ssize_t writev P((int fd, const struct iovec *iov, int iovcnt));
+extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
 #endif
 
 #ifndef STDIN_FILENO
@@ -1225,82 +1279,147 @@ extern ssize_t writev P((int fd, const struct iovec *iov, int iovcnt));
 #if defined(_S_IFMT) && defined(_S_IFDIR)
 #define S_ISDIR(mode)   (((mode) & (_S_IFMT)) == (_S_IFDIR))
 #else
-error: Don t know how to define S_ISDIR
+#error Don t know how to define S_ISDIR
+#endif
+#endif
+
+#if SIZEOF_SIZE_T == SIZEOF_INT
+#  define        SIZE_T_FMT    "%u"
+#  define        SIZE_T_FMT_TYPE unsigned
+#  define        SIZE_T_ATOI   (size_t)atoi
+#  ifndef SIZE_MAX
+#    define      SIZE_MAX      UINT_MAX
+#  endif
+#else
+#  define        SIZE_T_FMT    "%lu"
+#  define        SIZE_T_FMT_TYPE unsigned long
+#  define        SIZE_T_ATOI   (size_t)atol
+#  ifndef SIZE_MAX
+#    define      SIZE_MAX      ULONG_MAX
+#  endif
+#endif
+
+#if SIZEOF_SSIZE_T == SIZEOF_INT
+#  define        SSIZE_T_FMT   "%d"
+#  define        SSIZE_T_FMT_TYPE int
+#  define        SSIZE_T_ATOI  (ssize_t)atoi
+#  ifndef SSIZE_MAX
+#    define      SSIZE_MAX     INT_MAX
+#  endif
+#  ifndef SSIZE_MIN
+#    define      SSIZE_MIN     INT_MIN
+#  endif
+#else
+#  define        SSIZE_T_FMT   "%ld"
+#  define        SSIZE_T_FMT_TYPE long
+#  define        SSIZE_T_ATOI  (ssize_t)atol
+#  ifndef SSIZE_MAX
+#    define      SSIZE_MAX     LONG_MAX
+#  endif
+#  ifndef SSIZE_MIN
+#    define      SSIZE_MIN     LONG_MIN
+#  endif
 #endif
+
+#if SIZEOF_TIME_T == SIZEOF_INT
+#  define        TIME_T_FMT    "%u"
+#  define        TIME_T_FMT_TYPE unsigned
+#  define        TIME_T_ATOI   (time_t)atoi
+#  ifndef TIME_MAX
+#    define      TIME_MAX      UINT_MAX
+#  endif
+#else
+#  define        TIME_T_FMT    "%lu"
+#  define        TIME_T_FMT_TYPE unsigned long
+#  define        TIME_T_ATOI   (time_t)atol
+#  ifndef TIME_MAX
+#    define      TIME_MAX      ULONG_MAX
+#  endif
 #endif
 
 #if SIZEOF_OFF_T > SIZEOF_LONG
-#  define        OFF_T_FMT       LL_FMT
+#  define        OFF_T_FMT       "%lld"
+#  define        OFF_T_RFMT       "lld"
+#  define        OFF_T_FMT_TYPE  long long
+#  define        OFF_T_ATOI     (off_t)atoll
+#  define        OFF_T_STRTOL   (off_t)strtoll
 #else
-#  define        OFF_T_FMT       "%ld"
+#  if SIZEOF_OFF_T == SIZEOF_LONG
+#    define        OFF_T_FMT       "%ld"
+#    define        OFF_T_RFMT      "ld"
+#    define        OFF_T_FMT_TYPE  long
+#    define        OFF_T_ATOI   (off_t)atol
+#    define        OFF_T_STRTOL         (off_t)strtol
+#  else
+#    define        OFF_T_FMT       "%d"
+#    define        OFF_T_RFMT      "d"
+#    define        OFF_T_FMT_TYPE  int
+#    define        OFF_T_ATOI   (off_t)atoi
+#    define        OFF_T_STRTOL         (off_t)strtol
+#  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
+#  define AM64_FMT OFF_T_FMT
+#else
 #if SIZEOF_LONG == 8
-   typedef long am64_t;
 #  ifdef LONG_MAX
-#    define AM64_MAX LONG_MAX
+#    define AM64_MAX (off_t)(LONG_MAX)
 #  else
-#    define AM64_MAX 9223372036854775807L
+#    define AM64_MAX (off_t)9223372036854775807L
 #  endif
 #  ifdef LONG_MIN
-#    define AM64_MIN LONG_MIN
+#    define AM64_MIN (off_t)(LONG_MIN)
 #  else
-#    define AM64_MIN -9223372036854775807L -1L
+#    define AM64_MIN (off_t)(-9223372036854775807L -1L)
 #  endif
 #  define AM64_FMT "%ld"
 #else
 #if SIZEOF_LONG_LONG == 8
-   typedef long long am64_t;
 #  ifdef LONG_LONG_MAX
-#    define AM64_MAX LONG_LONG_MAX
+#    define AM64_MAX (off_t)(LONG_LONG_MAX)
 #  else
-#    define AM64_MAX 9223372036854775807LL
+#    define AM64_MAX (off_t)9223372036854775807LL
 #  endif
 #  ifdef LONG_LONG_MIN
-#    define AM64_MIN LONG_LONG_MIN
+#    define AM64_MIN (off_t)(LONG_LONG_MIN)
 #  else
-#    define AM64_MIN -9223372036854775807LL -1LL
+#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
 #  endif
 #  define AM64_FMT LL_FMT
 #else
 #if SIZEOF_INTMAX_T == 8
-   typedef intmax_t am64_t;
 #  ifdef INTMAX_MAX
-#    define AM64_MAX INTMAX_MAX
+#    define AM64_MAX (off_t)(INTMAX_MAX)
 #  else
-#    define AM64_MAX 9223372036854775807LL
+#    define AM64_MAX (off_t)9223372036854775807LL
 #  endif
 #  ifdef INTMAX_MIN
-#    define AM64_MIN INTMAX_MIN
+#    define AM64_MIN (off_t)(INTMAX_MIN)
 #  else
-#    define AM64_MIN -9223372036854775807LL -1LL
+#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
 #  endif
 #  define AM64_FMT LL_FMT
-#else
-#if SIZEOF_OFF_T == 8
-   typedef off_t am64_t;
-#  ifdef OFF_MAX
-#    define AM64_MAX OFF_MAX
-#  else
-#    define AM64_MAX 9223372036854775807LL
-#  endif
-#  ifdef OFF_MIN
-#    define AM64_MIN OFF_MIN
-#  else
-#    define AM64_MIN -9223372036854775807LL -1LL
-#  endif
-#  define AM64_FMT OFF_T_FMT
-#else  /* no 64 bits tyupe found, use long. */
-   typedef long am64_t;
+#else  /* no 64 bits type found, use long. */
 #  ifdef LONG_MAX
-#    define AM64_MAX LONG_MAX
+#    define AM64_MAX (off_t)(LONG_MAX)
 #  else
-#    define AM64_MAX 2147483647
+#    define AM64_MAX (off_t)2147483647
 #  endif
 #  ifdef LONG_MIN
-#    define AM64_MIN LONG_MIN
+#    define AM64_MIN (off_t)(LONG_MIN)
 #  else
-#    define AM64_MIN -2147483647 -1
+#    define AM64_MIN (off_t)(-2147483647 -1)
 #  endif
 #  define AM64_FMT "%ld"
 #endif
@@ -1308,4 +1427,33 @@ error: Don t know how to define S_ISDIR
 #endif
 #endif
 
+#ifdef HAVE_LIBREADLINE
+#  ifdef HAVE_READLINE_READLINE_H
+#    include <readline/readline.h>
+#    ifdef HAVE_READLINE_HISTORY_H
+#      include <readline/history.h>
+#    endif
+#  else
+#    ifdef HAVE_READLINE_H
+#      include <readline.h>
+#      ifdef HAVE_HISTORY_H
+#        include <history.h>
+#      endif
+#    else
+#      undef HAVE_LIBREADLINE
+#    endif
+#  endif
+#else
+
+char * readline(const char *prompt);
+void   add_history(const char *line);
+
+#endif
+
+#define BIND_CYCLE_RETRIES     120             /* Total of 30 minutes */
+
+#define DBG_SUBDIR_SERVER  "server"
+#define DBG_SUBDIR_CLIENT  "client"
+#define DBG_SUBDIR_AMANDAD "amandad"
+
 #endif /* !AMANDA_H */