]>
git.cameronkatri.com Git - apple_cmds.git/blob - file_cmds/pax/options.c
1 /* $OpenBSD: options.c,v 1.70 2008/06/11 00:49:08 pvalchev Exp $ */
2 /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
5 * Copyright (c) 1992 Keith Muller.
6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved.
9 * This code is derived from software contributed to Berkeley by
10 * Keith Muller of the University of California, San Diego.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
40 static const char sccsid
[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
42 __used
static const char rcsid
[] = "$OpenBSD: options.c,v 1.70 2008/06/11 00:49:08 pvalchev Exp $";
46 #include <sys/types.h>
52 #endif /* __APPLE__ */
53 #include <sys/param.h>
71 * Routines which handle command line options
74 static char flgch
[] = FLGCH
; /* list of all possible flags */
75 static OPLIST
*ophead
= NULL
; /* head for format specific options -x */
76 static OPLIST
*optail
= NULL
; /* option tail */
78 static int no_op(void);
79 static void printflg(unsigned int);
80 static int c_frmt(const void *, const void *);
81 static off_t
str_offt(char *);
82 static char *pax_getline(FILE *fp
);
83 static void pax_options(int, char **);
85 static void tar_options(int, char **);
86 static void tar_usage(void);
87 static void cpio_options(int, char **);
88 static void cpio_usage(void);
90 /* errors from getline */
91 #define GETLINE_FILE_CORRUPT 1
92 #define GETLINE_OUT_OF_MEM 2
93 static int getline_error
;
96 #define GZIP_CMD "gzip" /* command to run as gzip */
97 #define COMPRESS_CMD "compress" /* command to run as compress */
98 #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
101 * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
102 * (see pax.h for description of each function)
104 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
105 * read, end_read, st_write, write, end_write, trail,
106 * rd_data, wr_data, options
109 const FSUB fsub
[] = {
110 /* OLD BINARY CPIO */
111 {"bcpio", 5120, sizeof(HD_BCPIO
), 1, 0, 0, 1, bcpio_id
, cpio_strd
,
112 bcpio_rd
, bcpio_endrd
, cpio_stwr
, bcpio_wr
, cpio_endwr
, cpio_trail
,
113 rd_wrfile
, wr_rdfile
, bad_opt
},
115 /* OLD OCTAL CHARACTER CPIO */
116 {"cpio", 5120, sizeof(HD_CPIO
), 1, 0, 0, 1, cpio_id
, cpio_strd
,
117 cpio_rd
, cpio_endrd
, cpio_stwr
, cpio_wr
, cpio_endwr
, cpio_trail
,
118 rd_wrfile
, wr_rdfile
, bad_opt
},
121 {"pax", 5120, BLKMULT
, 0, 1, BLKMULT
, 0, pax_id
, ustar_strd
,
122 pax_rd
, tar_endrd
, ustar_stwr
, pax_wr
, tar_endwr
, tar_trail
,
123 rd_wrfile
, wr_rdfile
, pax_opt
},
126 {"sv4cpio", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, vcpio_id
, cpio_strd
,
127 vcpio_rd
, vcpio_endrd
, cpio_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
128 rd_wrfile
, wr_rdfile
, bad_opt
},
130 /* SVR4 HEX CPIO WITH CRC */
131 {"sv4crc", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, crc_id
, crc_strd
,
132 vcpio_rd
, vcpio_endrd
, crc_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
133 rd_wrfile
, wr_rdfile
, bad_opt
},
136 {"tar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, tar_id
, no_op
,
137 tar_rd
, tar_endrd
, no_op
, tar_wr
, tar_endwr
, tar_trail
,
138 rd_wrfile
, wr_rdfile
, tar_opt
},
141 {"ustar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, ustar_id
, ustar_strd
,
142 ustar_rd
, tar_endrd
, ustar_stwr
, ustar_wr
, tar_endwr
, tar_trail
,
143 rd_wrfile
, wr_rdfile
, bad_opt
},
145 #define F_OCPIO 0 /* format when called as cpio -6 */
146 #define F_ACPIO 1 /* format when called as cpio -c */
147 #define F_PAX 2 /* -x pax */
148 #define F_SCPIO 3 /* -x sv4cpio */
149 #define F_CPIO 4 /* format when called as cpio */
150 #define F_OTAR 5 /* format when called as tar -o */
151 #define F_TAR 6 /* format when called as tar */
152 #define DEFLT F_TAR /* default write format from list above */
155 * ford is the archive search order used by get_arc() to determine what kind
156 * of archive we are dealing with. This helps to properly id archive formats
157 * some formats may be subsets of others....
159 int ford
[] = {F_PAX
, F_TAR
, F_OTAR
, F_CPIO
, F_SCPIO
, F_ACPIO
, F_OCPIO
, -1 };
162 * Do we have -C anywhere?
168 * figure out if we are pax, tar or cpio. Call the appropriate options
173 options(int argc
, char **argv
)
177 * Are we acting like pax, tar or cpio (based on argv[0])
179 if ((argv0
= strrchr(argv
[0], '/')) != NULL
)
184 if (strcmp(NM_TAR
, argv0
) == 0) {
185 tar_options(argc
, argv
);
187 } else if (strcmp(NM_CPIO
, argv0
) == 0) {
188 cpio_options(argc
, argv
);
192 * assume pax as the default
195 pax_options(argc
, argv
);
198 #define OPT_INSECURE 1
199 struct option pax_longopts
[] = {
200 { "insecure", no_argument
, 0, OPT_INSECURE
},
206 * look at the user specified flags. set globals as required and check if
207 * the user specified a legal set of flags. If not, complain and exit
211 pax_options(int argc
, char **argv
)
215 unsigned int flg
= 0;
216 unsigned int bflg
= 0;
224 * process option flags
226 while ((c
=getopt_long(argc
,argv
,"0ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ", pax_longopts
, NULL
)) != -1) {
230 * Use \0 as pathname terminator.
231 * (For use with the -print0 option of find(1).)
247 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
248 paxwarn(1, "Invalid block size %s", optarg
);
254 * inverse match on patterns
261 * match only dir on extract, not the subtree at dir
268 * filename where the archive is stored
270 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
272 * treat a - as stdin (like tar)
282 * interactive file rename
289 * use bzip2. Non standard option.
291 gzip_program
= BZIP2_CMD
;
295 * do not clobber files that exist
302 * try to link src to dest with copy (-rw)
309 * select first match for a pattern only
316 * pass format specific options
319 if (pax_format_opt_add(optarg
) < 0)
324 * specify file characteristic options
326 for (pt
= optarg
; *pt
!= '\0'; ++pt
) {
330 * do not preserve access time
336 * preserve user id, group id, file
337 * mode, access/modification times
346 * do not preserve modification time
358 * preserve file mode bits
363 paxwarn(1, "Invalid -p string: %c", *pt
);
374 pax_read_or_list_mode
=1;
379 * file name substitution name pattern
381 if (rep_add(optarg
) < 0) {
389 * preserve access time on filesystem nodes we read
396 * ignore those older files
403 * verbose operation mode
416 * specify an archive format on write
419 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
420 if ((frmt
= (FSUB
*)bsearch(&tmp
, fsub
, n_fsub
, sizeof(FSUB
),
425 paxwarn(1, "Unknown -x format: %s", optarg
);
426 (void)fputs("pax: Known -x formats are:", stderr
);
427 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
428 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
429 (void)fputs("\n\n", stderr
);
434 * use gzip. Non standard option.
436 gzip_program
= GZIP_CMD
;
440 * non-standard option on number of bytes written on a
441 * single archive volume.
443 if ((wrlimit
= str_offt(optarg
)) <= 0) {
444 paxwarn(1, "Invalid write limit %s", optarg
);
447 if (wrlimit
% BLKMULT
) {
448 paxwarn(1, "Write limit is not a %d byte multiple",
456 * On extraction check file inode change time before the
457 * modification of the file name. Non standard option.
464 * non-standard limit on read faults
465 * 0 indicates stop after first error, values
466 * indicate a limit, "NONE" try forever
469 if (strcmp(NONE
, optarg
) == 0)
471 else if ((maxflt
= atoi(optarg
)) < 0) {
472 paxwarn(1, "Error count value must be positive");
478 * non-standard option for selecting files within an
479 * archive by group (gid or name)
481 if (grp_add(optarg
) < 0) {
489 * follow command line symlinks only
493 Lflag
= 0; /* -H and -L are mutually exclusive */
494 flg
&= ~CLF
; /* only use the last one seen */
502 Hflag
= 0; /* -H and -L are mutually exclusive */
503 flg
&= ~CHF
; /* only use the last one seen */
507 * Force one volume. Non standard option.
509 force_one_volume
= 1;
513 * do NOT follow symlinks (default)
520 * non-standard option for selecting files within an
521 * archive by modification time range (lower,upper)
523 if (trng_add(optarg
) < 0) {
531 * non-standard option for selecting files within an
532 * archive by user (uid or name)
534 if (usr_add(optarg
) < 0) {
542 * do not pass over mount points in the file system
549 * On extraction check file inode change time after the
550 * modification of the file name. Non standard option.
557 * On extraction check modification time after the
558 * modification of the file name. Non standard option.
573 * Fix for POSIX.cmd/pax/pax.ex test 132: force -wu options to look
574 * like -wua options were specified.
576 if (uflag
&& (flg
& WF
) && !(flg
& RF
)) { /* -w but not -r -w */
581 * figure out the operation mode of pax read,write,extract,copy,append
582 * or list. check that we have not been given a bogus set of flags
583 * for the operation mode.
587 pax_read_or_list_mode
=1;
590 } else if (ISEXTRACT(flg
)) {
593 } else if (ISARCHIVE(flg
)) {
596 } else if (ISAPPND(flg
)) {
599 } else if (ISCOPY(flg
)) {
610 * if we are writing (ARCHIVE) we use the default format if the user
611 * did not specify a format. when we write during an APPEND, we will
612 * adopt the format of the existing archive if none was supplied.
614 if (!(flg
& XF
) && (act
== ARCHIVE
))
615 frmt
= &(fsub
[DEFLT
]);
618 * if copying (-r and -w) and there is no -x specified, we act as
619 * if -x pax was specified.
621 if (!(flg
& XF
) && (act
== COPY
))
622 frmt
= &(fsub
[F_PAX
]);
625 * Initialize the global extended header template.
627 tmp_name
= getenv("TMPDIR");
629 asprintf(&header_name_g
, "%s%s", tmp_name
, "/GlobalHead.%p.%n");
631 header_name_g
= "/tmp/GlobalHead.%p.%n";
635 * process the args as they are interpreted by the operation mode
640 for (; optind
< argc
; optind
++)
641 if (pat_add(argv
[optind
], NULL
) < 0)
645 if (optind
>= argc
) {
646 paxwarn(0, "Destination directory was not supplied");
654 for (; optind
< argc
; optind
++)
655 if (ftree_add(argv
[optind
], 0) < 0)
658 * no read errors allowed on updates/append operation!
668 * look at the user specified flags. set globals as required and check if
669 * the user specified a legal set of flags. If not, complain and exit
673 tar_options(int argc
, char **argv
)
679 int incfiles_max
= 0;
684 struct incfile
*incfiles
= NULL
;
687 * Set default values.
692 * process option flags
694 while ((c
= getoldopt(argc
, argv
,
695 "b:cef:hjmopqruts:vwxzBC:HI:LOPXZ014578")) != -1) {
699 * specify blocksize in 512-byte blocks
701 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
702 paxwarn(1, "Invalid block size %s", optarg
);
705 wrblksz
*= 512; /* XXX - check for int oflow */
715 * stop after first error
721 * filename where the archive is stored
723 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
742 * use bzip2. Non standard option.
744 gzip_program
= BZIP2_CMD
;
748 * do not preserve modification time
760 * preserve uid/gid and file mode, regardless of umask
767 * select first match for a pattern only
774 * append to the archive
780 * file name substitution name pattern
782 if (rep_add(optarg
) < 0) {
789 * list contents of the tape
795 * verbose operation mode
801 * interactive file rename
807 * extract an archive, preserving mode,
808 * and mtime if possible.
815 * use gzip. Non standard option.
817 gzip_program
= GZIP_CMD
;
821 * Nothing to do here, this is pax default
830 * follow command line symlinks only
835 if (++nincfiles
> incfiles_max
) {
836 incfiles_max
= nincfiles
+ 3;
837 incfiles
= realloc(incfiles
,
838 sizeof(*incfiles
) * incfiles_max
);
839 if (incfiles
== NULL
) {
840 paxwarn(0, "Unable to allocate space "
845 incfiles
[nincfiles
- 1].file
= optarg
;
846 incfiles
[nincfiles
- 1].dir
= chdname
;
856 * do not remove leading '/' from pathnames
862 * do not pass over mount points in the file system
870 gzip_program
= COMPRESS_CMD
;
898 /* Traditional tar behaviour (pax uses stderr unless in list mode) */
899 if (fstdin
== 1 && act
== ARCHIVE
)
904 /* Traditional tar behaviour (pax wants to read file list from stdin) */
905 if ((act
== ARCHIVE
|| act
== APPND
) && argc
== 0 && nincfiles
== 0)
909 * process the args as they are interpreted by the operation mode
917 char *file
, *dir
= NULL
;
919 while (nincfiles
|| *argv
!= NULL
) {
921 * If we queued up any include files,
922 * pull them in now. Otherwise, check
923 * for -I and -C positional flags.
924 * Anything else must be a file to
928 file
= incfiles
->file
;
932 } else if (strcmp(*argv
, "-I") == 0) {
943 if (strcmp(file
, "-") == 0)
945 else if ((fp
= fopen(file
, "r")) == NULL
) {
946 paxwarn(1, "Unable to open file '%s' for read", file
);
949 while ((str
= pax_getline(fp
)) != NULL
) {
950 if (pat_add(str
, dir
) < 0)
954 if (strcmp(file
, "-") != 0)
957 paxwarn(1, "Problem with file '%s'", file
);
960 } else if (strcmp(*argv
, "-C") == 0) {
965 } else if (pat_add(*argv
++, chdname
) < 0)
971 * if patterns were added, we are doing chdir()
972 * on a file-by-file basis, else, just one
973 * global chdir (if any) after opening input.
981 frmt
= &(fsub
[Oflag
? F_OTAR
: F_TAR
]);
983 if (Oflag
== 2 && opt_add("write_opt=nodir") < 0)
986 if (chdname
!= NULL
) { /* initial chdir() */
987 if (ftree_add(chdname
, 1) < 0)
991 while (nincfiles
|| *argv
!= NULL
) {
992 char *file
, *dir
= NULL
;
995 * If we queued up any include files, pull them in
996 * now. Otherwise, check for -I and -C positional
997 * flags. Anything else must be a file to include
1001 file
= incfiles
->file
;
1002 dir
= incfiles
->dir
;
1005 } else if (strcmp(*argv
, "-I") == 0) {
1006 if (*++argv
== NULL
)
1016 /* Set directory if needed */
1018 if (ftree_add(dir
, 1) < 0)
1022 if (strcmp(file
, "-") == 0)
1024 else if ((fp
= fopen(file
, "r")) == NULL
) {
1025 paxwarn(1, "Unable to open file '%s' for read", file
);
1028 while ((str
= pax_getline(fp
)) != NULL
) {
1029 if (ftree_add(str
, 0) < 0)
1032 if (strcmp(file
, "-") != 0)
1034 if (getline_error
) {
1035 paxwarn(1, "Problem with file '%s'",
1039 } else if (strcmp(*argv
, "-C") == 0) {
1040 if (*++argv
== NULL
)
1042 if (ftree_add(*argv
++, 1) < 0)
1045 } else if (ftree_add(*argv
++, 0) < 0)
1049 * no read errors allowed on updates/append operation!
1054 if (!fstdin
&& ((arcname
== NULL
) || (*arcname
== '\0'))) {
1055 arcname
= getenv("TAPE");
1056 if ((arcname
== NULL
) || (*arcname
== '\0'))
1057 arcname
= _PATH_DEFTAPE
;
1074 slash
+= strspn(slash
, "/");
1075 slash
+= strcspn(slash
, "/");
1077 done
= (*slash
== '\0');
1080 if (stat(path
, &sb
)) {
1081 if (errno
!= ENOENT
|| mkdir(path
, 0777)) {
1082 paxwarn(1, "%s", path
);
1085 } else if (!S_ISDIR(sb
.st_mode
)) {
1086 syswarn(1, ENOTDIR
, "%s", path
);
1098 * look at the user specified flags. set globals as required and check if
1099 * the user specified a legal set of flags. If not, complain and exit
1103 cpio_options(int argc
, char **argv
)
1119 while ((c
=getopt(argc
,argv
,"abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
1123 * preserve access time on files read
1129 * swap bytes and half-words when reading data
1136 frmt
= &(fsub
[F_ACPIO
]);
1140 * create directories as needed
1146 * invert meaning of pattern list
1152 * restore an archive
1158 * use bzip2. Non standard option.
1160 gzip_program
= BZIP2_CMD
;
1166 * use links instead of copies when possible
1172 * preserve modification time
1181 frmt
= &(fsub
[F_CPIO
]);
1191 * interactively rename files
1197 * swap bytes after reading data
1202 * list contents of archive
1209 * replace newer files
1215 * verbose operation mode
1221 * use gzip. Non standard option.
1223 gzip_program
= GZIP_CMD
;
1233 * Use 5120 byte block size
1239 * set block size in bytes
1241 wrblksz
= atoi(optarg
);
1245 * file with patterns to extract or list
1247 if ((fp
= fopen(optarg
, "r")) == NULL
) {
1248 paxwarn(1, "Unable to open file '%s' for read", optarg
);
1251 while ((str
= pax_getline(fp
)) != NULL
) {
1255 if (getline_error
) {
1256 paxwarn(1, "Problem with file '%s'", optarg
);
1264 * filename where the archive is stored
1266 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
1268 * treat a - as stdin
1277 * specify an archive format on write
1280 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
1281 if ((frmt
= (FSUB
*)bsearch((void *)&tmp
, (void *)fsub
,
1282 n_fsub
, sizeof(FSUB
), c_frmt
)) != NULL
)
1284 paxwarn(1, "Unknown -H format: %s", optarg
);
1285 (void)fputs("cpio: Known -H formats are:", stderr
);
1286 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
1287 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
1288 (void)fputs("\n\n", stderr
);
1293 * follow symbolic links
1299 * swap halfwords after reading data
1304 * use compress. Non standard option.
1306 gzip_program
= COMPRESS_CMD
;
1310 * process Version 6 cpio format
1312 frmt
= &(fsub
[F_OCPIO
]);
1323 * process the args as they are interpreted by the operation mode
1328 while (*argv
!= NULL
)
1329 if (pat_add(*argv
++, NULL
) < 0)
1333 if (*argv
== NULL
) {
1334 paxwarn(0, "Destination directory was not supplied");
1338 if (mkpath(dirptr
) < 0)
1348 * no read errors allowed on updates/append operation!
1351 while ((str
= pax_getline(stdin
)) != NULL
) {
1354 if (getline_error
) {
1355 paxwarn(1, "Problem while reading stdin");
1367 * print out those invalid flag sets found to the user
1371 printflg(unsigned int flg
)
1376 (void)fprintf(stderr
,"%s: Invalid combination of options:", argv0
);
1377 while ((nxt
= ffs(flg
)) != 0) {
1380 (void)fprintf(stderr
, " -%c", flgch
[pos
-1]);
1382 (void)putc('\n', stderr
);
1387 * comparison routine used by bsearch to find the format specified
1392 c_frmt(const void *a
, const void *b
)
1394 return(strcmp(((const FSUB
*)a
)->name
, ((const FSUB
*)b
)->name
));
1399 * called by format specific options routines to get each format specific
1400 * flag and value specified with -o
1402 * pointer to next OPLIST entry or NULL (end of list).
1410 if ((opt
= ophead
) != NULL
)
1411 ophead
= ophead
->fow
;
1417 * generic routine used to complain about a format specific options
1418 * when the format does not support options.
1429 * print all we were given
1431 paxwarn(1,"These format options are not supported");
1432 while ((opt
= opt_next()) != NULL
) {
1433 if (opt
->separator
== SEP_EQ
) {
1434 (void)fprintf(stderr
, "\t%s = %s\n", opt
->name
, opt
->value
);
1435 } else if (opt
->separator
== SEP_COLONEQ
) {
1436 (void)fprintf(stderr
, "\t%s := %s\n", opt
->name
, opt
->value
);
1437 } else { /* SEP_NONE */
1438 (void)fprintf(stderr
, "\t%s\n", opt
->name
);
1447 * breaks the value supplied to -o into an option name and value. Options
1448 * are given to -o in the form -o name-value,name=value
1449 * multiple -o may be specified.
1451 * 0 if format in name=value format, -1 if -o is passed junk.
1455 opt_add(const char *str
)
1463 if ((str
== NULL
) || (*str
== '\0')) {
1464 paxwarn(0, "Invalid option name");
1467 if ((dstr
= strdup(str
)) == NULL
) {
1468 paxwarn(0, "Unable to allocate space for option list");
1474 * break into name and values pieces and stuff each one into a
1475 * OPLIST structure. When we know the format, the format specific
1476 * option function will go through this list
1478 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1479 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1481 if ((pt
= strchr(frpt
, '=')) == NULL
) {
1482 paxwarn(0, "Invalid options format");
1486 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1487 paxwarn(0, "Unable to allocate space for option list");
1494 opt
->separator
= SEP_EQ
;
1500 if (ophead
== NULL
) {
1501 optail
= ophead
= opt
;
1511 * pax_format_opt_add()
1512 * breaks the value supplied to -o into a option name and value. options
1513 * are given to -o in the form -o name-value,name=value
1514 * multiple -o may be specified.
1516 * 0 if format in name=value format, -1 if -o is passed junk
1520 pax_format_opt_add(register char *str
)
1522 register OPLIST
*opt
;
1523 register char *frpt
;
1525 register char *endpt
;
1526 register int separator
;
1528 if ((str
== NULL
) || (*str
== '\0')) {
1529 paxwarn(0, "Invalid option name");
1532 if ((str
= strdup(str
)) == NULL
) {
1533 paxwarn(0, "Unable to allocate space for option list");
1539 * break into name and values pieces and stuff each one into a
1540 * OPLIST structure. When we know the format, the format specific
1541 * option function will go through this list
1543 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1544 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1546 if ((pt
= strstr(frpt
, ":=")) != NULL
) {
1548 pt
++; /* beyond the := */
1549 separator
= SEP_COLONEQ
;
1550 } else if ((pt
= strchr(frpt
, '=')) != NULL
) {
1554 /* keyword with no value */
1555 separator
= SEP_NONE
;
1557 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1558 paxwarn(0, "Unable to allocate space for option list");
1564 opt
->separator
= separator
;
1570 if (ophead
== NULL
) {
1571 optail
= ophead
= opt
;
1582 * Convert an expression of the following forms to an off_t > 0.
1583 * 1) A positive decimal number.
1584 * 2) A positive decimal number followed by a b (mult by 512).
1585 * 3) A positive decimal number followed by a k (mult by 1024).
1586 * 4) A positive decimal number followed by a m (mult by 512).
1587 * 5) A positive decimal number followed by a w (mult by sizeof int)
1588 * 6) Two or more positive decimal numbers (with/without k,b or w).
1589 * separated by x (also * for backwards compatibility), specifying
1590 * the product of the indicated values.
1592 * 0 for an error, a positive value o.w.
1602 num
= strtol(val
, &expr
, 0);
1603 if ((num
== LONG_MAX
) || (num
<= 0) || (expr
== val
))
1605 num
= strtoq(val
, &expr
, 0);
1606 if ((num
== QUAD_MAX
) || (num
<= 0) || (expr
== val
))
1647 num
*= str_offt(expr
+ 1);
1658 pax_getline(FILE *f
)
1663 name
= fgetln(f
, &len
);
1665 getline_error
= ferror(f
) ? GETLINE_FILE_CORRUPT
: 0;
1668 if (name
[len
-1] != '\n')
1672 getline_error
= GETLINE_OUT_OF_MEM
;
1675 memcpy(temp
, name
, len
-1);
1682 * for those option functions where the archive format has nothing to do.
1695 * print the usage summary to the user
1702 "usage: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s replstr]\n"
1703 " [-T range] [-U user] [--insecure] [pattern ...]\n"
1704 " pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G group] [-o options]\n"
1705 " [-p string] [-s replstr] [-T range] [-U user] [--insecure] [pattern ...]\n"
1706 " pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1707 " [-G group] [-o options] [-s replstr] [-T range] [-U user]\n"
1708 " [-x format] [--insecure] [file ...]\n"
1709 " pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1710 " [-T range] [-U user] [--insecure] [file ...] directory\n",
1717 * print the usage summary to the user
1724 "usage: tar {crtux}[014578befHhjLmOoPpqsvwXZz]\n"
1725 " [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
1727 " tar {-crtux} [-014578eHhjLmOoPpqvwXZz] [-b blocking-factor]\n"
1728 " [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
1735 * print the usage summary to the user
1742 "usage: cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format]\n"
1743 " [-O archive] < name-list [> archive]\n"
1744 " cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]\n"
1745 " [-I archive] [pattern ...] [< archive]\n"
1746 " cpio -p [-adLlmuv] destination-directory < name-list\n",