Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/bin/pax/options.c,v rcsdiff: /ftp/cvs/cvsroot/src/bin/pax/options.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.98.6.1 retrieving revision 1.99 diff -u -p -r1.98.6.1 -r1.99 --- src/bin/pax/options.c 2009/08/25 18:11:15 1.98.6.1 +++ src/bin/pax/options.c 2007/01/16 19:06:41 1.99 @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.98.6.1 2009/08/25 18:11:15 snj Exp $ */ +/* $NetBSD: options.c,v 1.99 2007/01/16 19:06:41 cbiere Exp $ */ /*- * Copyright (c) 1992 Keith Muller. @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -__RCSID("$NetBSD: options.c,v 1.98.6.1 2009/08/25 18:11:15 snj Exp $"); +__RCSID("$NetBSD: options.c,v 1.99 2007/01/16 19:06:41 cbiere Exp $"); #endif #endif /* not lint */ @@ -85,7 +85,7 @@ static int no_op(void); static void printflg(unsigned int); static int c_frmt(const void *, const void *); static off_t str_offt(char *); -static char *get_line(FILE *fp); +static char *getline(FILE *fp); static void pax_options(int, char **); static void pax_usage(void); static void tar_options(int, char **); @@ -95,10 +95,10 @@ static void cpio_options(int, char **); static void cpio_usage(void); #endif -/* errors from get_line */ +/* errors from getline */ #define GETLINE_FILE_CORRUPT 1 #define GETLINE_OUT_OF_MEM 2 -static int get_line_error; +static int getline_error; #define BZIP2_CMD "bzip2" /* command to run as bzip2 */ #define GZIP_CMD "gzip" /* command to run as gzip */ @@ -816,6 +816,14 @@ struct option tar_longopts[] = { }; static void +tar_set_action(int op) +{ + if (act != ERROR && act != op) + tar_usage(); + act = op; +} + +static void tar_options(int argc, char **argv) { int c; @@ -857,7 +865,7 @@ tar_options(int argc, char **argv) /* * create an archive */ - act = ARCHIVE; + tar_set_action(ARCHIVE); break; case 'e': /* @@ -954,7 +962,7 @@ tar_options(int argc, char **argv) /* * append to the archive */ - act = APPND; + tar_set_action(APPND); break; case 's': /* @@ -969,7 +977,7 @@ tar_options(int argc, char **argv) /* * list contents of the tape */ - act = LIST; + tar_set_action(LIST); break; case 'v': /* @@ -988,7 +996,7 @@ tar_options(int argc, char **argv) * extract an archive, preserving mode, * and mtime if possible. */ - act = EXTRACT; + tar_set_action(EXTRACT); pmtime = 1; break; case 'z': @@ -1183,7 +1191,7 @@ tar_options(int argc, char **argv) tty_warn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = get_line(fp)) != NULL) { + while ((str = getline(fp)) != NULL) { if (dirisnext) { if (dir) free(dir); @@ -1216,7 +1224,7 @@ tar_options(int argc, char **argv) free(dir); if (strcmp(file, "-") != 0) fclose(fp); - if (get_line_error) { + if (getline_error) { tty_warn(1, "Problem with file '%s'", file); tar_usage(); } @@ -1286,7 +1294,7 @@ tar_options(int argc, char **argv) tty_warn(1, "Unable to open file '%s' for read", file); tar_usage(); } - while ((str = get_line(fp)) != NULL) { + while ((str = getline(fp)) != NULL) { if (dirisnext) { if (ftree_add(str, 1) < 0) tar_usage(); @@ -1310,7 +1318,7 @@ tar_options(int argc, char **argv) tar_usage(); if (strcmp(file, "-") != 0) fclose(fp); - if (get_line_error) { + if (getline_error) { tty_warn(1, "Problem with file '%s'", file); tar_usage(); @@ -1419,6 +1427,17 @@ struct option cpio_longopts[] = { { 0, 0, 0, 0 }, }; +static void +cpio_set_action(int op) +{ + if ((act == APPND && op == ARCHIVE) || (act == ARCHIVE && op == APPND)) + act = APPND; + else if (act != ERROR && act != op) + cpio_usage(); + else + act = op; +} + /* * cpio_options() * look at the user specified flags. set globals as required and check if @@ -1488,7 +1507,7 @@ cpio_options(int argc, char **argv) /* * read the archive */ - act = EXTRACT; + cpio_set_action(EXTRACT); flg |= RF; break; #ifdef notyet @@ -1513,7 +1532,7 @@ cpio_options(int argc, char **argv) /* * write an archive */ - act = ARCHIVE; + cpio_set_action(ARCHIVE); frmt = &(fsub[F_SV4CRC]); flg |= WF; break; @@ -1521,7 +1540,7 @@ cpio_options(int argc, char **argv) /* * cpio -p is like pax -rw */ - act = COPY; + cpio_set_action(COPY); flg |= RF | WF; break; case 'r': @@ -1542,7 +1561,7 @@ cpio_options(int argc, char **argv) /* * list contents of archive */ - act = LIST; + cpio_set_action(LIST); listf = stdout; flg &= ~RF; break; @@ -1571,7 +1590,7 @@ cpio_options(int argc, char **argv) /* * append to an archive */ - act = APPND; + cpio_set_action(APPND); flg |= AF; break; case 'B': @@ -1598,11 +1617,11 @@ cpio_options(int argc, char **argv) optarg); cpio_usage(); } - while ((str = get_line(fp)) != NULL) { + while ((str = getline(fp)) != NULL) { pat_add(str, NULL); } fclose(fp); - if (get_line_error) { + if (getline_error) { tty_warn(1, "Problem with file '%s'", optarg); cpio_usage(); } @@ -1754,10 +1773,10 @@ cpio_options(int argc, char **argv) * no read errors allowed on updates/append operation! */ maxflt = 0; - while ((str = get_line(stdin)) != NULL) { + while ((str = getline(stdin)) != NULL) { ftree_add(str, 0); } - if (get_line_error) { + if (getline_error) { tty_warn(1, "Problem while reading stdin"); cpio_usage(); } @@ -1985,21 +2004,21 @@ str_offt(char *val) } char * -get_line(FILE *f) +getline(FILE *f) { char *name, *temp; size_t len; name = fgetln(f, &len); if (!name) { - get_line_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; + getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0; return 0; } if (name[len-1] != '\n') len++; temp = malloc(len); if (!temp) { - get_line_error = GETLINE_OUT_OF_MEM; + getline_error = GETLINE_OUT_OF_MEM; return 0; } memcpy(temp, name, len-1);