]>
git.saurik.com Git - apple/file_cmds.git/blob - pax/options.c
feb97e23508b1b33b26ce75cd9ff3426dad8c7e6
1 /* $OpenBSD: options.c,v 1.61 2004/04/16 22:50:23 deraadt 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
[] __attribute__((__unused__
)) = "$OpenBSD: options.c,v 1.61 2004/04/16 22:50:23 deraadt Exp $";
45 #include <sys/types.h>
49 #include <sys/param.h>
65 * Routines which handle command line options
68 static char flgch
[] = FLGCH
; /* list of all possible flags */
69 static OPLIST
*ophead
= NULL
; /* head for format specific options -x */
70 static OPLIST
*optail
= NULL
; /* option tail */
72 static int no_op(void);
73 static void printflg(unsigned int);
74 static int c_frmt(const void *, const void *);
75 static off_t
str_offt(char *);
76 static char *getline(FILE *fp
);
77 static void pax_options(int, char **);
79 static void tar_options(int, char **);
80 static void tar_usage(void);
81 static void cpio_options(int, char **);
82 static void cpio_usage(void);
84 /* errors from getline */
85 #define GETLINE_FILE_CORRUPT 1
86 #define GETLINE_OUT_OF_MEM 2
87 static int getline_error
;
90 #define GZIP_CMD "gzip" /* command to run as gzip */
91 #define COMPRESS_CMD "compress" /* command to run as compress */
94 * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
95 * (see pax.h for description of each function)
97 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
98 * read, end_read, st_write, write, end_write, trail,
99 * rd_data, wr_data, options
103 /* 0: OLD BINARY CPIO */
104 {"bcpio", 5120, sizeof(HD_BCPIO
), 1, 0, 0, 1, bcpio_id
, cpio_strd
,
105 bcpio_rd
, bcpio_endrd
, cpio_stwr
, bcpio_wr
, cpio_endwr
, cpio_trail
,
106 rd_wrfile
, wr_rdfile
, bad_opt
},
108 /* 1: OLD OCTAL CHARACTER CPIO */
109 {"cpio", 5120, sizeof(HD_CPIO
), 1, 0, 0, 1, cpio_id
, cpio_strd
,
110 cpio_rd
, cpio_endrd
, cpio_stwr
, cpio_wr
, cpio_endwr
, cpio_trail
,
111 rd_wrfile
, wr_rdfile
, bad_opt
},
113 /* 2: SVR4 HEX CPIO */
114 {"sv4cpio", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, vcpio_id
, cpio_strd
,
115 vcpio_rd
, vcpio_endrd
, cpio_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
116 rd_wrfile
, wr_rdfile
, bad_opt
},
118 /* 3: SVR4 HEX CPIO WITH CRC */
119 {"sv4crc", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, crc_id
, crc_strd
,
120 vcpio_rd
, vcpio_endrd
, crc_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
121 rd_wrfile
, wr_rdfile
, bad_opt
},
124 {"tar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, tar_id
, no_op
,
125 tar_rd
, tar_endrd
, no_op
, tar_wr
, tar_endwr
, tar_trail
,
126 rd_wrfile
, wr_rdfile
, tar_opt
},
129 {"ustar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, ustar_id
, ustar_strd
,
130 ustar_rd
, tar_endrd
, ustar_stwr
, ustar_wr
, tar_endwr
, tar_trail
,
131 rd_wrfile
, wr_rdfile
, bad_opt
},
134 {"pax", 5120, BLKMULT
, 0, 1, BLKMULT
, 0, pax_id
, ustar_strd
,
135 pax_rd
, tar_endrd
, ustar_stwr
, pax_wr
, tar_endwr
, tar_trail
,
136 rd_wrfile
, wr_rdfile
, pax_opt
},
138 #define F_OCPIO 0 /* format when called as cpio -6 */
139 #define F_ACPIO 1 /* format when called as cpio -c */
140 #define F_CPIO 3 /* format when called as cpio */
141 #define F_OTAR 4 /* format when called as tar -o */
142 #define F_TAR 5 /* format when called as tar */
143 #define F_PAX 6 /* format when called as pax -x pax */
144 #define DEFLT 5 /* default write format from list above */
147 * ford is the archive search order used by get_arc() to determine what kind
148 * of archive we are dealing with. This helps to properly id archive formats
149 * some formats may be subsets of others....
151 int ford
[] = {6, 5, 4, 3, 2, 1, 0, -1 };
155 * figure out if we are pax, tar or cpio. Call the appropriate options
160 options(int argc
, char **argv
)
164 * Are we acting like pax, tar or cpio (based on argv[0])
166 if ((argv0
= strrchr(argv
[0], '/')) != NULL
)
171 if (strcmp(NM_TAR
, argv0
) == 0) {
172 tar_options(argc
, argv
);
174 } else if (strcmp(NM_CPIO
, argv0
) == 0) {
175 cpio_options(argc
, argv
);
179 * assume pax as the default
182 pax_options(argc
, argv
);
187 * look at the user specified flags. set globals as required and check if
188 * the user specified a legal set of flags. If not, complain and exit
192 pax_options(int argc
, char **argv
)
196 unsigned int flg
= 0;
197 unsigned int bflg
= 0;
205 * process option flags
207 while ((c
=getopt(argc
,argv
,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ0"))
221 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
222 paxwarn(1, "Invalid block size %s", optarg
);
228 * inverse match on patterns
235 * match only dir on extract, not the subtree at dir
242 * filename where the archive is stored
244 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
246 * treat a - as stdin (like tar)
256 * interactive file rename
263 * do not clobber files that exist
270 * try to link src to dest with copy (-rw)
277 * select first match for a pattern only
284 * pass format specific options
287 if (pax_format_opt_add(optarg
) < 0)
292 * specify file characteristic options
294 for (pt
= optarg
; *pt
!= '\0'; ++pt
) {
298 * do not preserve access time
304 * preserve user id, group id, file
305 * mode, access/modification times
314 * do not preserve modification time
326 * preserve file mode bits
331 paxwarn(1, "Invalid -p string: %c", *pt
);
342 pax_read_or_list_mode
=1;
347 * file name substitution name pattern
349 if (rep_add(optarg
) < 0) {
357 * preserve access time on filesystem nodes we read
364 * ignore those older files
371 * verbose operation mode
384 * specify an archive format on write
388 if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
389 sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) {
391 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
392 if ((frmt
= (FSUB
*)lsearch((void *)&tmp
, (void *)fsub
,
393 &n_fsub
, sizeof(FSUB
), c_frmt
)) != NULL
) {
397 paxwarn(1, "Unknown -x format: %s", optarg
);
398 (void)fputs("pax: Known -x formats are:", stderr
);
399 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
400 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
401 (void)fputs("\n\n", stderr
);
406 * use gzip. Non standard option.
408 gzip_program
= GZIP_CMD
;
412 * non-standard option on number of bytes written on a
413 * single archive volume.
415 if ((wrlimit
= str_offt(optarg
)) <= 0) {
416 paxwarn(1, "Invalid write limit %s", optarg
);
419 if (wrlimit
% BLKMULT
) {
420 paxwarn(1, "Write limit is not a %d byte multiple",
428 * On extraction check file inode change time before the
429 * modification of the file name. Non standard option.
436 * non-standard limit on read faults
437 * 0 indicates stop after first error, values
438 * indicate a limit, "NONE" try forever
441 if (strcmp(NONE
, optarg
) == 0)
443 else if ((maxflt
= atoi(optarg
)) < 0) {
444 paxwarn(1, "Error count value must be positive");
450 * non-standard option for selecting files within an
451 * archive by group (gid or name)
453 if (grp_add(optarg
) < 0) {
461 * follow command line symlinks only
465 Lflag
= 0; /* -H and -L are mutually exclusive */
466 flg
&= ~CLF
; /* only use the last one seen */
474 Hflag
= 0; /* -H and -L are mutually exclusive */
475 flg
&= ~CHF
; /* only use the last one seen */
479 * Force one volume. Non standard option.
481 force_one_volume
= 1;
485 * do NOT follow symlinks (default)
492 * non-standard option for selecting files within an
493 * archive by modification time range (lower,upper)
495 if (trng_add(optarg
) < 0) {
503 * non-standard option for selecting files within an
504 * archive by user (uid or name)
506 if (usr_add(optarg
) < 0) {
514 * do not pass over mount points in the file system
521 * On extraction check file inode change time after the
522 * modification of the file name. Non standard option.
529 * On extraction check modification time after the
530 * modification of the file name. Non standard option.
537 * Use \0 as pathname terminator.
538 * (For use with the -print0 option of find(1).)
550 * Fix for POSIX.cmd/pax/pax.ex test 132: force -wu options to look
551 * like -wua options were specified.
553 if (uflag
&& (flg
& WF
) && !(flg
& RF
)) { /* -w but not -r -w */
558 * figure out the operation mode of pax read,write,extract,copy,append
559 * or list. check that we have not been given a bogus set of flags
560 * for the operation mode.
564 pax_read_or_list_mode
=1;
567 } else if (ISEXTRACT(flg
)) {
570 } else if (ISARCHIVE(flg
)) {
573 } else if (ISAPPND(flg
)) {
576 } else if (ISCOPY(flg
)) {
587 * if we are writing (ARCHIVE) we use the default format if the user
588 * did not specify a format. when we write during an APPEND, we will
589 * adopt the format of the existing archive if none was supplied.
591 if (!(flg
& XF
) && (act
== ARCHIVE
))
592 frmt
= &(fsub
[DEFLT
]);
595 * if copying (-r and -w) and there is no -x specified, we act as
596 * if -x pax was specified.
598 if (!(flg
& XF
) && (act
== COPY
))
599 frmt
= &(fsub
[F_PAX
]);
602 * Initialize the global extended header template.
604 tmp_name
= getenv("TMPDIR");
606 asprintf(&header_name_g
, "%s%s", tmp_name
, "/GlobalHead.%p.%n");
608 header_name_g
= "/tmp/GlobalHead.%p.%n";
612 * process the args as they are interpreted by the operation mode
617 for (; optind
< argc
; optind
++)
618 if (pat_add(argv
[optind
], NULL
) < 0)
622 if (optind
>= argc
) {
623 paxwarn(0, "Destination directory was not supplied");
631 for (; optind
< argc
; optind
++)
632 if (ftree_add(argv
[optind
], 0) < 0)
635 * no read errors allowed on updates/append operation!
645 * look at the user specified flags. set globals as required and check if
646 * the user specified a legal set of flags. If not, complain and exit
650 tar_options(int argc
, char **argv
)
656 int incfiles_max
= 0;
661 struct incfile
*incfiles
= NULL
;
664 * Set default values.
669 * process option flags
671 while ((c
= getoldopt(argc
, argv
,
672 "b:cef:hmopqruts:vwxzBC:HI:LOPXZ014578")) != -1) {
676 * specify blocksize in 512-byte blocks
678 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
679 paxwarn(1, "Invalid block size %s", optarg
);
682 wrblksz
*= 512; /* XXX - check for int oflow */
692 * stop after first error
698 * filename where the archive is stored
700 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
719 * do not preserve modification time
731 * preserve uid/gid and file mode, regardless of umask
738 * select first match for a pattern only
745 * append to the archive
751 * file name substitution name pattern
753 if (rep_add(optarg
) < 0) {
760 * list contents of the tape
766 * verbose operation mode
772 * interactive file rename
778 * extract an archive, preserving mode,
779 * and mtime if possible.
786 * use gzip. Non standard option.
788 gzip_program
= GZIP_CMD
;
792 * Nothing to do here, this is pax default
800 * follow command line symlinks only
805 if (++nincfiles
> incfiles_max
) {
806 incfiles_max
= nincfiles
+ 3;
807 incfiles
= realloc(incfiles
,
808 sizeof(*incfiles
) * incfiles_max
);
809 if (incfiles
== NULL
) {
810 paxwarn(0, "Unable to allocate space "
815 incfiles
[nincfiles
- 1].file
= optarg
;
816 incfiles
[nincfiles
- 1].dir
= chdname
;
826 * do not remove leading '/' from pathnames
832 * do not pass over mount points in the file system
840 gzip_program
= COMPRESS_CMD
;
868 /* Traditional tar behaviour (pax uses stderr unless in list mode) */
869 if (fstdin
== 1 && act
== ARCHIVE
)
874 /* Traditional tar behaviour (pax wants to read file list from stdin) */
875 if ((act
== ARCHIVE
|| act
== APPND
) && argc
== 0 && nincfiles
== 0)
879 * process the args as they are interpreted by the operation mode
889 while (nincfiles
|| *argv
!= NULL
) {
891 * If we queued up any include files,
892 * pull them in now. Otherwise, check
893 * for -I and -C positional flags.
894 * Anything else must be a file to
898 file
= incfiles
->file
;
902 } else if (strcmp(*argv
, "-I") == 0) {
913 if (strcmp(file
, "-") == 0)
915 else if ((fp
= fopen(file
, "r")) == NULL
) {
916 paxwarn(1, "Unable to open file '%s' for read", file
);
919 while ((str
= getline(fp
)) != NULL
) {
920 if (pat_add(str
, dir
) < 0)
924 if (strcmp(file
, "-") != 0)
927 paxwarn(1, "Problem with file '%s'", file
);
930 } else if (strcmp(*argv
, "-C") == 0) {
934 } else if (pat_add(*argv
++, chdname
) < 0)
940 * if patterns were added, we are doing chdir()
941 * on a file-by-file basis, else, just one
942 * global chdir (if any) after opening input.
950 frmt
= &(fsub
[Oflag
? F_OTAR
: F_TAR
]);
952 if (Oflag
== 2 && opt_add("write_opt=nodir") < 0)
955 if (chdname
!= NULL
) { /* initial chdir() */
956 if (ftree_add(chdname
, 1) < 0)
960 while (nincfiles
|| *argv
!= NULL
) {
964 * If we queued up any include files, pull them in
965 * now. Otherwise, check for -I and -C positional
966 * flags. Anything else must be a file to include
970 file
= incfiles
->file
;
974 } else if (strcmp(*argv
, "-I") == 0) {
985 /* Set directory if needed */
987 if (ftree_add(dir
, 1) < 0)
991 if (strcmp(file
, "-") == 0)
993 else if ((fp
= fopen(file
, "r")) == NULL
) {
994 paxwarn(1, "Unable to open file '%s' for read", file
);
997 while ((str
= getline(fp
)) != NULL
) {
998 if (ftree_add(str
, 0) < 0)
1001 if (strcmp(file
, "-") != 0)
1003 if (getline_error
) {
1004 paxwarn(1, "Problem with file '%s'",
1008 } else if (strcmp(*argv
, "-C") == 0) {
1009 if (*++argv
== NULL
)
1011 if (ftree_add(*argv
++, 1) < 0)
1013 } else if (ftree_add(*argv
++, 0) < 0)
1017 * no read errors allowed on updates/append operation!
1022 if (!fstdin
&& ((arcname
== NULL
) || (*arcname
== '\0'))) {
1023 arcname
= getenv("TAPE");
1024 if ((arcname
== NULL
) || (*arcname
== '\0'))
1025 arcname
= _PATH_DEFTAPE
;
1042 slash
+= strspn(slash
, "/");
1043 slash
+= strcspn(slash
, "/");
1045 done
= (*slash
== '\0');
1048 if (stat(path
, &sb
)) {
1049 if (errno
!= ENOENT
|| mkdir(path
, 0777)) {
1050 paxwarn(1, "%s", path
);
1053 } else if (!S_ISDIR(sb
.st_mode
)) {
1054 syswarn(1, ENOTDIR
, "%s", path
);
1066 * look at the user specified flags. set globals as required and check if
1067 * the user specified a legal set of flags. If not, complain and exit
1071 cpio_options(int argc
, char **argv
)
1089 while ((c
=getopt(argc
,argv
,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
1093 * preserve access time on files read
1099 * swap bytes and half-words when reading data
1106 frmt
= &(fsub
[F_ACPIO
]);
1110 * create directories as needed
1116 * invert meaning of pattern list
1122 * restore an archive
1130 * use links instead of copies when possible
1136 * preserve modification time
1145 frmt
= &(fsub
[F_CPIO
]);
1155 * interactively rename files
1161 * swap bytes after reading data
1166 * list contents of archive
1173 * replace newer files
1179 * verbose operation mode
1185 * use gzip. Non standard option.
1187 gzip_program
= GZIP_CMD
;
1197 * Use 5120 byte block size
1203 * set block size in bytes
1205 wrblksz
= atoi(optarg
);
1209 * file with patterns to extract or list
1211 if ((fp
= fopen(optarg
, "r")) == NULL
) {
1212 paxwarn(1, "Unable to open file '%s' for read", optarg
);
1215 while ((str
= getline(fp
)) != NULL
) {
1219 if (getline_error
) {
1220 paxwarn(1, "Problem with file '%s'", optarg
);
1228 * filename where the archive is stored
1230 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
1232 * treat a - as stdin
1241 * specify an archive format on write
1245 if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
1246 sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL)
1248 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
1249 if ((frmt
= (FSUB
*)lsearch((void *)&tmp
, (void *)fsub
,
1250 &n_fsub
, sizeof(FSUB
), c_frmt
)) != NULL
)
1252 paxwarn(1, "Unknown -H format: %s", optarg
);
1253 (void)fputs("cpio: Known -H formats are:", stderr
);
1254 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
1255 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
1256 (void)fputs("\n\n", stderr
);
1261 * follow symbolic links
1267 * swap halfwords after reading data
1272 * use compress. Non standard option.
1274 gzip_program
= COMPRESS_CMD
;
1278 * process Version 6 cpio format
1280 frmt
= &(fsub
[F_OCPIO
]);
1291 * process the args as they are interpreted by the operation mode
1296 while (*argv
!= NULL
)
1297 if (pat_add(*argv
++, NULL
) < 0)
1301 if (*argv
== NULL
) {
1302 paxwarn(0, "Destination directory was not supplied");
1306 if (mkpath(dirptr
) < 0)
1316 * no read errors allowed on updates/append operation!
1319 while ((str
= getline(stdin
)) != NULL
) {
1322 if (getline_error
) {
1323 paxwarn(1, "Problem while reading stdin");
1335 * print out those invalid flag sets found to the user
1339 printflg(unsigned int flg
)
1344 (void)fprintf(stderr
,"%s: Invalid combination of options:", argv0
);
1345 while ((nxt
= ffs(flg
)) != 0) {
1348 (void)fprintf(stderr
, " -%c", flgch
[pos
-1]);
1350 (void)putc('\n', stderr
);
1355 * comparison routine used by bsearch to find the format specified
1360 c_frmt(const void *a
, const void *b
)
1362 return(strcmp(((FSUB
*)a
)->name
, ((FSUB
*)b
)->name
));
1367 * called by format specific options routines to get each format specific
1368 * flag and value specified with -o
1370 * pointer to next OPLIST entry or NULL (end of list).
1378 if ((opt
= ophead
) != NULL
)
1379 ophead
= ophead
->fow
;
1385 * generic routine used to complain about a format specific options
1386 * when the format does not support options.
1397 * print all we were given
1399 paxwarn(1,"These format options are not supported");
1400 while ((opt
= opt_next()) != NULL
) {
1401 if (opt
->separator
== SEP_EQ
) {
1402 (void)fprintf(stderr
, "\t%s = %s\n", opt
->name
, opt
->value
);
1403 } else if (opt
->separator
== SEP_COLONEQ
) {
1404 (void)fprintf(stderr
, "\t%s := %s\n", opt
->name
, opt
->value
);
1405 } else { /* SEP_NONE */
1406 (void)fprintf(stderr
, "\t%s\n", opt
->name
);
1415 * breaks the value supplied to -o into a option name and value. options
1416 * are given to -o in the form -o name-value,name=value
1417 * multiple -o may be specified.
1419 * 0 if format in name=value format, -1 if -o is passed junk
1423 opt_add(const char *str
)
1431 if ((str
== NULL
) || (*str
== '\0')) {
1432 paxwarn(0, "Invalid option name");
1435 if ((dstr
= strdup(str
)) == NULL
) {
1436 paxwarn(0, "Unable to allocate space for option list");
1439 frpt
= endpt
= dstr
;
1442 * break into name and values pieces and stuff each one into a
1443 * OPLIST structure. When we know the format, the format specific
1444 * option function will go through this list
1446 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1447 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1449 if ((pt
= strchr(frpt
, '=')) == NULL
) {
1450 paxwarn(0, "Invalid options format");
1454 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1455 paxwarn(0, "Unable to allocate space for option list");
1462 opt
->separator
= SEP_EQ
;
1468 if (ophead
== NULL
) {
1469 optail
= ophead
= opt
;
1480 * pax_format_opt_add()
1481 * breaks the value supplied to -o into a option name and value. options
1482 * are given to -o in the form -o name-value,name=value
1483 * multiple -o may be specified.
1485 * 0 if format in name=value format, -1 if -o is passed junk
1489 pax_format_opt_add(register char *str
)
1491 register OPLIST
*opt
;
1492 register char *frpt
;
1494 register char *endpt
;
1495 register int separator
;
1497 if ((str
== NULL
) || (*str
== '\0')) {
1498 paxwarn(0, "Invalid option name");
1501 if ((str
= strdup(str
)) == NULL
) {
1502 paxwarn(0, "Unable to allocate space for option list");
1508 * break into name and values pieces and stuff each one into a
1509 * OPLIST structure. When we know the format, the format specific
1510 * option function will go through this list
1512 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1513 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1515 if ((pt
= strstr(frpt
, ":=")) != NULL
) {
1517 pt
++; /* beyond the := */
1518 separator
= SEP_COLONEQ
;
1519 } else if ((pt
= strchr(frpt
, '=')) != NULL
) {
1523 /* keyword with no value */
1524 separator
= SEP_NONE
;
1526 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1527 paxwarn(0, "Unable to allocate space for option list");
1533 opt
->separator
= separator
;
1539 if (ophead
== NULL
) {
1540 optail
= ophead
= opt
;
1551 * Convert an expression of the following forms to an off_t > 0.
1552 * 1) A positive decimal number.
1553 * 2) A positive decimal number followed by a b (mult by 512).
1554 * 3) A positive decimal number followed by a k (mult by 1024).
1555 * 4) A positive decimal number followed by a m (mult by 512).
1556 * 5) A positive decimal number followed by a w (mult by sizeof int)
1557 * 6) Two or more positive decimal numbers (with/without k,b or w).
1558 * separated by x (also * for backwards compatibility), specifying
1559 * the product of the indicated values.
1561 * 0 for an error, a positive value o.w.
1571 num
= strtol(val
, &expr
, 0);
1572 if ((num
== LONG_MAX
) || (num
<= 0) || (expr
== val
))
1574 num
= strtoq(val
, &expr
, 0);
1575 if ((num
== QUAD_MAX
) || (num
<= 0) || (expr
== val
))
1616 num
*= str_offt(expr
+ 1);
1632 name
= fgetln(f
, &len
);
1634 getline_error
= ferror(f
) ? GETLINE_FILE_CORRUPT
: 0;
1637 if (name
[len
-1] != '\n')
1641 getline_error
= GETLINE_OUT_OF_MEM
;
1644 memcpy(temp
, name
, len
-1);
1651 * for those option functions where the archive format has nothing to do.
1664 * print the usage summary to the user
1670 (void)fputs("usage: pax [-cdnvzO] [-E limit] [-f archive] ", stderr
);
1671 (void)fputs("[-s replstr] ... [-U user] ...", stderr
);
1672 (void)fputs("\n [-G group] ... ", stderr
);
1673 (void)fputs("[-T [from_date][,to_date]] ... ", stderr
);
1674 (void)fputs("[pattern ...]\n", stderr
);
1675 (void)fputs(" pax -r [-cdiknuvzDOYZ] [-E limit] ", stderr
);
1676 (void)fputs("[-f archive] [-o options] ... \n", stderr
);
1677 (void)fputs(" [-p string] ... [-s replstr] ... ", stderr
);
1678 (void)fputs("[-U user] ... [-G group] ...\n ", stderr
);
1679 (void)fputs("[-T [from_date][,to_date]] ... ", stderr
);
1680 (void)fputs(" [pattern ...]\n", stderr
);
1681 (void)fputs(" pax -w [-dituvzHLOPX] [-b blocksize] ", stderr
);
1682 (void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr
);
1683 (void)fputs(" [-B bytes] [-s replstr] ... ", stderr
);
1684 (void)fputs("[-o options] ... [-U user] ...", stderr
);
1685 (void)fputs("\n [-G group] ... ", stderr
);
1686 (void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr
);
1687 (void)fputs("[file ...]\n", stderr
);
1688 (void)fputs(" pax -r -w [-diklntuvDHLOPXYZ] ", stderr
);
1689 (void)fputs("[-p string] ... [-s replstr] ...", stderr
);
1690 (void)fputs("\n [-U user] ... [-G group] ... ", stderr
);
1691 (void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr
);
1692 (void)fputs("\n [file ...] directory\n", stderr
);
1698 * print the usage summary to the user
1704 (void)fputs("usage: tar [-]{crtux}[-befhmopqsvwzHLOPXZ014578] [blocksize] ",
1706 (void)fputs("[archive] [replstr] [-C directory] [-I file] [file ...]\n",
1713 * print the usage summary to the user
1719 (void)fputs("usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr
);
1720 (void)fputs(" [-F archive] < name-list [> archive]\n", stderr
);
1721 (void)fputs(" cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr
);
1722 (void)fputs(" [-I archive] [-F archive] [pattern...] [< archive]\n", stderr
);
1723 (void)fputs(" cpio -p [-adlLmuvV] destination-directory < name-list\n", stderr
);