]>
git.saurik.com Git - apple/file_cmds.git/blob - 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
39 static const char sccsid
[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
41 static const char rcsid
[] = "$OpenBSD: options.c,v 1.70 2008/06/11 00:49:08 pvalchev Exp $";
45 #include <sys/types.h>
51 #endif /* __APPLE__ */
52 #include <sys/param.h>
68 * Routines which handle command line options
71 static char flgch
[] = FLGCH
; /* list of all possible flags */
72 static OPLIST
*ophead
= NULL
; /* head for format specific options -x */
73 static OPLIST
*optail
= NULL
; /* option tail */
75 static int no_op(void);
76 static void printflg(unsigned int);
77 static int c_frmt(const void *, const void *);
78 static off_t
str_offt(char *);
79 static char *pax_getline(FILE *fp
);
80 static void pax_options(int, char **);
82 static void tar_options(int, char **);
83 static void tar_usage(void);
84 static void cpio_options(int, char **);
85 static void cpio_usage(void);
87 /* errors from getline */
88 #define GETLINE_FILE_CORRUPT 1
89 #define GETLINE_OUT_OF_MEM 2
90 static int getline_error
;
93 #define GZIP_CMD "gzip" /* command to run as gzip */
94 #define COMPRESS_CMD "compress" /* command to run as compress */
95 #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
98 * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
99 * (see pax.h for description of each function)
101 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
102 * read, end_read, st_write, write, end_write, trail,
103 * rd_data, wr_data, options
107 /* 0: OLD BINARY CPIO */
108 {"bcpio", 5120, sizeof(HD_BCPIO
), 1, 0, 0, 1, bcpio_id
, cpio_strd
,
109 bcpio_rd
, bcpio_endrd
, cpio_stwr
, bcpio_wr
, cpio_endwr
, cpio_trail
,
110 rd_wrfile
, wr_rdfile
, bad_opt
},
112 /* 1: OLD OCTAL CHARACTER CPIO */
113 {"cpio", 5120, sizeof(HD_CPIO
), 1, 0, 0, 1, cpio_id
, cpio_strd
,
114 cpio_rd
, cpio_endrd
, cpio_stwr
, cpio_wr
, cpio_endwr
, cpio_trail
,
115 rd_wrfile
, wr_rdfile
, bad_opt
},
117 /* 2: SVR4 HEX CPIO */
118 {"sv4cpio", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, vcpio_id
, cpio_strd
,
119 vcpio_rd
, vcpio_endrd
, cpio_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
120 rd_wrfile
, wr_rdfile
, bad_opt
},
122 /* 3: SVR4 HEX CPIO WITH CRC */
123 {"sv4crc", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, crc_id
, crc_strd
,
124 vcpio_rd
, vcpio_endrd
, crc_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
125 rd_wrfile
, wr_rdfile
, bad_opt
},
128 {"tar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, tar_id
, no_op
,
129 tar_rd
, tar_endrd
, no_op
, tar_wr
, tar_endwr
, tar_trail
,
130 rd_wrfile
, wr_rdfile
, tar_opt
},
133 {"ustar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, ustar_id
, ustar_strd
,
134 ustar_rd
, tar_endrd
, ustar_stwr
, ustar_wr
, tar_endwr
, tar_trail
,
135 rd_wrfile
, wr_rdfile
, bad_opt
},
138 {"pax", 5120, BLKMULT
, 0, 1, BLKMULT
, 0, pax_id
, ustar_strd
,
139 pax_rd
, tar_endrd
, ustar_stwr
, pax_wr
, tar_endwr
, tar_trail
,
140 rd_wrfile
, wr_rdfile
, pax_opt
},
142 #define F_OCPIO 0 /* format when called as cpio -6 */
143 #define F_ACPIO 1 /* format when called as cpio -c */
144 #define F_CPIO 3 /* format when called as cpio */
145 #define F_OTAR 4 /* format when called as tar -o */
146 #define F_TAR 5 /* format when called as tar */
147 #define F_PAX 6 /* format for pax */
148 #define DEFLT 5 /* default write format from list above */
151 * ford is the archive search order used by get_arc() to determine what kind
152 * of archive we are dealing with. This helps to properly id archive formats
153 * some formats may be subsets of others....
155 int ford
[] = {6, 5, 4, 3, 2, 1, 0, -1 };
158 * Do we have -C anywhere?
164 * figure out if we are pax, tar or cpio. Call the appropriate options
169 options(int argc
, char **argv
)
173 * Are we acting like pax, tar or cpio (based on argv[0])
175 if ((argv0
= strrchr(argv
[0], '/')) != NULL
)
180 if (strcmp(NM_TAR
, argv0
) == 0) {
181 tar_options(argc
, argv
);
183 } else if (strcmp(NM_CPIO
, argv0
) == 0) {
184 cpio_options(argc
, argv
);
188 * assume pax as the default
191 pax_options(argc
, argv
);
194 #define OPT_INSECURE 1
195 struct option pax_longopts
[] = {
196 { "insecure", no_argument
, 0, OPT_INSECURE
},
202 * look at the user specified flags. set globals as required and check if
203 * the user specified a legal set of flags. If not, complain and exit
207 pax_options(int argc
, char **argv
)
211 unsigned int flg
= 0;
212 unsigned int bflg
= 0;
220 * process option flags
222 while ((c
=getopt_long(argc
,argv
,"0ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ", pax_longopts
, NULL
)) != -1) {
226 * Use \0 as pathname terminator.
227 * (For use with the -print0 option of find(1).)
243 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
244 paxwarn(1, "Invalid block size %s", optarg
);
250 * inverse match on patterns
257 * match only dir on extract, not the subtree at dir
264 * filename where the archive is stored
266 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
268 * treat a - as stdin (like tar)
278 * interactive file rename
285 * use bzip2. Non standard option.
287 gzip_program
= BZIP2_CMD
;
291 * do not clobber files that exist
298 * try to link src to dest with copy (-rw)
305 * select first match for a pattern only
312 * pass format specific options
315 if (pax_format_opt_add(optarg
) < 0)
320 * specify file characteristic options
322 for (pt
= optarg
; *pt
!= '\0'; ++pt
) {
326 * do not preserve access time
332 * preserve user id, group id, file
333 * mode, access/modification times
342 * do not preserve modification time
354 * preserve file mode bits
359 paxwarn(1, "Invalid -p string: %c", *pt
);
370 pax_read_or_list_mode
=1;
375 * file name substitution name pattern
377 if (rep_add(optarg
) < 0) {
385 * preserve access time on filesystem nodes we read
392 * ignore those older files
399 * verbose operation mode
412 * specify an archive format on write
415 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
416 if ((frmt
= (FSUB
*)lsearch(&tmp
, fsub
, &n_fsub
, sizeof(FSUB
),
421 paxwarn(1, "Unknown -x format: %s", optarg
);
422 (void)fputs("pax: Known -x formats are:", stderr
);
423 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
424 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
425 (void)fputs("\n\n", stderr
);
430 * use gzip. Non standard option.
432 gzip_program
= GZIP_CMD
;
436 * non-standard option on number of bytes written on a
437 * single archive volume.
439 if ((wrlimit
= str_offt(optarg
)) <= 0) {
440 paxwarn(1, "Invalid write limit %s", optarg
);
443 if (wrlimit
% BLKMULT
) {
444 paxwarn(1, "Write limit is not a %d byte multiple",
452 * On extraction check file inode change time before the
453 * modification of the file name. Non standard option.
460 * non-standard limit on read faults
461 * 0 indicates stop after first error, values
462 * indicate a limit, "NONE" try forever
465 if (strcmp(NONE
, optarg
) == 0)
467 else if ((maxflt
= atoi(optarg
)) < 0) {
468 paxwarn(1, "Error count value must be positive");
474 * non-standard option for selecting files within an
475 * archive by group (gid or name)
477 if (grp_add(optarg
) < 0) {
485 * follow command line symlinks only
489 Lflag
= 0; /* -H and -L are mutually exclusive */
490 flg
&= ~CLF
; /* only use the last one seen */
498 Hflag
= 0; /* -H and -L are mutually exclusive */
499 flg
&= ~CHF
; /* only use the last one seen */
503 * Force one volume. Non standard option.
505 force_one_volume
= 1;
509 * do NOT follow symlinks (default)
516 * non-standard option for selecting files within an
517 * archive by modification time range (lower,upper)
519 if (trng_add(optarg
) < 0) {
527 * non-standard option for selecting files within an
528 * archive by user (uid or name)
530 if (usr_add(optarg
) < 0) {
538 * do not pass over mount points in the file system
545 * On extraction check file inode change time after the
546 * modification of the file name. Non standard option.
553 * On extraction check modification time after the
554 * modification of the file name. Non standard option.
569 * Fix for POSIX.cmd/pax/pax.ex test 132: force -wu options to look
570 * like -wua options were specified.
572 if (uflag
&& (flg
& WF
) && !(flg
& RF
)) { /* -w but not -r -w */
577 * figure out the operation mode of pax read,write,extract,copy,append
578 * or list. check that we have not been given a bogus set of flags
579 * for the operation mode.
583 pax_read_or_list_mode
=1;
586 } else if (ISEXTRACT(flg
)) {
589 } else if (ISARCHIVE(flg
)) {
592 } else if (ISAPPND(flg
)) {
595 } else if (ISCOPY(flg
)) {
606 * if we are writing (ARCHIVE) we use the default format if the user
607 * did not specify a format. when we write during an APPEND, we will
608 * adopt the format of the existing archive if none was supplied.
610 if (!(flg
& XF
) && (act
== ARCHIVE
))
611 frmt
= &(fsub
[DEFLT
]);
614 * if copying (-r and -w) and there is no -x specified, we act as
615 * if -x pax was specified.
617 if (!(flg
& XF
) && (act
== COPY
))
618 frmt
= &(fsub
[F_PAX
]);
621 * Initialize the global extended header template.
623 tmp_name
= getenv("TMPDIR");
625 asprintf(&header_name_g
, "%s%s", tmp_name
, "/GlobalHead.%p.%n");
627 header_name_g
= "/tmp/GlobalHead.%p.%n";
631 * process the args as they are interpreted by the operation mode
636 for (; optind
< argc
; optind
++)
637 if (pat_add(argv
[optind
], NULL
) < 0)
641 if (optind
>= argc
) {
642 paxwarn(0, "Destination directory was not supplied");
650 for (; optind
< argc
; optind
++)
651 if (ftree_add(argv
[optind
], 0) < 0)
654 * no read errors allowed on updates/append operation!
664 * look at the user specified flags. set globals as required and check if
665 * the user specified a legal set of flags. If not, complain and exit
669 tar_options(int argc
, char **argv
)
675 int incfiles_max
= 0;
680 struct incfile
*incfiles
= NULL
;
683 * Set default values.
688 * process option flags
690 while ((c
= getoldopt(argc
, argv
,
691 "b:cef:hjmopqruts:vwxzBC:HI:LOPXZ014578")) != -1) {
695 * specify blocksize in 512-byte blocks
697 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
698 paxwarn(1, "Invalid block size %s", optarg
);
701 wrblksz
*= 512; /* XXX - check for int oflow */
711 * stop after first error
717 * filename where the archive is stored
719 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
738 * use bzip2. Non standard option.
740 gzip_program
= BZIP2_CMD
;
744 * do not preserve modification time
756 * preserve uid/gid and file mode, regardless of umask
763 * select first match for a pattern only
770 * append to the archive
776 * file name substitution name pattern
778 if (rep_add(optarg
) < 0) {
785 * list contents of the tape
791 * verbose operation mode
797 * interactive file rename
803 * extract an archive, preserving mode,
804 * and mtime if possible.
811 * use gzip. Non standard option.
813 gzip_program
= GZIP_CMD
;
817 * Nothing to do here, this is pax default
826 * follow command line symlinks only
831 if (++nincfiles
> incfiles_max
) {
832 incfiles_max
= nincfiles
+ 3;
833 incfiles
= realloc(incfiles
,
834 sizeof(*incfiles
) * incfiles_max
);
835 if (incfiles
== NULL
) {
836 paxwarn(0, "Unable to allocate space "
841 incfiles
[nincfiles
- 1].file
= optarg
;
842 incfiles
[nincfiles
- 1].dir
= chdname
;
852 * do not remove leading '/' from pathnames
858 * do not pass over mount points in the file system
866 gzip_program
= COMPRESS_CMD
;
894 /* Traditional tar behaviour (pax uses stderr unless in list mode) */
895 if (fstdin
== 1 && act
== ARCHIVE
)
900 /* Traditional tar behaviour (pax wants to read file list from stdin) */
901 if ((act
== ARCHIVE
|| act
== APPND
) && argc
== 0 && nincfiles
== 0)
905 * process the args as they are interpreted by the operation mode
913 char *file
, *dir
= NULL
;
915 while (nincfiles
|| *argv
!= NULL
) {
917 * If we queued up any include files,
918 * pull them in now. Otherwise, check
919 * for -I and -C positional flags.
920 * Anything else must be a file to
924 file
= incfiles
->file
;
928 } else if (strcmp(*argv
, "-I") == 0) {
939 if (strcmp(file
, "-") == 0)
941 else if ((fp
= fopen(file
, "r")) == NULL
) {
942 paxwarn(1, "Unable to open file '%s' for read", file
);
945 while ((str
= pax_getline(fp
)) != NULL
) {
946 if (pat_add(str
, dir
) < 0)
950 if (strcmp(file
, "-") != 0)
953 paxwarn(1, "Problem with file '%s'", file
);
956 } else if (strcmp(*argv
, "-C") == 0) {
961 } else if (pat_add(*argv
++, chdname
) < 0)
967 * if patterns were added, we are doing chdir()
968 * on a file-by-file basis, else, just one
969 * global chdir (if any) after opening input.
977 frmt
= &(fsub
[Oflag
? F_OTAR
: F_TAR
]);
979 if (Oflag
== 2 && opt_add("write_opt=nodir") < 0)
982 if (chdname
!= NULL
) { /* initial chdir() */
983 if (ftree_add(chdname
, 1) < 0)
987 while (nincfiles
|| *argv
!= NULL
) {
988 char *file
, *dir
= NULL
;
991 * If we queued up any include files, pull them in
992 * now. Otherwise, check for -I and -C positional
993 * flags. Anything else must be a file to include
997 file
= incfiles
->file
;
1001 } else if (strcmp(*argv
, "-I") == 0) {
1002 if (*++argv
== NULL
)
1012 /* Set directory if needed */
1014 if (ftree_add(dir
, 1) < 0)
1018 if (strcmp(file
, "-") == 0)
1020 else if ((fp
= fopen(file
, "r")) == NULL
) {
1021 paxwarn(1, "Unable to open file '%s' for read", file
);
1024 while ((str
= pax_getline(fp
)) != NULL
) {
1025 if (ftree_add(str
, 0) < 0)
1028 if (strcmp(file
, "-") != 0)
1030 if (getline_error
) {
1031 paxwarn(1, "Problem with file '%s'",
1035 } else if (strcmp(*argv
, "-C") == 0) {
1036 if (*++argv
== NULL
)
1038 if (ftree_add(*argv
++, 1) < 0)
1041 } else if (ftree_add(*argv
++, 0) < 0)
1045 * no read errors allowed on updates/append operation!
1050 if (!fstdin
&& ((arcname
== NULL
) || (*arcname
== '\0'))) {
1051 arcname
= getenv("TAPE");
1052 if ((arcname
== NULL
) || (*arcname
== '\0'))
1053 arcname
= _PATH_DEFTAPE
;
1070 slash
+= strspn(slash
, "/");
1071 slash
+= strcspn(slash
, "/");
1073 done
= (*slash
== '\0');
1076 if (stat(path
, &sb
)) {
1077 if (errno
!= ENOENT
|| mkdir(path
, 0777)) {
1078 paxwarn(1, "%s", path
);
1081 } else if (!S_ISDIR(sb
.st_mode
)) {
1082 syswarn(1, ENOTDIR
, "%s", path
);
1094 * look at the user specified flags. set globals as required and check if
1095 * the user specified a legal set of flags. If not, complain and exit
1099 cpio_options(int argc
, char **argv
)
1115 while ((c
=getopt(argc
,argv
,"abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
1119 * preserve access time on files read
1125 * swap bytes and half-words when reading data
1132 frmt
= &(fsub
[F_ACPIO
]);
1136 * create directories as needed
1142 * invert meaning of pattern list
1148 * restore an archive
1154 * use bzip2. Non standard option.
1156 gzip_program
= BZIP2_CMD
;
1162 * use links instead of copies when possible
1168 * preserve modification time
1177 frmt
= &(fsub
[F_CPIO
]);
1187 * interactively rename files
1193 * swap bytes after reading data
1198 * list contents of archive
1205 * replace newer files
1211 * verbose operation mode
1217 * use gzip. Non standard option.
1219 gzip_program
= GZIP_CMD
;
1229 * Use 5120 byte block size
1235 * set block size in bytes
1237 wrblksz
= atoi(optarg
);
1241 * file with patterns to extract or list
1243 if ((fp
= fopen(optarg
, "r")) == NULL
) {
1244 paxwarn(1, "Unable to open file '%s' for read", optarg
);
1247 while ((str
= pax_getline(fp
)) != NULL
) {
1251 if (getline_error
) {
1252 paxwarn(1, "Problem with file '%s'", optarg
);
1260 * filename where the archive is stored
1262 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
1264 * treat a - as stdin
1273 * specify an archive format on write
1276 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
1277 if ((frmt
= (FSUB
*)lsearch((void *)&tmp
, (void *)fsub
,
1278 &n_fsub
, sizeof(FSUB
), c_frmt
)) != NULL
)
1280 paxwarn(1, "Unknown -H format: %s", optarg
);
1281 (void)fputs("cpio: Known -H formats are:", stderr
);
1282 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
1283 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
1284 (void)fputs("\n\n", stderr
);
1289 * follow symbolic links
1295 * swap halfwords after reading data
1300 * use compress. Non standard option.
1302 gzip_program
= COMPRESS_CMD
;
1306 * process Version 6 cpio format
1308 frmt
= &(fsub
[F_OCPIO
]);
1319 * process the args as they are interpreted by the operation mode
1324 while (*argv
!= NULL
)
1325 if (pat_add(*argv
++, NULL
) < 0)
1329 if (*argv
== NULL
) {
1330 paxwarn(0, "Destination directory was not supplied");
1334 if (mkpath(dirptr
) < 0)
1344 * no read errors allowed on updates/append operation!
1347 while ((str
= pax_getline(stdin
)) != NULL
) {
1350 if (getline_error
) {
1351 paxwarn(1, "Problem while reading stdin");
1363 * print out those invalid flag sets found to the user
1367 printflg(unsigned int flg
)
1372 (void)fprintf(stderr
,"%s: Invalid combination of options:", argv0
);
1373 while ((nxt
= ffs(flg
)) != 0) {
1376 (void)fprintf(stderr
, " -%c", flgch
[pos
-1]);
1378 (void)putc('\n', stderr
);
1383 * comparison routine used by bsearch to find the format specified
1388 c_frmt(const void *a
, const void *b
)
1390 return(strcmp(((const FSUB
*)a
)->name
, ((const FSUB
*)b
)->name
));
1395 * called by format specific options routines to get each format specific
1396 * flag and value specified with -o
1398 * pointer to next OPLIST entry or NULL (end of list).
1406 if ((opt
= ophead
) != NULL
)
1407 ophead
= ophead
->fow
;
1413 * generic routine used to complain about a format specific options
1414 * when the format does not support options.
1425 * print all we were given
1427 paxwarn(1,"These format options are not supported");
1428 while ((opt
= opt_next()) != NULL
) {
1429 if (opt
->separator
== SEP_EQ
) {
1430 (void)fprintf(stderr
, "\t%s = %s\n", opt
->name
, opt
->value
);
1431 } else if (opt
->separator
== SEP_COLONEQ
) {
1432 (void)fprintf(stderr
, "\t%s := %s\n", opt
->name
, opt
->value
);
1433 } else { /* SEP_NONE */
1434 (void)fprintf(stderr
, "\t%s\n", opt
->name
);
1443 * breaks the value supplied to -o into an option name and value. Options
1444 * are given to -o in the form -o name-value,name=value
1445 * multiple -o may be specified.
1447 * 0 if format in name=value format, -1 if -o is passed junk.
1451 opt_add(const char *str
)
1459 if ((str
== NULL
) || (*str
== '\0')) {
1460 paxwarn(0, "Invalid option name");
1463 if ((dstr
= strdup(str
)) == NULL
) {
1464 paxwarn(0, "Unable to allocate space for option list");
1470 * break into name and values pieces and stuff each one into a
1471 * OPLIST structure. When we know the format, the format specific
1472 * option function will go through this list
1474 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1475 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1477 if ((pt
= strchr(frpt
, '=')) == NULL
) {
1478 paxwarn(0, "Invalid options format");
1482 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1483 paxwarn(0, "Unable to allocate space for option list");
1490 opt
->separator
= SEP_EQ
;
1496 if (ophead
== NULL
) {
1497 optail
= ophead
= opt
;
1507 * pax_format_opt_add()
1508 * breaks the value supplied to -o into a option name and value. options
1509 * are given to -o in the form -o name-value,name=value
1510 * multiple -o may be specified.
1512 * 0 if format in name=value format, -1 if -o is passed junk
1516 pax_format_opt_add(register char *str
)
1518 register OPLIST
*opt
;
1519 register char *frpt
;
1521 register char *endpt
;
1522 register int separator
;
1524 if ((str
== NULL
) || (*str
== '\0')) {
1525 paxwarn(0, "Invalid option name");
1528 if ((str
= strdup(str
)) == NULL
) {
1529 paxwarn(0, "Unable to allocate space for option list");
1535 * break into name and values pieces and stuff each one into a
1536 * OPLIST structure. When we know the format, the format specific
1537 * option function will go through this list
1539 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1540 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1542 if ((pt
= strstr(frpt
, ":=")) != NULL
) {
1544 pt
++; /* beyond the := */
1545 separator
= SEP_COLONEQ
;
1546 } else if ((pt
= strchr(frpt
, '=')) != NULL
) {
1550 /* keyword with no value */
1551 separator
= SEP_NONE
;
1553 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1554 paxwarn(0, "Unable to allocate space for option list");
1560 opt
->separator
= separator
;
1566 if (ophead
== NULL
) {
1567 optail
= ophead
= opt
;
1578 * Convert an expression of the following forms to an off_t > 0.
1579 * 1) A positive decimal number.
1580 * 2) A positive decimal number followed by a b (mult by 512).
1581 * 3) A positive decimal number followed by a k (mult by 1024).
1582 * 4) A positive decimal number followed by a m (mult by 512).
1583 * 5) A positive decimal number followed by a w (mult by sizeof int)
1584 * 6) Two or more positive decimal numbers (with/without k,b or w).
1585 * separated by x (also * for backwards compatibility), specifying
1586 * the product of the indicated values.
1588 * 0 for an error, a positive value o.w.
1598 num
= strtol(val
, &expr
, 0);
1599 if ((num
== LONG_MAX
) || (num
<= 0) || (expr
== val
))
1601 num
= strtoq(val
, &expr
, 0);
1602 if ((num
== QUAD_MAX
) || (num
<= 0) || (expr
== val
))
1643 num
*= str_offt(expr
+ 1);
1654 pax_getline(FILE *f
)
1659 name
= fgetln(f
, &len
);
1661 getline_error
= ferror(f
) ? GETLINE_FILE_CORRUPT
: 0;
1664 if (name
[len
-1] != '\n')
1668 getline_error
= GETLINE_OUT_OF_MEM
;
1671 memcpy(temp
, name
, len
-1);
1678 * for those option functions where the archive format has nothing to do.
1691 * print the usage summary to the user
1698 "usage: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s replstr]\n"
1699 " [-T range] [-U user] [--insecure] [pattern ...]\n"
1700 " pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G group] [-o options]\n"
1701 " [-p string] [-s replstr] [-T range] [-U user] [--insecure] [pattern ...]\n"
1702 " pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1703 " [-G group] [-o options] [-s replstr] [-T range] [-U user]\n"
1704 " [-x format] [--insecure] [file ...]\n"
1705 " pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1706 " [-T range] [-U user] [--insecure] [file ...] directory\n",
1713 * print the usage summary to the user
1720 "usage: tar {crtux}[014578befHhjLmOoPpqsvwXZz]\n"
1721 " [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
1723 " tar {-crtux} [-014578eHhjLmOoPpqvwXZz] [-b blocking-factor]\n"
1724 " [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
1731 * print the usage summary to the user
1738 "usage: cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format]\n"
1739 " [-O archive] < name-list [> archive]\n"
1740 " cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]\n"
1741 " [-I archive] [pattern ...] [< archive]\n"
1742 " cpio -p [-adLlmuv] destination-directory < name-list\n",