-/* Define miscellaneous amanda functions. */
-#define ERR_INTERACTIVE 1
-#define ERR_SYSLOG 2
-#define ERR_AMANDALOG 4
-
-/* For static buffer manager [alloc.c:sbuf_man()] */
-#define SBUF_MAGIC 42
-#define SBUF_DEF(name, len) static SBUF2_DEF(len) name = {SBUF_MAGIC, len, -1}
-#define SBUF2_DEF(len) \
- struct { \
- int magic; \
- int max, cur; \
- void *bufp[len]; \
- }
-
-extern void set_logerror P((void (*f)(char *)));
-extern void set_pname P((char *pname));
-extern char *get_pname P((void));
-extern int erroutput_type;
-extern void error P((char *format, ...))
- __attribute__ ((format (printf, 1, 2)));
-extern void errordump P((char *format, ...))
- __attribute__ ((format (printf, 1, 2)));
-extern int onerror P((void (*errf)(void)));
-
-extern void *debug_alloc P((char *c, int l, size_t size));
-extern void *debug_newalloc P((char *c, int l, void *old, size_t size));
-extern char *debug_stralloc P((char *c, int l, const char *str));
-extern char *debug_newstralloc P((char *c, int l, char *oldstr, const char *newstr));
-extern char *debug_caller_loc P((char *file, int line));
-
-extern int debug_alloc_push P((char *file, int line));
-extern void debug_alloc_pop P((void));
+/* 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"
+
+void *debug_alloc(const char *file, int line, size_t size);
+void *debug_newalloc(const char *file, int line, void *old, size_t size);
+char *debug_stralloc(const char *file, int line, const char *str);
+char *debug_newstralloc(const char *file, int line,
+ char *oldstr, const char *newstr);
+char *debug_vstralloc(const char *file, int line, const char *str, ...);
+char *debug_newvstralloc(const char *file, int line,
+ char *oldstr, const char *str, ...);
+char *debug_vstrallocf(const char *file, int line, const char *fmt,
+ ...) G_GNUC_PRINTF(3, 4);
+char *debug_newvstrallocf(const char *file, int line, char *oldstr,
+ const char *fmt, ...) G_GNUC_PRINTF(4, 5);
+
+/* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing
+ * string, or allocates a brand new one. */
+char *debug_vstrextend(const char *file, int line, char **oldstr, ...);