1 /* $OpenBSD: options.c,v 1.101 2016/12/26 23:43:52 krw 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/types.h>
53 * argv[0] names. Used for tar and cpio emulation
57 #define NM_CPIO "cpio"
61 * Constants used to specify the legal sets of flags in pax. For each major
62 * operation mode of pax, a set of illegal flags is defined. If any one of
63 * those illegal flags are found set, we scream and exit
67 * flags (one for each option).
87 #define CBF 0x00040000 /* nonstandard extension */
88 #define CDF 0x00080000 /* nonstandard extension */
89 #define CEF 0x00100000 /* nonstandard extension */
90 #define CGF 0x00200000 /* nonstandard extension */
91 #define CHF 0x00400000 /* nonstandard extension */
92 #define CLF 0x00800000 /* nonstandard extension */
93 #define CPF 0x01000000 /* nonstandard extension */
94 #define CTF 0x02000000 /* nonstandard extension */
95 #define CUF 0x04000000 /* nonstandard extension */
96 #define CXF 0x08000000
97 #define CYF 0x10000000 /* nonstandard extension */
98 #define CZF 0x20000000 /* nonstandard extension */
99 #define C0F 0x40000000 /* nonstandard extension */
102 * ascii string indexed by bit position above (alter the above and you must
103 * alter this string) used to tell the user what flags caused us to complain
105 #define FLGCH "abcdfiklnoprstuvwxBDEGHLPTUXYZ0"
108 * legal pax operation bit patterns
111 #define ISLIST(x) (((x) & (RF|WF)) == 0)
112 #define ISEXTRACT(x) (((x) & (RF|WF)) == RF)
113 #define ISARCHIVE(x) (((x) & (AF|RF|WF)) == WF)
114 #define ISAPPND(x) (((x) & (AF|RF|WF)) == (AF|WF))
115 #define ISCOPY(x) (((x) & (RF|WF)) == (RF|WF))
116 #define ISWRITE(x) (((x) & (RF|WF)) == WF)
119 * Illegal option flag subsets based on pax operation
122 #define BDEXTR (AF|BF|LF|TF|WF|XF|CBF|CHF|CLF|CPF|CXF)
123 #define BDARCH (CF|KF|LF|NF|PF|RF|CDF|CEF|CYF|CZF)
124 #define BDCOPY (AF|BF|FF|OF|XF|CBF|CEF)
125 #define BDLIST (AF|BF|IF|KF|LF|OF|PF|RF|TF|UF|WF|XF|CBF|CDF|CHF|CLF|CPF|CXF|CYF|CZF)
129 * Routines which handle command line options
132 static char flgch
[] = FLGCH
; /* list of all possible flags */
133 static OPLIST
*ophead
= NULL
; /* head for format specific options -x */
134 static OPLIST
*optail
= NULL
; /* option tail */
136 static int no_op(void);
137 static void printflg(unsigned int);
138 static off_t
str_offt(char *);
139 static char *get_line(FILE *fp
);
140 static void pax_options(int, char **);
141 static void pax_usage(void);
142 static void tar_options(int, char **);
143 static void tar_usage(void);
145 static void cpio_options(int, char **);
146 static void cpio_usage(void);
149 static int compress_id(char *_blk
, int _size
);
150 static int gzip_id(char *_blk
, int _size
);
151 static int bzip2_id(char *_blk
, int _size
);
152 static int xz_id(char *_blk
, int _size
);
154 #define GZIP_CMD "gzip" /* command to run as gzip */
155 #define COMPRESS_CMD "compress" /* command to run as compress */
156 #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
159 * Format specific routine table
160 * (see pax.h for description of each function)
162 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
163 * read, end_read, st_write, write, end_write, trail,
164 * rd_data, wr_data, options
169 /* 0: OLD BINARY CPIO */
171 /* 1: OLD OCTAL CHARACTER CPIO */
173 /* 2: SVR4 HEX CPIO */
175 /* 3: SVR4 HEX CPIO WITH CRC */
178 /* 0: OLD BINARY CPIO */
179 {"bcpio", 5120, sizeof(HD_BCPIO
), 1, 0, 0, 1, bcpio_id
, cpio_strd
,
180 bcpio_rd
, bcpio_endrd
, cpio_stwr
, bcpio_wr
, cpio_endwr
, cpio_trail
,
183 /* 1: OLD OCTAL CHARACTER CPIO */
184 {"cpio", 5120, sizeof(HD_CPIO
), 1, 0, 0, 1, cpio_id
, cpio_strd
,
185 cpio_rd
, cpio_endrd
, cpio_stwr
, cpio_wr
, cpio_endwr
, cpio_trail
,
188 /* 2: SVR4 HEX CPIO */
189 {"sv4cpio", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, vcpio_id
, cpio_strd
,
190 vcpio_rd
, vcpio_endrd
, cpio_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
193 /* 3: SVR4 HEX CPIO WITH CRC */
194 {"sv4crc", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, crc_id
, crc_strd
,
195 vcpio_rd
, vcpio_endrd
, crc_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
199 {"tar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, tar_id
, no_op
,
200 tar_rd
, tar_endrd
, no_op
, tar_wr
, tar_endwr
, tar_trail
,
204 {"ustar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, ustar_id
, ustar_strd
,
205 ustar_rd
, tar_endrd
, no_op
, ustar_wr
, tar_endwr
, tar_trail
,
209 /* 6: compress, to detect failure to use -Z */
211 /* 7: xz, to detect failure to decompress it */
213 /* 8: bzip2, to detect failure to use -j */
215 /* 9: gzip, to detect failure to use -z */
218 /* 6: compress, to detect failure to use -Z */
219 {NULL
, 0, 4, 0, 0, 0, 0, compress_id
},
220 /* 7: xz, to detect failure to decompress it */
221 {NULL
, 0, 4, 0, 0, 0, 0, xz_id
},
222 /* 8: bzip2, to detect failure to use -j */
223 {NULL
, 0, 4, 0, 0, 0, 0, bzip2_id
},
224 /* 9: gzip, to detect failure to use -z */
225 {NULL
, 0, 4, 0, 0, 0, 0, gzip_id
},
228 #define F_OCPIO 0 /* format when called as cpio -6 */
229 #define F_ACPIO 1 /* format when called as cpio -c */
230 #define F_CPIO 3 /* format when called as cpio */
231 #define F_OTAR 4 /* format when called as tar -o */
232 #define F_TAR 5 /* format when called as tar */
233 #define DEFLT 5 /* default write format from list above */
236 * ford is the archive search order used by get_arc() to determine what kind
237 * of archive we are dealing with. This helps to properly id archive formats
238 * some formats may be subsets of others....
240 int ford
[] = {5, 4, 9, 8, 7, 6, 3, 2, 1, 0, -1};
243 * Do we have -C anywhere and what is it?
246 char *chdname
= NULL
;
250 * figure out if we are pax, tar or cpio. Call the appropriate options
255 options(int argc
, char **argv
)
257 extern char *__progname
;
260 * Are we acting like pax, tar or cpio (based on argv[0])
264 if (strcmp(NM_TAR
, argv0
) == 0) {
266 tar_options(argc
, argv
);
270 else if (strcmp(NM_CPIO
, argv0
) == 0) {
272 cpio_options(argc
, argv
);
277 * assume pax as the default
281 pax_options(argc
, argv
);
286 * look at the user specified flags. set globals as required and check if
287 * the user specified a legal set of flags. If not, complain and exit
291 pax_options(int argc
, char **argv
)
295 unsigned int flg
= 0;
296 unsigned int bflg
= 0;
301 * process option flags
303 while ((c
=getopt(argc
,argv
,"ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0"))
317 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
318 paxwarn(1, "Invalid block size %s", optarg
);
324 * inverse match on patterns
331 * match only dir on extract, not the subtree at dir
338 * filename where the archive is stored
345 * interactive file rename
352 * use bzip2. Non standard option.
354 gzip_program
= BZIP2_CMD
;
358 * do not clobber files that exist
365 * try to link src to dest with copy (-rw)
372 * select first match for a pattern only
379 * pass format specific options
382 if (opt_add(optarg
) < 0)
387 * specify file characteristic options
389 for (pt
= optarg
; *pt
!= '\0'; ++pt
) {
393 * do not preserve access time
399 * preserve user id, group id, file
400 * mode, access/modification times
409 * do not preserve modification time
421 * preserve file mode bits
426 paxwarn(1, "Invalid -p string: %c", *pt
);
441 * file name substitution name pattern
443 if (rep_add(optarg
) < 0) {
451 * preserve access time on filesystem nodes we read
458 * ignore those older files
465 * verbose operation mode
478 * specify an archive format on write
480 for (i
= 0; i
< sizeof(fsub
)/sizeof(FSUB
); ++i
)
481 if (fsub
[i
].name
!= NULL
&&
482 strcmp(fsub
[i
].name
, optarg
) == 0)
484 if (i
< sizeof(fsub
)/sizeof(FSUB
)) {
489 paxwarn(1, "Unknown -x format: %s", optarg
);
490 (void)fputs("pax: Known -x formats are:", stderr
);
491 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
492 if (fsub
[i
].name
!= NULL
)
493 (void)fprintf(stderr
, " %s",
495 (void)fputs("\n\n", stderr
);
500 * use gzip. Non standard option.
502 gzip_program
= GZIP_CMD
;
506 * non-standard option on number of bytes written on a
507 * single archive volume.
509 if ((wrlimit
= str_offt(optarg
)) <= 0) {
510 paxwarn(1, "Invalid write limit %s", optarg
);
513 if (wrlimit
% BLKMULT
) {
514 paxwarn(1, "Write limit is not a %d byte multiple",
522 * On extraction check file inode change time before the
523 * modification of the file name. Non standard option.
530 * non-standard limit on read faults
531 * 0 indicates stop after first error, values
535 maxflt
= strtonum(optarg
, 0, INT_MAX
, &errstr
);
537 paxwarn(1, "Error count value: %s", errstr
);
543 * non-standard option for selecting files within an
544 * archive by group (gid or name)
546 if (grp_add(optarg
) < 0) {
554 * follow command line symlinks only
568 * Force one volume. Non standard option.
570 force_one_volume
= 1;
574 * do NOT follow symlinks (default)
581 * non-standard option for selecting files within an
582 * archive by modification time range (lower,upper)
584 if (trng_add(optarg
) < 0) {
592 * non-standard option for selecting files within an
593 * archive by user (uid or name)
595 if (usr_add(optarg
) < 0) {
603 * do not pass over mount points in the file system
610 * On extraction check file inode change time after the
611 * modification of the file name. Non standard option.
618 * On extraction check modification time after the
619 * modification of the file name. Non standard option.
626 * Use \0 as pathname terminator.
627 * (For use with the -print0 option of find(1).)
639 * figure out the operation mode of pax read,write,extract,copy,append
640 * or list. check that we have not been given a bogus set of flags
641 * for the operation mode.
647 } else if (ISEXTRACT(flg
)) {
650 } else if (ISARCHIVE(flg
)) {
653 } else if (ISAPPND(flg
)) {
656 } else if (ISCOPY(flg
)) {
667 * if we are writing (ARCHIVE) we use the default format if the user
668 * did not specify a format. when we write during an APPEND, we will
669 * adopt the format of the existing archive if none was supplied.
671 if (!(flg
& XF
) && (act
== ARCHIVE
))
672 frmt
= &(fsub
[DEFLT
]);
675 * process the args as they are interpreted by the operation mode
680 for (; optind
< argc
; optind
++)
681 if (pat_add(argv
[optind
], NULL
) < 0)
685 if (optind
>= argc
) {
686 paxwarn(0, "Destination directory was not supplied");
694 for (; optind
< argc
; optind
++)
695 if (ftree_add(argv
[optind
], 0) < 0)
698 * no read errors allowed on updates/append operation!
708 * look at the user specified flags. set globals as required and check if
709 * the user specified a legal set of flags. If not, complain and exit
713 tar_options(int argc
, char **argv
)
718 int incfiles_max
= 0;
723 struct incfile
*incfiles
= NULL
;
726 * Set default values.
731 * process option flags
733 while ((c
= getoldopt(argc
, argv
,
734 "b:cef:hjmopqruts:vwxzBC:HI:LNOPXZ014578")) != -1) {
738 * specify blocksize in 512-byte blocks
740 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
741 paxwarn(1, "Invalid block size %s", optarg
);
744 wrblksz
*= 512; /* XXX - check for int oflow */
754 * stop after first error
760 * filename where the archive is stored
772 * use bzip2. Non standard option.
774 gzip_program
= BZIP2_CMD
;
778 * do not preserve modification time
791 * preserve uid/gid and file mode, regardless of umask
798 * select first match for a pattern only
805 * append to the archive
811 * file name substitution name pattern
813 if (rep_add(optarg
) < 0) {
820 * list contents of the tape
826 * verbose operation mode
832 * interactive file rename
838 * extract an archive, preserving mode,
839 * and mtime if possible.
846 * use gzip. Non standard option.
848 gzip_program
= GZIP_CMD
;
852 * Nothing to do here, this is pax default
861 * follow command line symlinks only
866 if (++nincfiles
> incfiles_max
) {
867 size_t n
= nincfiles
+ 3;
870 p
= reallocarray(incfiles
, n
,
873 paxwarn(0, "Unable to allocate space "
880 incfiles
[nincfiles
- 1].file
= optarg
;
881 incfiles
[nincfiles
- 1].dir
= chdname
;
890 /* numeric uid and gid only */
895 * do not remove leading '/' from pathnames
901 * do not pass over mount points in the file system
909 gzip_program
= COMPRESS_CMD
;
937 if ((arcname
== NULL
) || (*arcname
== '\0')) {
938 arcname
= getenv("TAPE");
939 if ((arcname
== NULL
) || (*arcname
== '\0'))
940 arcname
= _PATH_DEFTAPE
;
942 if ((arcname
[0] == '-') && (arcname
[1]== '\0'))
946 * Traditional tar behaviour: list-like output goes to stdout unless
947 * writing the archive there. (pax uses stderr unless in list mode)
949 if (act
== LIST
|| act
== EXTRACT
|| arcname
!= NULL
)
952 /* Traditional tar behaviour (pax wants to read file list from stdin) */
953 if ((act
== ARCHIVE
|| act
== APPND
) && argc
== 0 && nincfiles
== 0)
957 * process the args as they are interpreted by the operation mode
967 while (nincfiles
|| *argv
!= NULL
) {
969 * If we queued up any include files,
970 * pull them in now. Otherwise, check
971 * for -I and -C positional flags.
972 * Anything else must be a file to
976 file
= incfiles
->file
;
980 } else if (strcmp(*argv
, "-I") == 0) {
991 if (strcmp(file
, "-") == 0)
993 else if ((fp
= fopen(file
, "r")) == NULL
) {
995 "Unable to open %s", file
);
998 while ((str
= get_line(fp
)) != NULL
) {
999 if (pat_add(str
, dir
) < 0)
1005 "Unable to read from %s",
1006 strcmp(file
, "-") ? file
:
1010 if (strcmp(file
, "-") != 0)
1012 } else if (strcmp(*argv
, "-C") == 0) {
1013 if (*++argv
== NULL
)
1017 } else if (pat_add(*argv
++, chdname
) < 0)
1023 * if patterns were added, we are doing chdir()
1024 * on a file-by-file basis, else, just one
1025 * global chdir (if any) after opening input.
1033 frmt
= &(fsub
[Oflag
? F_OTAR
: F_TAR
]);
1035 if (chdname
!= NULL
) { /* initial chdir() */
1036 if (ftree_add(chdname
, 1) < 0)
1040 while (nincfiles
|| *argv
!= NULL
) {
1044 * If we queued up any include files, pull them in
1045 * now. Otherwise, check for -I and -C positional
1046 * flags. Anything else must be a file to include
1050 file
= incfiles
->file
;
1051 dir
= incfiles
->dir
;
1054 } else if (strcmp(*argv
, "-I") == 0) {
1055 if (*++argv
== NULL
)
1065 /* Set directory if needed */
1067 if (ftree_add(dir
, 1) < 0)
1071 if (strcmp(file
, "-") == 0)
1073 else if ((fp
= fopen(file
, "r")) == NULL
) {
1074 syswarn(1, errno
, "Unable to open %s",
1078 while ((str
= get_line(fp
)) != NULL
) {
1079 if (ftree_add(str
, 0) < 0)
1084 "Unable to read from %s",
1085 strcmp(file
, "-") ? file
: "stdin");
1088 if (strcmp(file
, "-") != 0)
1090 } else if (strcmp(*argv
, "-C") == 0) {
1091 if (*++argv
== NULL
)
1093 if (ftree_add(*argv
++, 1) < 0)
1096 } else if (ftree_add(*argv
++, 0) < 0)
1100 * no read errors allowed on updates/append operation!
1120 slash
+= strspn(slash
, "/");
1121 slash
+= strcspn(slash
, "/");
1123 done
= (*slash
== '\0');
1126 if (stat(path
, &sb
)) {
1127 if (errno
!= ENOENT
|| mkdir(path
, 0777)) {
1128 paxwarn(1, "%s", path
);
1131 } else if (!S_ISDIR(sb
.st_mode
)) {
1132 syswarn(1, ENOTDIR
, "%s", path
);
1146 * look at the user specified flags. set globals as required and check if
1147 * the user specified a legal set of flags. If not, complain and exit
1151 cpio_options(int argc
, char **argv
)
1154 int c
, list_only
= 0;
1167 while ((c
=getopt(argc
,argv
,"abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
1171 * preserve access time on files read
1177 * swap bytes and half-words when reading data
1184 frmt
= &(fsub
[F_ACPIO
]);
1188 * create directories as needed
1194 * invert meaning of pattern list
1200 * restore an archive
1206 * use bzip2. Non standard option.
1208 gzip_program
= BZIP2_CMD
;
1214 * use links instead of copies when possible
1220 * preserve modification time
1229 frmt
= &(fsub
[F_CPIO
]);
1239 * interactively rename files
1245 * swap bytes after reading data
1250 * list contents of archive
1256 * replace newer files
1262 * verbose operation mode
1268 * use gzip. Non standard option.
1270 gzip_program
= GZIP_CMD
;
1280 * Use 5120 byte block size
1286 * set block size in bytes
1288 wrblksz
= strtonum(optarg
, 0, INT_MAX
, &errstr
);
1290 paxwarn(1, "Invalid block size %s: %s",
1297 * file with patterns to extract or list
1299 if ((fp
= fopen(optarg
, "r")) == NULL
) {
1300 syswarn(1, errno
, "Unable to open %s",
1304 while ((str
= get_line(fp
)) != NULL
) {
1309 "Unable to read from %s", optarg
);
1318 * filename where the archive is stored
1320 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
1322 * treat a - as stdin
1331 * specify an archive format on write
1333 for (i
= 0; i
< sizeof(fsub
)/sizeof(FSUB
); ++i
)
1334 if (fsub
[i
].name
!= NULL
&&
1335 strcmp(fsub
[i
].name
, optarg
) == 0)
1337 if (i
< sizeof(fsub
)/sizeof(FSUB
)) {
1341 paxwarn(1, "Unknown -H format: %s", optarg
);
1342 (void)fputs("cpio: Known -H formats are:", stderr
);
1343 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
1344 if (fsub
[i
].name
!= NULL
)
1345 (void)fprintf(stderr
, " %s",
1347 (void)fputs("\n\n", stderr
);
1352 * follow symbolic links
1358 * swap halfwords after reading data
1363 * use compress. Non standard option.
1365 gzip_program
= COMPRESS_CMD
;
1369 * process Version 6 cpio format
1371 frmt
= &(fsub
[F_OCPIO
]);
1382 * process the args as they are interpreted by the operation mode
1390 * cpio is like pax: list to stderr
1391 * unless in list mode
1395 while (*argv
!= NULL
)
1396 if (pat_add(*argv
++, NULL
) < 0)
1400 if (*argv
== NULL
) {
1401 paxwarn(0, "Destination directory was not supplied");
1405 if (mkpath(dirptr
) < 0)
1415 * no read errors allowed on updates/append operation!
1418 while ((str
= get_line(stdin
)) != NULL
) {
1421 if (ferror(stdin
)) {
1422 syswarn(1, errno
, "Unable to read from %s",
1432 #endif /* !NOCPIO */
1436 * print out those invalid flag sets found to the user
1440 printflg(unsigned int flg
)
1445 (void)fprintf(stderr
,"%s: Invalid combination of options:", argv0
);
1446 while ((nxt
= ffs(flg
)) != 0) {
1449 (void)fprintf(stderr
, " -%c", flgch
[pos
-1]);
1451 (void)putc('\n', stderr
);
1456 * called by format specific options routines to get each format specific
1457 * flag and value specified with -o
1459 * pointer to next OPLIST entry or NULL (end of list).
1467 if ((opt
= ophead
) != NULL
)
1468 ophead
= ophead
->fow
;
1474 * generic routine used to complain about a format specific options
1475 * when the format does not support options.
1486 * print all we were given
1488 paxwarn(1,"These format options are not supported");
1489 while ((opt
= opt_next()) != NULL
)
1490 (void)fprintf(stderr
, "\t%s = %s\n", opt
->name
, opt
->value
);
1497 * breaks the value supplied to -o into a option name and value. options
1498 * are given to -o in the form -o name-value,name=value
1499 * multiple -o may be specified.
1501 * 0 if format in name=value format, -1 if -o is passed junk
1505 opt_add(const char *str
)
1513 if ((str
== NULL
) || (*str
== '\0')) {
1514 paxwarn(0, "Invalid option name");
1517 if ((dstr
= strdup(str
)) == NULL
) {
1518 paxwarn(0, "Unable to allocate space for option list");
1521 frpt
= endpt
= dstr
;
1524 * break into name and values pieces and stuff each one into a
1525 * OPLIST structure. When we know the format, the format specific
1526 * option function will go through this list
1528 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1529 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1531 if ((pt
= strchr(frpt
, '=')) == NULL
) {
1532 paxwarn(0, "Invalid options format");
1536 if ((opt
= malloc(sizeof(OPLIST
))) == NULL
) {
1537 paxwarn(0, "Unable to allocate space for option list");
1541 dstr
= NULL
; /* parts of string going onto the OPLIST */
1550 if (ophead
== NULL
) {
1551 optail
= ophead
= opt
;
1563 * Convert an expression of the following forms to an off_t > 0.
1564 * 1) A positive decimal number.
1565 * 2) A positive decimal number followed by a b (mult by 512).
1566 * 3) A positive decimal number followed by a k (mult by 1024).
1567 * 4) A positive decimal number followed by a m (mult by 512).
1568 * 5) A positive decimal number followed by a w (mult by sizeof int)
1569 * 6) Two or more positive decimal numbers (with/without k,b or w).
1570 * separated by x (also * for backwards compatibility), specifying
1571 * the product of the indicated values.
1573 * 0 for an error, a positive value o.w.
1582 num
= strtoll(val
, &expr
, 0);
1583 if ((num
== LLONG_MAX
) || (num
<= 0) || (expr
== val
))
1623 num
*= str_offt(expr
+ 1);
1641 len
= getline(&str
, &size
, f
);
1646 if (str
[len
- 1] == '\n')
1647 str
[len
- 1] = '\0';
1648 } while (str
[0] == '\0');
1654 * for those option functions where the archive format has nothing to do.
1667 * print the usage summary to the user
1674 "usage: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s replstr]\n"
1675 " [-T range] [-U user] [pattern ...]\n"
1676 " pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G group] [-o options]\n"
1677 " [-p string] [-s replstr] [-T range] [-U user] [pattern ...]\n"
1678 " pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1679 " [-G group] [-o options] [-s replstr] [-T range] [-U user]\n"
1680 " [-x format] [file ...]\n"
1681 " pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1682 " [-T range] [-U user] [file ...] directory\n",
1689 * print the usage summary to the user
1696 "usage: tar {crtux}[014578befHhjLmNOoPpqsvwXZz]\n"
1697 " [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
1699 " tar {-crtux} [-014578eHhjLmNOoPpqvwXZz] [-b blocking-factor]\n"
1700 " [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
1708 * print the usage summary to the user
1715 "usage: cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format]\n"
1716 " [-O archive] < name-list [> archive]\n"
1717 " cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]\n"
1718 " [-I archive] [pattern ...] [< archive]\n"
1719 " cpio -p [-adLlmuv] destination-directory < name-list\n",
1723 #endif /* !NOCPIO */
1727 compress_id(char *blk
, int size
)
1729 if (size
>= 2 && blk
[0] == '\037' && blk
[1] == '\235') {
1730 paxwarn(0, "input compressed with %s; use the -%c option"
1731 " to decompress it", "compress", 'Z');
1738 gzip_id(char *blk
, int size
)
1740 if (size
>= 2 && blk
[0] == '\037' && blk
[1] == '\213') {
1741 paxwarn(0, "input compressed with %s; use the -%c option"
1742 " to decompress it", "gzip", 'z');
1749 bzip2_id(char *blk
, int size
)
1751 if (size
>= 3 && blk
[0] == 'B' && blk
[1] == 'Z' && blk
[2] == 'h') {
1752 paxwarn(0, "input compressed with %s; use the -%c option"
1753 " to decompress it", "bzip2", 'j');
1760 xz_id(char *blk
, int size
)
1762 if (size
>= 6 && memcmp(blk
, "\xFD\x37\x7A\x58\x5A", 6) == 0) {
1763 paxwarn(0, "input compressed with xz");