diff -Nur pax-3.3-doc/src/ar_io.c pax-3.3-gcc/src/ar_io.c --- pax-3.3-doc/src/ar_io.c 2003-02-03 19:06:42.000000000 +1000 +++ pax-3.3-gcc/src/ar_io.c 2003-04-22 15:15:50.000000000 +1000 @@ -388,11 +388,7 @@ * could have written anything yet. */ if (frmt == NULL) { -# ifdef LONG_OFF_T - (void)fprintf(listf, "%s: unknown format, %lu bytes skipped.\n", -# else - (void)fprintf(listf, "%s: unknown format, %qu bytes skipped.\n", -# endif + (void)fprintf(listf, "%s: unknown format, %" FMT_OFF "u bytes skipped.\n", argv0, rdcnt); (void)fflush(listf); flcnt = 0; @@ -400,14 +396,10 @@ } if (strcmp(NM_CPIO, argv0) == 0) - (void)fprintf(listf, "%qu blocks\n", (rdcnt ? rdcnt : wrcnt) / 5120); + (void)fprintf(listf, "%" FMT_OFF "u blocks\n", (rdcnt ? rdcnt : wrcnt) / 5120); else if (strcmp(NM_TAR, argv0) != 0) (void)fprintf(listf, -# ifdef LONG_OFF_T - "%s: %s vol %d, %lu files, %lu bytes read, %lu bytes written.\n", -# else - "%s: %s vol %d, %lu files, %qu bytes read, %qu bytes written.\n", -# endif + "%s: %s vol %d, %lu files, %" FMT_OFF "u bytes read, %" FMT_OFF "u bytes written.\n", argv0, frmt->name, arvol-1, flcnt, rdcnt, wrcnt); (void)fflush(listf); flcnt = 0; diff -Nur pax-3.3-doc/src/ar_subs.c pax-3.3-gcc/src/ar_subs.c --- pax-3.3-doc/src/ar_subs.c 2003-02-03 19:06:43.000000000 +1000 +++ pax-3.3-gcc/src/ar_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -57,6 +57,7 @@ #include #include #include +#include #include "pax.h" #include "extern.h" diff -Nur pax-3.3-doc/src/cpio.c pax-3.3-gcc/src/cpio.c --- pax-3.3-doc/src/cpio.c 2003-02-03 19:06:43.000000000 +1000 +++ pax-3.3-gcc/src/cpio.c 2003-04-22 15:15:50.000000000 +1000 @@ -223,13 +223,8 @@ */ if ((arcn->sb.st_size == 0) || (arcn->sb.st_size >= sizeof(arcn->ln_name))) { -# ifdef LONG_OFF_T - paxwarn(1, "Cpio link name length is invalid: %lu", - arcn->sb.st_size); -# else - paxwarn(1, "Cpio link name length is invalid: %qu", + paxwarn(1, "Cpio link name length is invalid: %" FMT_OFF "u", arcn->sb.st_size); -# endif return(-1); } diff -Nur pax-3.3-doc/src/extern.h pax-3.3-gcc/src/extern.h --- pax-3.3-doc/src/extern.h 2002-10-19 01:38:11.000000000 +1000 +++ pax-3.3-gcc/src/extern.h 2003-04-22 15:15:50.000000000 +1000 @@ -302,3 +302,12 @@ int tty_read(char *, int); void paxwarn(int, const char *, ...); void syswarn(int, int, const char *, ...); + +/* + * Handle printing of offsets. + */ +#ifdef LONG_OFF_T +#define FMT_OFF "l" +#else +#define FMT_OFF "q" +#endif diff -Nur pax-3.3-doc/src/gen_subs.c pax-3.3-gcc/src/gen_subs.c --- pax-3.3-doc/src/gen_subs.c 2002-10-17 05:20:02.000000000 +1000 +++ pax-3.3-gcc/src/gen_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -56,6 +56,7 @@ #include #include #include +#include #include #include "pax.h" #include "extern.h" @@ -128,19 +129,11 @@ * print device id's for devices, or sizes for other nodes */ if ((arcn->type == PAX_CHR) || (arcn->type == PAX_BLK)) -# ifdef LONG_OFF_T - (void)fprintf(fp, "%4u,%4u ", MAJOR(sbp->st_rdev), -# else - (void)fprintf(fp, "%4lu,%4lu ", (unsigned long)MAJOR(sbp->st_rdev), -# endif + (void)fprintf(fp, "%4lu,%4lu ", + (unsigned long)MAJOR(sbp->st_rdev), (unsigned long)MINOR(sbp->st_rdev)); - else { -# ifdef LONG_OFF_T - (void)fprintf(fp, "%9lu ", sbp->st_size); -# else - (void)fprintf(fp, "%9qu ", sbp->st_size); -# endif - } + else + (void)fprintf(fp, "%9" FMT_OFF "u ", sbp->st_size); /* * print name and link info for hard and soft links diff -Nur pax-3.3-doc/src/options.c pax-3.3-gcc/src/options.c --- pax-3.3-doc/src/options.c 2003-02-03 19:06:43.000000000 +1000 +++ pax-3.3-gcc/src/options.c 2003-04-22 15:15:50.000000000 +1000 @@ -76,7 +76,7 @@ static void printflg(unsigned int); static int c_frmt(const void *, const void *); static off_t str_offt(char *); -static char *getline(FILE *fp); +static char *getln(FILE *fp); static void pax_options(int, char **); static void pax_usage(void); static void tar_options(int, char **); @@ -87,7 +87,7 @@ /* errors from getline */ #define GETLINE_FILE_CORRUPT 1 #define GETLINE_OUT_OF_MEM 2 -static int getline_error; +static int getln_error; #define GZIP_CMD "gzip" /* command to run as gzip */ @@ -520,6 +520,7 @@ * or list. check that we have not been given a bogus set of flags * for the operation mode. */ + listf = stderr; if (ISLIST(flg)) { act = LIST; listf = stdout; @@ -870,14 +871,14 @@ paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = getln(fp)) != NULL) { if (pat_add(str, dir) < 0) tar_usage(); sawpat = 1; } if (strcmp(file, "-") != 0) fclose(fp); - if (getline_error) { + if (getln_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); } @@ -943,13 +944,13 @@ paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = getln(fp)) != NULL) { if (ftree_add(str, 0) < 0) tar_usage(); } if (strcmp(file, "-") != 0) fclose(fp); - if (getline_error) { + if (getln_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); @@ -1030,6 +1031,7 @@ dflag = 1; act = -1; nodirs = 1; + listf = stderr; while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1) switch (c) { case 'a': @@ -1156,11 +1158,11 @@ paxwarn(1, "Unable to open file '%s' for read", optarg); cpio_usage(); } - while ((str = getline(fp)) != NULL) { + while ((str = getln(fp)) != NULL) { pat_add(str, NULL); } fclose(fp); - if (getline_error) { + if (getln_error) { paxwarn(1, "Problem with file '%s'", optarg); cpio_usage(); } @@ -1255,10 +1257,10 @@ * no read errors allowed on updates/append operation! */ maxflt = 0; - while ((str = getline(stdin)) != NULL) { + while ((str = getln(stdin)) != NULL) { ftree_add(str, NULL); } - if (getline_error) { + if (getln_error) { paxwarn(1, "Problem while reading stdin"); cpio_usage(); } @@ -1483,29 +1485,40 @@ return(num); } +/* + * getln() + * read a line and return it in a malloc'ed buffer. + * + * In pax 3.0 this was called my_getline(). somewhere + * between 3.0 and 3.3 it was replaced with a function + * called getline() that did the same thing as my_getline() + * but used fgetln(). fgetln() is not a GNU function - its + * only available on BSD, and that made life difficult. + * Very difficult in fact, as the easiy way to emulate + * fgetln() is to use the GNU getline() function, buts its + * name clashed with the one defined here. This third + * re-write is shorter and faster than the previous two, + * and is compatible with GNU libc. + */ char * -getline(FILE *f) +getln(FILE * f) { - char *name, *temp; + char *name = 0; + size_t buflen = 0; size_t len; - name = fgetln(f, &len); - if (!name) { - getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; + len = getline(&name, &buflen, f); + if (len == (size_t)-1) { + if (name) + free(name); + getln_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; return(0); } - if (name[len-1] != '\n') - len++; - temp = malloc(len); - if (!temp) { - getline_error = GETLINE_OUT_OF_MEM; - return(0); - } - memcpy(temp, name, len-1); - temp[len-1] = 0; - return(temp); + if (name[len - 1] == '\n') + name[len - 1] = '\0'; + return name; } - + /* * no_op() * for those option functions where the archive format has nothing to do. diff -Nur pax-3.3-doc/src/pax.c pax-3.3-gcc/src/pax.c --- pax-3.3-doc/src/pax.c 2002-10-17 05:20:02.000000000 +1000 +++ pax-3.3-gcc/src/pax.c 2003-04-22 15:15:50.000000000 +1000 @@ -108,7 +108,7 @@ char *ltmfrmt; /* -v locale time format (if any) */ char *argv0; /* root of argv[0] */ sigset_t s_mask; /* signal mask for cleanup critical sect */ -FILE *listf = stderr; /* file pointer to print file list to */ +FILE *listf; /* file pointer to print file list to */ char *tempfile; /* tempfile to use for mkstemp(3) */ char *tempbase; /* basename of tempfile to use for mkstemp(3) */ diff -Nur pax-3.3-doc/src/sel_subs.c pax-3.3-gcc/src/sel_subs.c --- pax-3.3-doc/src/sel_subs.c 2002-10-17 05:20:02.000000000 +1000 +++ pax-3.3-gcc/src/sel_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include "pax.h"