reconfigure git-buildpackage for unstable
[debian/amanda] / tape-src / tapeio.c
index 984dddcec9f33c5d0e2da5f008db255d09bf741a..69fdb5cac683d9602ed30515e363a171ceeaca30 100644 (file)
  */
 
 /*
- * $Id: tapeio.c,v 1.20.4.7.4.4.2.9 2003/11/28 12:34:52 martinea Exp $
+ * $Id: tapeio.c,v 1.57 2006/07/06 15:04:18 martinea Exp $
  *
  * implements generic tape I/O functions
  */
 
 #include "amanda.h"
-#include <errno.h>
-
+#include "conffile.h"
 #include "tapeio.h"
 #include "fileheader.h"
+
 #ifndef R_OK
 #define R_OK 4
 #define W_OK 2
 
 static struct virtualtape {
     char *prefix;
-    int (*xxx_tape_access) P((char *, int));
-    int (*xxx_tape_open) ();
-    int (*xxx_tape_stat) P((char *, struct stat *));
-    int (*xxx_tapefd_close) P((int));
-    int (*xxx_tapefd_fsf) P((int, int));
-    ssize_t (*xxx_tapefd_read) P((int, void *, size_t));
-    int (*xxx_tapefd_rewind) P((int));
-    void (*xxx_tapefd_resetofs) P((int));
-    int (*xxx_tapefd_unload) P((int));
-    int (*xxx_tapefd_status) P((int, struct am_mt_status *));
-    int (*xxx_tapefd_weof) P((int, int));
-    ssize_t (*xxx_tapefd_write) P((int, const void *, size_t));
-    int (*xxx_tapefd_can_fork) P((int));
+    int (*xxx_tape_access)(char *, int);
+    int (*xxx_tape_open)(char *, int, mode_t);
+    int (*xxx_tape_stat)(char *, struct stat *);
+    int (*xxx_tapefd_close)(int);
+    int (*xxx_tapefd_fsf)(int, off_t);
+    ssize_t (*xxx_tapefd_read)(int, void *, size_t);
+    int (*xxx_tapefd_rewind)(int);
+    void (*xxx_tapefd_resetofs)(int);
+    int (*xxx_tapefd_unload)(int);
+    int (*xxx_tapefd_status)(int, struct am_mt_status *);
+    int (*xxx_tapefd_weof)(int, off_t);
+    ssize_t (*xxx_tapefd_write)(int, const void *, size_t);
+    int (*xxx_tapefd_can_fork)(int);
 } vtable[] = {
   /* note: "tape" has to be the first entry because it is the
   **        default if no prefix match is found.
@@ -85,7 +85,11 @@ static struct virtualtape {
        file_tapefd_read, file_tapefd_rewind, file_tapefd_resetofs,
        file_tapefd_unload, file_tapefd_status, file_tapefd_weof,
         file_tapefd_write, file_tapefd_can_fork },
-  {NULL,},
+  {NULL, NULL, NULL, NULL,
+        NULL, NULL,
+       NULL, NULL, NULL,
+       NULL, NULL, NULL,
+       NULL, NULL}
 };
 
 static struct tape_info {
@@ -94,23 +98,28 @@ static struct tape_info {
     char *disk;
     int level;
     char *datestamp;
-    long length;
+    off_t length;
     char *tapetype;
     int fake_label;
     int ioctl_fork;
     int master_fd;
 } *tape_info = NULL;
-static int tape_info_count = 0;
+static struct tape_info **tape_info_p = &tape_info;
+
+static size_t tape_info_count = 0;
 
 static char *errstr = NULL;
 
+static void tape_info_init(void *ptr);
+static int name2slot(char *name, char **ntrans);
+
 /*
  * Additional initialization function for tape_info table.
  */
 
 static void
-tape_info_init(ptr)
-    void *ptr;
+tape_info_init(
+    void *ptr)
 {
     struct tape_info *t = ptr;
 
@@ -125,15 +134,16 @@ tape_info_init(ptr)
  */
 
 static int
-name2slot(name, ntrans)
-    char *name;
-    char **ntrans;
+name2slot(
+    char *name,
+    char **ntrans)
 {
     char *pc;
-    int len, i;
+    size_t len;
+    int i;
 
     if(0 != (pc = strchr(name, ':'))) {
-        len = pc - name;
+        len = (size_t)(pc - name);
        for( i = 0 ; vtable[i].prefix && vtable[i].prefix[0]; i++ ) {
            if(0 == strncmp(vtable[i].prefix, name , len)
                && '\0' == vtable[i].prefix[len]) {
@@ -156,10 +166,12 @@ name2slot(name, ntrans)
  */
 
 int
-tapeio_init_devname(char * dev,
-                   char **dev_left,
-                   char **dev_right,
-                   char **dev_next) {
+tapeio_init_devname(
+    char * dev,
+    char **dev_left,
+    char **dev_right,
+    char **dev_next)
+{
     int ch;
     char *p;
     int depth;
@@ -173,7 +185,9 @@ tapeio_init_devname(char * dev,
        depth = 1;
        p++;
        while(depth > 0) {
-           while((ch = *p++) != '\0' && ch != '{' && ch != '}') {}
+           ch = *p++;
+           while((ch != '\0') && (ch != '{') && (ch != '}'))
+               ch = *p++;
            if(ch == '\0') {
                /*
                 * Did not find a matching '}'.
@@ -213,9 +227,11 @@ tapeio_init_devname(char * dev,
  */
 
 char *
-tapeio_next_devname(char * dev_left,
-                   char * dev_right,
-                   char **dev_next) {
+tapeio_next_devname(
+    char * dev_left,
+    char * dev_right,
+    char **dev_next)
+{
     int ch;
     char *next;
     char *p;
@@ -224,7 +240,9 @@ tapeio_next_devname(char * dev_left,
     p = next = *dev_next;                      /* remember the start point */
     depth = 0;
     do {
-       while((ch = *p++) != '\0' && ch != '{' && ch != '}' && ch != ',') {}
+       ch = *p++;
+       while((ch != '\0') && (ch != '{') && (ch != '}') && (ch != ','))
+           ch = *p++;
        if(ch == '\0') {
            /*
             * Found the end of a name.
@@ -257,13 +275,13 @@ tapeio_next_devname(char * dev_left,
  */
 
 char *
-tapefd_getinfo_host(fd)
-    int fd;
+tapefd_getinfo_host(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     if(tape_info[fd].master_fd != -1)
@@ -272,14 +290,14 @@ tapefd_getinfo_host(fd)
 }
 
 void
-tapefd_setinfo_host(fd, v)
-    int fd;
-    char *v;
+tapefd_setinfo_host(
+    int fd,
+    char *v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     amfree(tape_info[fd].host);
@@ -289,13 +307,13 @@ tapefd_setinfo_host(fd, v)
 }
 
 char *
-tapefd_getinfo_disk(fd)
-    int fd;
+tapefd_getinfo_disk(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     if(tape_info[fd].master_fd != -1)
@@ -304,14 +322,14 @@ tapefd_getinfo_disk(fd)
 }
 
 void
-tapefd_setinfo_disk(fd, v)
-    int fd;
-    char *v;
+tapefd_setinfo_disk(
+    int fd,
+    char *v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     amfree(tape_info[fd].disk);
@@ -321,13 +339,13 @@ tapefd_setinfo_disk(fd, v)
 }
 
 int
-tapefd_getinfo_level(fd)
-    int fd;
+tapefd_getinfo_level(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     if(tape_info[fd].master_fd != -1)
@@ -336,163 +354,163 @@ tapefd_getinfo_level(fd)
 }
 
 void
-tapefd_setinfo_level(fd, v)
-    int fd;
-    int v;
+tapefd_setinfo_level(
+    int fd,
+    int v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].level = v;
 }
 
 char *
-tapefd_getinfo_datestamp(fd)
-    int fd;
+tapefd_getinfo_datestamp(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     return tape_info[fd].datestamp;
 }
 
 void
-tapefd_setinfo_datestamp(fd, v)
-    int fd;
-    char *v;
+tapefd_setinfo_datestamp(
+    int fd,
+    char *v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].datestamp = newstralloc(tape_info[fd].datestamp, v);
 }
 
-long
-tapefd_getinfo_length(fd)
-    int fd;
+off_t
+tapefd_getinfo_length(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     return tape_info[fd].length;
 }
 
 void
-tapefd_setinfo_length(fd, v)
-    int fd;
-    long v;
+tapefd_setinfo_length(
+    int fd,
+    off_t v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].length = v;
 }
 
 char *
-tapefd_getinfo_tapetype(fd)
-    int fd;
+tapefd_getinfo_tapetype(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     return tape_info[fd].tapetype;
 }
 
 void
-tapefd_setinfo_tapetype(fd, v)
-    int fd;
-    char *v;
+tapefd_setinfo_tapetype(
+    int fd,
+    char *v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].tapetype = newstralloc(tape_info[fd].tapetype, v);
 }
 
 int
-tapefd_getinfo_fake_label(fd)
-    int fd;
+tapefd_getinfo_fake_label(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     return tape_info[fd].fake_label;
 }
 
 void
-tapefd_setinfo_fake_label(fd, v)
-    int fd;
-    int v;
+tapefd_setinfo_fake_label(
+    int fd,
+    int v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].fake_label = v;
 }
 
 int
-tapefd_getinfo_ioctl_fork(fd)
-    int fd;
+tapefd_getinfo_ioctl_fork(
+    int fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     return tape_info[fd].ioctl_fork;
 }
 
 void
-tapefd_setinfo_ioctl_fork(fd, v)
-    int fd;
-    int v;
+tapefd_setinfo_ioctl_fork(
+    int fd,
+    int v)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].ioctl_fork = v;
 }
 
 void
-tapefd_set_master_fd(fd, master_fd)
-    int fd;
-    int master_fd;
+tapefd_set_master_fd(
+    int fd,
+    int master_fd)
 {
-    amtable_alloc((void **)&tape_info,
+    amtable_alloc((void **)tape_info_p,
                  &tape_info_count,
-                 sizeof(*tape_info),
-                 fd + 1,
+                 SIZEOF(*tape_info),
+                 (size_t)fd + 1,
                  10,
                  tape_info_init);
     tape_info[fd].master_fd = master_fd;
@@ -504,9 +522,9 @@ tapefd_set_master_fd(fd, master_fd)
  */
 
 int
-tape_access(filename, mode)
-    char *filename;
-    int mode;
+tape_access(
+    char *filename,
+    int mode)
 {
     char *tname;
     int vslot;
@@ -516,9 +534,9 @@ tape_access(filename, mode)
 }
 
 int
-tape_stat(filename, buf)
-    char *filename;
-    struct stat *buf;
+tape_stat(
+    char *filename,
+    struct stat *buf)
 {
     char *tname;
     int vslot;
@@ -528,21 +546,26 @@ tape_stat(filename, buf)
 }
 
 int
-tape_open(filename, mode, mask)
-    char *filename;
-    int mode;
-    int mask;
+tape_open(
+    char *filename,
+    int mode, ...)
 {
     char *tname;
     int vslot;
     int fd;
+    mode_t mask;
+    va_list ap;
+
+    va_start(ap, mode);
+    mask = (mode_t)va_arg(ap, int);
+    va_end(ap);
 
     vslot = name2slot(filename, &tname);
     if((fd = vtable[vslot].xxx_tape_open(tname, mode, mask)) >= 0) {
-       amtable_alloc((void **)&tape_info,
+       amtable_alloc((void **)tape_info_p,
                      &tape_info_count,
-                     sizeof(*tape_info),
-                     fd + 1,
+                     SIZEOF(*tape_info),
+                     (size_t)(fd + 1),
                      10,
                      tape_info_init);
        /*
@@ -558,193 +581,198 @@ tape_open(filename, mode, mask)
 }
 
 int
-tapefd_close(fd)
-    int fd;
+tapefd_close(
+    int fd)
 {
-    int vslot, res = -1;
+    int        res;
+    int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || ((vslot = tape_info[fd].vtape_index) < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     if((res = vtable[vslot].xxx_tapefd_close(fd)) == 0) {
        amfree(tape_info[fd].host);
        amfree(tape_info[fd].disk);
        amfree(tape_info[fd].datestamp);
        amfree(tape_info[fd].tapetype);
-       memset(tape_info + fd, 0, sizeof(*tape_info));
+       memset(tape_info + fd, 0, SIZEOF(*tape_info));
         tape_info_init((void *)(tape_info + fd));
     }
     return res;
 }
 
 int
-tapefd_can_fork(fd)
-    int fd;
+tapefd_can_fork(
+    int fd)
 {
-    int vslot, res = -1;
+    int        vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
-    res = vtable[vslot].xxx_tapefd_can_fork(fd);
 
-    return res;
+    vslot = tape_info[fd].vtape_index;
+    return vtable[vslot].xxx_tapefd_can_fork(fd);
 }
 
 int
-tapefd_fsf(fd, count)
-    int fd;
-    int count;
+tapefd_fsf(
+    int fd,
+    off_t count)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_fsf(fd, count);
 }
 
 int
-tapefd_rewind(fd)
-    int fd;
+tapefd_rewind(
+    int fd)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_rewind(fd);
 }
 
 void
-tapefd_resetofs(fd)
-    int fd;
+tapefd_resetofs(
+    int fd)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;                          /* not that it matters */
        return;
     }
+
+    vslot = tape_info[fd].vtape_index;
     vtable[vslot].xxx_tapefd_resetofs(fd);
 }
 
 int
-tapefd_unload(fd)
-    int fd;
+tapefd_unload(
+    int fd)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_unload(fd);
 }
 
 int
-tapefd_status(fd, stat)
-    int fd;
-    struct am_mt_status *stat;
+tapefd_status(
+    int fd,
+    struct am_mt_status *stat)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_status(fd, stat);
 }
 
 int
-tapefd_weof(fd, count)
-    int fd;
-    int count;
+tapefd_weof(
+    int fd,
+    off_t count)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_weof(fd, count);
-}
+} 
+
 
 ssize_t
-tapefd_read(fd, buffer, count)
-    int fd;
-    void *buffer;
-    size_t count;
+tapefd_read(
+    int fd,
+    void *buffer,
+    size_t count)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_read(fd, buffer, count);
 }
 
 ssize_t
-tapefd_write(fd, buffer, count)
-    int fd;
-    const void *buffer;
-    size_t count;
+tapefd_write(
+    int fd,
+    const void *buffer,
+    size_t count)
 {
     int vslot;
 
-    if(fd < 0
-       || fd >= tape_info_count
-       || (vslot = tape_info[fd].vtape_index) < 0) {
+    if ((fd < 0) || ((size_t)fd >= tape_info_count)
+       || (tape_info[fd].vtape_index < 0)) {
        errno = EBADF;
        return -1;
     }
+
+    vslot = tape_info[fd].vtape_index;
     return vtable[vslot].xxx_tapefd_write(fd, buffer, count);
 }
 
 char *
-tape_rewind(devname)
-    char *devname;
+tape_rewind(
+    char *devname)
 {
     int fd;
     char *r = NULL;
 
     if((fd = tape_open(devname, O_RDONLY)) < 0) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_rewind: tape open: ",
-                                 devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+       r = errstr = newvstrallocf(errstr,
+                                 _("tape_rewind: tape open: %s: %s"),
+                                 devname, strerror(errno));
     } else if(tapefd_rewind(fd) == -1) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_rewind: rewinding tape: ",
+       r = errstr = newvstrallocf(errstr,
+                                 _("tape_rewind: rewinding tape: %s: %s"),
                                  devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+                                 strerror(errno));
     }
     if(fd >= 0) {
        tapefd_close(fd);
@@ -753,26 +781,22 @@ tape_rewind(devname)
 }
 
 char *
-tape_unload(devname)
-    char *devname;
+tape_unload(
+    char *devname)
 {
     int fd;
     char *r = NULL;
 
     if((fd = tape_open(devname, O_RDONLY)) < 0) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_unload: tape open: ",
+       r = errstr = newvstrallocf(errstr,
+                                 _("tape_unload: tape open: %s: %s"),
                                  devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+                                 strerror(errno));
     } else if(tapefd_unload(fd) == -1) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_unload: unloading tape: ",
+       r = errstr = newvstrallocf(errstr,
+                                 _("tape_unload: unloading tape: %s: %s"),
                                  devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+                                 strerror(errno));
     }
     if(fd >= 0) {
        tapefd_close(fd);
@@ -781,30 +805,24 @@ tape_unload(devname)
 }
 
 char *
-tape_fsf(devname, count)
-    char *devname;
-    int count;
+tape_fsf(
+    char *devname,
+    off_t count)
 {
     int fd;
-    char count_str[NUM_STR_SIZE];
     char *r = NULL;
 
     if((fd = tape_open(devname, O_RDONLY)) < 0) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_fsf: tape open: ",
+       r = errstr = newvstrallocf(errstr,
+                                 _("tape_fsf: tape open: %s: %s"),
                                  devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+                                 strerror(errno));
     } else if(tapefd_fsf(fd, count) == -1) {
-       ap_snprintf(count_str, sizeof(count_str), "%d", count);
-       r = errstr = newvstralloc(errstr,
-                                 "tape_fsf: fsf ",
-                                 count_str,
-                                 "file", (count == 1) ? "" : "s",
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
+       r = errstr = newvstrallocf(errstr,
+                                 plural(_("tape_fsf: fsf %lld file: %s"),
+                                        _("tape_fsf: fsf %lld files: %s"),
+                                        count),
+                                 (long long)count, strerror(errno));
     }
     if(fd >= 0) {
        tapefd_close(fd);
@@ -812,13 +830,17 @@ tape_fsf(devname, count)
     return r;
 }
 
+/* Reads the tape label, like you expect. If failure, returns an error
+   string. If the tape might not be an Amanda tape, the returned
+   string will start with NOT_AMANDA_TAPE_MSG. */
+
 char *
-tapefd_rdlabel(fd, datestamp, label)
-    int fd;
-    char **datestamp;
-    char **label;
+tapefd_rdlabel(
+    int fd,
+    char **datestamp,
+    char **label)
 {
-    int rc;
+    ssize_t rc;
     size_t buflen;
     char *buffer = NULL;
     dumpfile_t file;
@@ -826,90 +848,95 @@ tapefd_rdlabel(fd, datestamp, label)
 
     amfree(*datestamp);
     amfree(*label);
-    buflen = MAX_TAPE_BLOCK_BYTES;
+    buflen = getconf_readblocksize() * 1024;
     buffer = alloc(buflen + 1);
 
     if(tapefd_getinfo_fake_label(fd)) {
        *datestamp = stralloc("X");
        *label = stralloc(FAKE_LABEL);
     } else if(tapefd_rewind(fd) == -1) {
-       r = errstr = newstralloc2(errstr, "rewinding tape: ", strerror(errno));
+       r = vstrallocf(_("rewinding tape: %s"), strerror(errno));
     } else if((rc = tapefd_read(fd, buffer, buflen)) == -1) {
-       r = errstr = newstralloc2(errstr, "reading label: ", strerror(errno));
+       r = vstrallocf(_(NOT_AMANDA_TAPE_MSG "(%s)"), strerror(errno));
+    } else if (rc == 0) {
+        r = vstrallocf(_(NOT_AMANDA_TAPE_MSG " (Read 0 bytes)"));
     } else {
-
        /* make sure buffer is null-terminated */
        buffer[rc] = '\0';
 
-       parse_file_header(buffer, &file, rc);
+       parse_file_header(buffer, &file, (size_t)rc);
        if(file.type != F_TAPESTART) {
-           r = errstr = newstralloc(errstr, "not an amanda tape");
+           r = vstrallocf(NOT_AMANDA_TAPE_MSG);
        } else {
            *datestamp = stralloc(file.datestamp);
            *label = stralloc(file.name);
        }
     }
     amfree(buffer);
+    if (r)
+       errstr = newvstrallocf(errstr, "%s", r);
     return r;
 }
 
 char *
-tape_rdlabel(devname, datestamp, label)
-    char *devname;
-    char **datestamp;
-    char **label;
+tape_rdlabel(
+    char *devname,
+    char **datestamp,
+    char **label)
 {
     int fd;
     char *r = NULL;
 
     if((fd = tape_open(devname, O_RDONLY)) < 0) {
-       r = errstr = newvstralloc(errstr,
-                                 "tape_rdlabel: tape open: ",
-                                 devname,
-                                 ": ",
-                                 strerror(errno),
-                                 NULL);
-    } else if(tapefd_rdlabel(fd, datestamp, label) != NULL) {
-       r = errstr;
-    }
+       r = vstrallocf(_("tape_rdlabel: tape open: %s: %s"),
+                      devname,
+                      strerror(errno));
+    } else
+        r = tapefd_rdlabel(fd, datestamp, label);
+
     if(fd >= 0) {
-       tapefd_close(fd);
+        tapefd_close(fd);
     }
+    if (r)
+       errstr = newvstrallocf(errstr, "%s", r);
     return r;
 }
 
 char *
-tapefd_wrlabel(fd, datestamp, label, size)
-    int fd;
-    char *datestamp;
-    char *label;
-    unsigned int size;
+tapefd_wrlabel(
+    int fd,
+    char *datestamp,
+    char *label,
+    size_t size)
 {
-    int rc;
+    ssize_t rc;
     char *buffer = NULL;
     dumpfile_t file;
     char *r = NULL;
 
     if(tapefd_rewind(fd) == -1) {
-       r = errstr = newstralloc2(errstr, "rewinding tape: ", strerror(errno));
+       r = errstr = newvstrallocf(errstr, _("rewinding tape: %s"),
+                       strerror(errno));
     } else {
        fh_init(&file);
        file.type = F_TAPESTART;
-       strncpy(file.datestamp, datestamp, sizeof(file.datestamp) - 1);
-       file.datestamp[sizeof(file.datestamp) - 1] = '\0';
-       strncpy(file.name, label, sizeof(file.name) - 1);
-       file.name[sizeof(file.name) - 1] = '\0';
-       buffer = alloc(size);
+       strncpy(file.datestamp, datestamp, SIZEOF(file.datestamp) - 1);
+       file.datestamp[SIZEOF(file.datestamp) - 1] = '\0';
+       strncpy(file.name, label, SIZEOF(file.name) - 1);
+       file.name[SIZEOF(file.name) - 1] = '\0';
        file.blocksize = size;
-       build_header(buffer, &file, size);
+        buffer = build_header(&file, size);
        tapefd_setinfo_host(fd, NULL);
        tapefd_setinfo_disk(fd, label);
        tapefd_setinfo_level(fd, -1);
-       if((rc = tapefd_write(fd, buffer, size)) != size) {
-           r = errstr = newstralloc2(errstr,
-                                     "writing label: ",
-                                     (rc != -1) ? "short write"
-                                                : strerror(errno));
+       if((rc = tapefd_write(fd, buffer, size)) != (ssize_t)size) {
+           if (rc != 1) {
+               r = errstr = newvstrallocf(errstr,
+                               _("writing label: short write"));
+           } else {
+               r = errstr = newvstrallocf(errstr,
+                               _("writing label: %s"), strerror(errno));
+           }
        }
        amfree(buffer);
     }
@@ -917,20 +944,23 @@ tapefd_wrlabel(fd, datestamp, label, size)
 }
 
 char *
-tape_wrlabel(devname, datestamp, label, size)
-    char *devname;
-    char *datestamp;
-    char *label;
-    unsigned int size;
+tape_wrlabel(
+    char *devname,
+    char *datestamp,
+    char *label,
+    size_t size)
 {
     int fd;
     char *r = NULL;
 
     if((fd = tape_open(devname, O_WRONLY)) < 0) {
-       r = errstr = newstralloc2(errstr,
-                                 "writing label: ",
-                                 (errno == EACCES) ? "tape is write-protected"
-                                                   : strerror(errno));
+       if (errno == EACCES) {
+           r = errstr = newvstrallocf(errstr,
+                                 _("writing label: tape is write-protected"));
+       } else {
+           r = errstr = newvstrallocf(errstr,
+                                 _("writing label: %s"), strerror(errno));
+       }
     } else if(tapefd_wrlabel(fd, datestamp, label, size) != NULL) {
        r = errstr;
     }
@@ -941,30 +971,34 @@ tape_wrlabel(devname, datestamp, label, size)
 }
 
 char *
-tapefd_wrendmark(fd, datestamp, size)
-    int fd;
-    char *datestamp;
-    unsigned int size;
+tapefd_wrendmark(
+    int fd,
+    char *datestamp,
+    size_t size)
 {
-    int rc;
+    ssize_t rc;
     char *buffer = NULL;
     dumpfile_t file;
     char *r = NULL;
 
     fh_init(&file);
     file.type = F_TAPEEND;
-    strncpy(file.datestamp, datestamp, sizeof(file.datestamp) - 1);
-    file.datestamp[sizeof(file.datestamp) - 1] = '\0';
-    buffer = alloc(size);
+    strncpy(file.datestamp, datestamp, SIZEOF(file.datestamp) - 1);
+    file.datestamp[SIZEOF(file.datestamp) - 1] = '\0';
     file.blocksize = size;
-    build_header(buffer, &file, size);
+    buffer = build_header(&file, size);
     tapefd_setinfo_host(fd, NULL);
     tapefd_setinfo_disk(fd, "TAPEEND");
     tapefd_setinfo_level(fd, -1);
 
-    if((rc = tapefd_write(fd, buffer, size)) != size) {
-       r = errstr = newstralloc2(errstr, "writing endmark: ",
-                                 (rc != -1) ? "short write" : strerror(errno));
+    if((rc = tapefd_write(fd, buffer, size)) != (ssize_t)size) {
+       if (rc != 1) {
+           r = errstr = newvstrallocf(errstr,
+                               _("writing endmark: short write"));
+       } else {
+           r = errstr = newvstrallocf(errstr,
+                               _("writing endmark: %s"), strerror(errno));
+       }
     }
     amfree(buffer);
 
@@ -972,19 +1006,22 @@ tapefd_wrendmark(fd, datestamp, size)
 }
 
 char *
-tape_wrendmark(devname, datestamp, size)
-    char *devname;
-    char *datestamp;
-    unsigned int size;
+tape_wrendmark(
+    char *devname,
+    char *datestamp,
+    size_t size)
 {
     int fd;
     char *r = NULL;
 
     if((fd = tape_open(devname, O_WRONLY)) < 0) {
-       r = errstr = newstralloc2(errstr,
-                                 "writing endmark: ",
-                                 (errno == EACCES) ? "tape is write-protected"
-                                                   : strerror(errno));
+       if (errno == EACCES) {
+           r = errstr = newvstrallocf(errstr,
+                                 _("writing endmark: tape is write-protected"));
+       } else {
+           r = errstr = newvstrallocf(errstr,
+                                 _("writing endmark: %s"), strerror(errno));
+       }
     } else if(tapefd_wrendmark(fd, datestamp, size) != NULL) {
        r = errstr;
     }
@@ -995,8 +1032,8 @@ tape_wrendmark(devname, datestamp, size)
 }
 
 char *
-tape_writable(devname)
-    char *devname;
+tape_writable(
+    char *devname)
 {
     int fd = -1;
     char *r = NULL;
@@ -1004,11 +1041,13 @@ tape_writable(devname)
     /* first, make sure the file exists and the permissions are right */
 
     if(tape_access(devname, R_OK|W_OK) == -1) {
-       r = errstr = newstralloc(errstr, strerror(errno));
+       r = errstr = newvstrallocf(errstr, "%s", strerror(errno));
     } else if((fd = tape_open(devname, O_WRONLY)) < 0) {
-       r = errstr = newstralloc(errstr,
-                                (errno == EACCES) ? "tape write-protected"
-                                                  : strerror(errno));
+       if (errno == EACCES) {
+           r = errstr = newvstrallocf(errstr, _("tape is write-protected"));
+       } else {
+           r = errstr = newvstrallocf(errstr, "%s", strerror(errno));
+       }
     }
     if(fd >= 0) {
        tapefd_close(fd);
@@ -1016,6 +1055,24 @@ tape_writable(devname)
     return r;
 }
 
+ssize_t
+getconf_readblocksize(void)
+{
+    tapetype_t *tape;
+    char       *conf_tapetype;
+
+    conf_tapetype = getconf_str(CNF_TAPETYPE);
+
+    if (!conf_tapetype || strlen(conf_tapetype) == 0)
+       return MAX_TAPE_BLOCK_KB;
+
+    tape = lookup_tapetype(conf_tapetype);
+    if (!tape)
+       return MAX_TAPE_BLOCK_KB;
+
+    return tapetype_get_readblocksize(tape);
+}
+
 #ifdef TEST
 
 /*
@@ -1038,22 +1095,22 @@ tape_writable(devname)
 static char *pgm;
 
 static void
-do_help()
+do_help(void)
 {
-    fprintf(stderr, "  ?|help\n");
-    fprintf(stderr, "  open [\"file\"|$TAPE [\"mode\":O_RDONLY]]\n");
-    fprintf(stderr, "  read [\"records\":\"all\"]\n");
-    fprintf(stderr, "  write [\"records\":1] [\"file#\":\"+\"] [\"record#\":\"+\"] [\"host\"] [\"disk\"] [\"level\"]\n");
-    fprintf(stderr, "  eof|weof [\"count\":1]\n");
-    fprintf(stderr, "  fsf [\"count\":1]\n");
-    fprintf(stderr, "  rewind\n");
-    fprintf(stderr, "  unload\n");
+    g_fprintf(stderr, _("  ?|help\n"));
+    g_fprintf(stderr, _("  open [\"file\"|$TAPE [\"mode\":O_RDONLY]]\n"));
+    g_fprintf(stderr, _("  read [\"records\":\"all\"]\n"));
+    g_fprintf(stderr, _("  write [\"records\":1] [\"file#\":\"+\"] [\"record#\":\"+\"] [\"host\"] [\"disk\"] [\"level\"]\n"));
+    g_fprintf(stderr, _("  eof|weof [\"count\":1]\n"));
+    g_fprintf(stderr, _("  fsf [\"count\":1]\n"));
+    g_fprintf(stderr, _("  rewind\n"));
+    g_fprintf(stderr, _("  unload\n"));
 }
 
 static void
-usage()
+usage(void)
 {
-    fprintf(stderr, "usage: %s [-c cmd [args] [%% cmd [args] ...]]\n", pgm);
+    g_fprintf(stderr, _("usage: %s [-c cmd [args] [%% cmd [args] ...]]\n"), pgm);
     do_help();
 }
 
@@ -1068,26 +1125,26 @@ static char **token;
 static int token_count;
 
 static int fd = -1;
-static int current_file = 0;
-static int current_record = 0;
+static off_t current_file = (off_t)0;
+static off_t current_record = (off_t)0;
 
 static int have_length = 0;
-static int length = 0;
+static int length = (off_t)0;
 
 static int show_timestamp = 0;
 
 char write_buf[TEST_BLOCKSIZE];
 
 static void
-do_open()
+do_open(void)
 {
-    int mode;
+    mode_t mode;
     char *file;
 
     if(token_count < 2
        || (token_count >= 2 && strcmp(token[1], "$TAPE") == 0)) {
        if((file = getenv("TAPE")) == NULL) {
-           fprintf(stderr, "tape_open: no file name and $TAPE not set\n");
+           g_fprintf(stderr, _("tape_open: no file name and $TAPE not set\n"));
            return;
        }
     } else {
@@ -1099,11 +1156,11 @@ do_open()
        mode = O_RDONLY;
     }
 
-    fprintf(stderr, "tapefd_open(\"%s\", %d): ", file, mode);
+    g_fprintf(stderr, _("tapefd_open(\"%s\", %d): "), file, mode);
     if((fd = tape_open(file, mode, 0644)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", fd);
+       g_fprintf(stderr, _("%d (OK)\n"), fd);
        if(have_length) {
            tapefd_setinfo_length(fd, length);
        }
@@ -1111,44 +1168,44 @@ do_open()
 }
 
 static void
-do_close()
+do_close(void)
 {
-    int result;
+    int        result;
 
-    fprintf(stderr, "tapefd_close(): ");
+    g_fprintf(stderr, _("tapefd_close(): "));
     if((result = tapefd_close(fd)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", result);
+       g_fprintf(stderr, _("%d (OK)\n"), result);
     }
 }
 
 static void
-do_read()
+do_read(void)
 {
-    int result;
-    int count = 0;
+    ssize_t    result;
+    off_t count = (off_t)0;
     int have_count = 0;
-    char buf[sizeof(write_buf)];
+    char buf[SIZEOF(write_buf)];
     int *p;
-    int i;
+    off_t i;
     char *s;
     time_t then;
     struct tm *tm;
 
     if(token_count > 1 && strcmp(token[1], "all") != 0) {
-       count = atoi(token[1]);
+       count = OFF_T_ATOI(token[1]);
        have_count = 1;
     }
 
     p = (int *)buf;
     for(i = 0; (! have_count) || (i < count); i++) {
-       fprintf(stderr, "tapefd_read(%d): ", i);
-       if((result = tapefd_read(fd, buf, sizeof(buf))) < 0) {
+       g_fprintf(stderr, _("tapefd_read(%lld): "), (long long)i);
+       if((result = tapefd_read(fd, buf, SIZEOF(buf))) < 0) {
            perror("");
            break;
        } else if(result == 0) {
-           fprintf(stderr, "%d (EOF)\n", result);
+           g_fprintf(stderr,  _("%zd (EOF)\n"), result);
            /*
             * If we were not given a count, EOF breaks the loop, otherwise
             * we keep trying (to test read after EOF handling).
@@ -1157,10 +1214,10 @@ do_read()
                break;
            }
        } else {
-           if(result == sizeof(buf)) {
-               s = "OK";
+           if(result == (ssize_t)sizeof(buf)) {
+               s = _("OK");
            } else {
-               s = "short read";
+               s = _("short read");
            }
 
            /*
@@ -1169,8 +1226,8 @@ do_read()
             * well screwed up at this point anyway so it is not worth
             * the effort to deal with.
             */
-           fprintf(stderr,
-                   "%d (%s): file %d: record %d",
+           g_fprintf(stderr,
+                   _("%zd (%s): file %d: record %d"),
                    result,
                    s,
                    p[0],
@@ -1178,7 +1235,7 @@ do_read()
            if(show_timestamp) {
                then = p[2];
                tm = localtime(&then);
-               fprintf(stderr,
+               g_fprintf(stderr,
                        ": %04d/%02d/%02d %02d:%02d:%02d\n",
                        tm->tm_year + 1900,
                        tm->tm_mon + 1,
@@ -1193,28 +1250,28 @@ do_read()
 }
 
 static void
-do_write()
+do_write(void)
 {
-    int result;
-    int count;
-    int *p;
-    int i;
+    int        result;
+    off_t count;
+    off_t *p;
+    off_t i;
     char *s;
     time_t now;
     struct tm *tm;
 
     if(token_count > 1) {
-       count = atoi(token[1]);
+       count = OFF_T_ATOI(token[1]);
     } else {
-       count = 1;
+       count = (off_t)1;
     }
 
     if(token_count > 2 && strcmp(token[2], "+") != 0) {
-       current_file = atoi(token[2]);
+       current_file = OFF_T_ATOI(token[2]);
     }
 
     if(token_count > 3 && strcmp(token[3], "+") != 0) {
-       current_record = atoi(token[3]);
+       current_record = OFF_T_ATOI(token[3]);
     }
 
     if(token_count > 4 && token[4][0] != '\0') {
@@ -1229,31 +1286,31 @@ do_write()
        tapefd_setinfo_level(fd, atoi(token[6]));
     }
 
-    p = (int *)write_buf;
+    p = (off_t *)write_buf;
     time(&now);
     p[2] = now;
     tm = localtime(&now);
-    for(i = 0; i < count; i++, current_record++) {
+    for(i = 0; i < count; i++, (current_record += (off_t)1)) {
        p[0] = current_file;
        p[1] = current_record;
-       fprintf(stderr, "tapefd_write(%d): ", i);
-       if((result = tapefd_write(fd, write_buf, sizeof(write_buf))) < 0) {
+       g_fprintf(stderr, _("tapefd_write(%lld): "), i);
+       if((result = tapefd_write(fd, write_buf, SIZEOF(write_buf))) < 0) {
            perror("");
            break;
        } else {
-           if(result == sizeof(write_buf)) {
-               s = "OK";
+           if(result == (ssize_t)sizeof(write_buf)) {
+               s = _("OK");
            } else {
-               s = "short write";
+               s = _("short write");
            }
-           fprintf(stderr,
-                   "%d (%s): file %d: record %d",
+           g_fprintf(stderr,
+                   _("%d (%s): file %lld: record %lld"),
                    result,
                    s,
                    p[0],
                    p[1]);
            if(show_timestamp) {
-               fprintf(stderr,
+               g_fprintf(stderr,
                        ": %04d/%02d/%02d %02d:%02d:%02d\n",
                        tm->tm_year + 1900,
                        tm->tm_mon + 1,
@@ -1268,83 +1325,83 @@ do_write()
 }
 
 static void
-do_fsf()
+do_fsf(void)
 {
-    int result;
-    int count;
+    int        result;
+    off_t count;
 
     if(token_count > 1) {
-       count = atoi(token[1]);
+       count = OFF_T_ATOI(token[1]);
     } else {
-       count = 1;
+       count = (off_t)1;
     }
 
-    fprintf(stderr, "tapefd_fsf(%d): ", count);
+    g_fprintf(stderr, _("tapefd_fsf(%lld): "), (long long)count);
     if((result = tapefd_fsf(fd, count)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", result);
+       g_fprintf(stderr, _("%d (OK)\n"), result);
        current_file += count;
-       current_record = 0;
+       current_record = (off_t)0;
     }
 }
 
 static void
-do_weof()
+do_weof(void)
 {
-    int result;
-    int count;
+    int        result;
+    off_t count;
 
     if(token_count > 1) {
-       count = atoi(token[1]);
+       count = OFF_T_ATOI(token[1]);
     } else {
-       count = 1;
+       count = (off_t)1;
     }
 
-    fprintf(stderr, "tapefd_weof(%d): ", count);
+    g_fprintf(stderr, _("tapefd_weof(%lld): "), count);
     if((result = tapefd_weof(fd, count)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", result);
+       g_fprintf(stderr, _("%d (OK)\n"), result);
        current_file += count;
-       current_record = 0;
+       current_record = (off_t)0;
     }
 }
 
 static void
-do_rewind()
+do_rewind(void)
 {
-    int result;
+    int        result;
 
-    fprintf(stderr, "tapefd_rewind(): ");
+    g_fprintf(stderr, _("tapefd_rewind(): "));
     if((result = tapefd_rewind(fd)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", result);
-       current_file = 0;
-       current_record = 0;
+       g_fprintf(stderr, _("%d (OK)\n"), result);
+       current_file = (off_t)0;
+       current_record = (off_t)0;
     }
 }
 
 static void
-do_unload()
+do_unload(void)
 {
-    int result;
+    int        result;
 
-    fprintf(stderr, "tapefd_unload(): ");
+    g_fprintf(stderr, _("tapefd_unload(): "));
     if((result = tapefd_unload(fd)) < 0) {
        perror("");
     } else {
-       fprintf(stderr, "%d (OK)\n", result);
-       current_file = -1;
-       current_record = -1;
+       g_fprintf(stderr, _("%d (OK)\n"), result);
+       current_file = (off_t)-1;
+       current_record = (off_t)-1;
     }
 }
 
 struct cmd {
     char *name;
     int min_chars;
-    void (*func)();
+    void (*func)(void);
 } cmd[] = {
     { "?",             0,      do_help },
     { "help",          0,      do_help },
@@ -1361,9 +1418,9 @@ struct cmd {
 };
 
 int
-main(argc, argv)
-    int argc;
-    char **argv;
+main(
+    int                argc,
+    char **    argv)
 {
     int ch;
     int cmdline = 0;
@@ -1373,6 +1430,18 @@ main(argc, argv)
     int j;
     time_t now;
 
+    /*
+     * Configure program for internationalization:
+     *   1) Only set the message locale for now.
+     *   2) Set textdomain for all amanda related programs to "amanda"
+     *      We don't want to be forced to support dozens of message catalogs.
+     */  
+    setlocale(LC_MESSAGES, "C");
+    textdomain("amanda"); 
+
+    /* Don't die when child closes pipe */
+    signal(SIGPIPE, SIG_IGN);
+
     if((pgm = strrchr(argv[0], '/')) != NULL) {
        pgm++;
     } else {
@@ -1410,17 +1479,17 @@ main(argc, argv)
            break;
        case 'l':
            have_length = 1;
-           length = atoi(optarg);
+           length = OFF_T_ATOI(optarg);
            j = strlen(optarg);
            if(j > 0) {
                switch(optarg[j-1] ) {
                case 'k':                               break;
-               case 'b': length /= 2;                  break;
-               case 'M': length *= 1024;               break;
-               default:  length /= 1024;               break;
+               case 'b': length /= (off_t)2;           break;
+               case 'M': length *= (off_t)1024;        break;
+               default:  length /= (off_t)1024;        break;
                }
            } else {
-               length /= 1024;
+               length /= (off_t)1024;
            }
            break;
        case 't':
@@ -1438,7 +1507,7 @@ main(argc, argv)
      */
     time(&now);
     srandom(now);
-    for(j = 0; j < sizeof(write_buf); j++) {
+    for(j = 0; j < (int)SIZEOF(write_buf); j++) {
        write_buf[j] = (char)random();
     }
 
@@ -1450,7 +1519,7 @@ main(argc, argv)
     while(1) {
        if(cmdline) {
            for(token_count = 1;
-               token_count < (sizeof(token_area) / sizeof(token_area[0]))
+               token_count < (int)(SIZEOF(token_area) / SIZEOF(token_area[0]))
                && optind < argc;
                token_count++, optind++) {
                if(strcmp(argv[optind], "%") == 0) {
@@ -1476,7 +1545,7 @@ main(argc, argv)
            }
            token_count = split(line,
                                token_area,
-                               sizeof(token_area) / sizeof(token_area[0]),
+                               SIZEOF(token_area) / SIZEOF(token_area[0]),
                                " ");
        }
        amfree(line);
@@ -1506,7 +1575,7 @@ main(argc, argv)
            }
        }
        if(cmd[i].name == NULL) {
-           fprintf(stderr, "%s: unknown command: %s\n", pgm, token[0]);
+           g_fprintf(stderr, _("%s: unknown command: %s\n"), pgm, token[0]);
            exit(1);
        }
        (*cmd[i].func)();