]>
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
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>
69 * Routines which handle command line options
72 static char flgch
[] = FLGCH
; /* list of all possible flags */
73 static OPLIST
*ophead
= NULL
; /* head for format specific options -x */
74 static OPLIST
*optail
= NULL
; /* option tail */
76 static int no_op(void);
77 static void printflg(unsigned int);
78 static int c_frmt(const void *, const void *);
79 static off_t
str_offt(char *);
80 static char *pax_getline(FILE *fp
);
81 static void pax_options(int, char **);
83 static void tar_options(int, char **);
84 static void tar_usage(void);
85 static void cpio_options(int, char **);
86 static void cpio_usage(void);
88 /* errors from getline */
89 #define GETLINE_FILE_CORRUPT 1
90 #define GETLINE_OUT_OF_MEM 2
91 static int getline_error
;
94 #define GZIP_CMD "gzip" /* command to run as gzip */
95 #define COMPRESS_CMD "compress" /* command to run as compress */
96 #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
99 * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
100 * (see pax.h for description of each function)
102 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
103 * read, end_read, st_write, write, end_write, trail,
104 * rd_data, wr_data, options
107 const FSUB fsub
[] = {
108 /* OLD BINARY CPIO */
109 {"bcpio", 5120, sizeof(HD_BCPIO
), 1, 0, 0, 1, bcpio_id
, cpio_strd
,
110 bcpio_rd
, bcpio_endrd
, cpio_stwr
, bcpio_wr
, cpio_endwr
, cpio_trail
,
111 rd_wrfile
, wr_rdfile
, bad_opt
},
113 /* OLD OCTAL CHARACTER CPIO */
114 {"cpio", 5120, sizeof(HD_CPIO
), 1, 0, 0, 1, cpio_id
, cpio_strd
,
115 cpio_rd
, cpio_endrd
, cpio_stwr
, cpio_wr
, cpio_endwr
, cpio_trail
,
116 rd_wrfile
, wr_rdfile
, bad_opt
},
119 {"pax", 5120, BLKMULT
, 0, 1, BLKMULT
, 0, pax_id
, ustar_strd
,
120 pax_rd
, tar_endrd
, ustar_stwr
, pax_wr
, tar_endwr
, tar_trail
,
121 rd_wrfile
, wr_rdfile
, pax_opt
},
124 {"sv4cpio", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, vcpio_id
, cpio_strd
,
125 vcpio_rd
, vcpio_endrd
, cpio_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
126 rd_wrfile
, wr_rdfile
, bad_opt
},
128 /* SVR4 HEX CPIO WITH CRC */
129 {"sv4crc", 5120, sizeof(HD_VCPIO
), 1, 0, 0, 1, crc_id
, crc_strd
,
130 vcpio_rd
, vcpio_endrd
, crc_stwr
, vcpio_wr
, cpio_endwr
, cpio_trail
,
131 rd_wrfile
, wr_rdfile
, bad_opt
},
134 {"tar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, tar_id
, no_op
,
135 tar_rd
, tar_endrd
, no_op
, tar_wr
, tar_endwr
, tar_trail
,
136 rd_wrfile
, wr_rdfile
, tar_opt
},
139 {"ustar", 10240, BLKMULT
, 0, 1, BLKMULT
, 0, ustar_id
, ustar_strd
,
140 ustar_rd
, tar_endrd
, ustar_stwr
, ustar_wr
, tar_endwr
, tar_trail
,
141 rd_wrfile
, wr_rdfile
, bad_opt
},
143 #define F_OCPIO 0 /* format when called as cpio -6 */
144 #define F_ACPIO 1 /* format when called as cpio -c */
145 #define F_PAX 2 /* -x pax */
146 #define F_SCPIO 3 /* -x sv4cpio */
147 #define F_CPIO 4 /* format when called as cpio */
148 #define F_OTAR 5 /* format when called as tar -o */
149 #define F_TAR 6 /* format when called as tar */
150 #define DEFLT F_TAR /* default write format from list above */
153 * ford is the archive search order used by get_arc() to determine what kind
154 * of archive we are dealing with. This helps to properly id archive formats
155 * some formats may be subsets of others....
157 int ford
[] = {F_PAX
, F_TAR
, F_OTAR
, F_CPIO
, F_SCPIO
, F_ACPIO
, F_OCPIO
, -1 };
160 * Do we have -C anywhere?
166 * figure out if we are pax, tar or cpio. Call the appropriate options
171 options(int argc
, char **argv
)
175 * Are we acting like pax, tar or cpio (based on argv[0])
177 if ((argv0
= strrchr(argv
[0], '/')) != NULL
)
182 if (strcmp(NM_TAR
, argv0
) == 0) {
183 tar_options(argc
, argv
);
185 } else if (strcmp(NM_CPIO
, argv0
) == 0) {
186 cpio_options(argc
, argv
);
190 * assume pax as the default
193 pax_options(argc
, argv
);
196 #define OPT_INSECURE 1
197 struct option pax_longopts
[] = {
198 { "insecure", no_argument
, 0, OPT_INSECURE
},
204 * look at the user specified flags. set globals as required and check if
205 * the user specified a legal set of flags. If not, complain and exit
209 pax_options(int argc
, char **argv
)
213 unsigned int flg
= 0;
214 unsigned int bflg
= 0;
222 * process option flags
224 while ((c
=getopt_long(argc
,argv
,"0ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ", pax_longopts
, NULL
)) != -1) {
228 * Use \0 as pathname terminator.
229 * (For use with the -print0 option of find(1).)
245 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
246 paxwarn(1, "Invalid block size %s", optarg
);
252 * inverse match on patterns
259 * match only dir on extract, not the subtree at dir
266 * filename where the archive is stored
268 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
270 * treat a - as stdin (like tar)
280 * interactive file rename
287 * use bzip2. Non standard option.
289 gzip_program
= BZIP2_CMD
;
293 * do not clobber files that exist
300 * try to link src to dest with copy (-rw)
307 * select first match for a pattern only
314 * pass format specific options
317 if (pax_format_opt_add(optarg
) < 0)
322 * specify file characteristic options
324 for (pt
= optarg
; *pt
!= '\0'; ++pt
) {
328 * do not preserve access time
334 * preserve user id, group id, file
335 * mode, access/modification times
344 * do not preserve modification time
356 * preserve file mode bits
361 paxwarn(1, "Invalid -p string: %c", *pt
);
372 pax_read_or_list_mode
=1;
377 * file name substitution name pattern
379 if (rep_add(optarg
) < 0) {
387 * preserve access time on filesystem nodes we read
394 * ignore those older files
401 * verbose operation mode
414 * specify an archive format on write
417 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
418 if ((frmt
= (FSUB
*)bsearch(&tmp
, fsub
, n_fsub
, sizeof(FSUB
),
423 paxwarn(1, "Unknown -x format: %s", optarg
);
424 (void)fputs("pax: Known -x formats are:", stderr
);
425 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
426 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
427 (void)fputs("\n\n", stderr
);
432 * use gzip. Non standard option.
434 gzip_program
= GZIP_CMD
;
438 * non-standard option on number of bytes written on a
439 * single archive volume.
441 if ((wrlimit
= str_offt(optarg
)) <= 0) {
442 paxwarn(1, "Invalid write limit %s", optarg
);
445 if (wrlimit
% BLKMULT
) {
446 paxwarn(1, "Write limit is not a %d byte multiple",
454 * On extraction check file inode change time before the
455 * modification of the file name. Non standard option.
462 * non-standard limit on read faults
463 * 0 indicates stop after first error, values
464 * indicate a limit, "NONE" try forever
467 if (strcmp(NONE
, optarg
) == 0)
469 else if ((maxflt
= atoi(optarg
)) < 0) {
470 paxwarn(1, "Error count value must be positive");
476 * non-standard option for selecting files within an
477 * archive by group (gid or name)
479 if (grp_add(optarg
) < 0) {
487 * follow command line symlinks only
491 Lflag
= 0; /* -H and -L are mutually exclusive */
492 flg
&= ~CLF
; /* only use the last one seen */
500 Hflag
= 0; /* -H and -L are mutually exclusive */
501 flg
&= ~CHF
; /* only use the last one seen */
505 * Force one volume. Non standard option.
507 force_one_volume
= 1;
511 * do NOT follow symlinks (default)
518 * non-standard option for selecting files within an
519 * archive by modification time range (lower,upper)
521 if (trng_add(optarg
) < 0) {
529 * non-standard option for selecting files within an
530 * archive by user (uid or name)
532 if (usr_add(optarg
) < 0) {
540 * do not pass over mount points in the file system
547 * On extraction check file inode change time after the
548 * modification of the file name. Non standard option.
555 * On extraction check modification time after the
556 * modification of the file name. Non standard option.
571 * Fix for POSIX.cmd/pax/pax.ex test 132: force -wu options to look
572 * like -wua options were specified.
574 if (uflag
&& (flg
& WF
) && !(flg
& RF
)) { /* -w but not -r -w */
579 * figure out the operation mode of pax read,write,extract,copy,append
580 * or list. check that we have not been given a bogus set of flags
581 * for the operation mode.
585 pax_read_or_list_mode
=1;
588 } else if (ISEXTRACT(flg
)) {
591 } else if (ISARCHIVE(flg
)) {
594 } else if (ISAPPND(flg
)) {
597 } else if (ISCOPY(flg
)) {
608 * if we are writing (ARCHIVE) we use the default format if the user
609 * did not specify a format. when we write during an APPEND, we will
610 * adopt the format of the existing archive if none was supplied.
612 if (!(flg
& XF
) && (act
== ARCHIVE
))
613 frmt
= &(fsub
[DEFLT
]);
616 * if copying (-r and -w) and there is no -x specified, we act as
617 * if -x pax was specified.
619 if (!(flg
& XF
) && (act
== COPY
))
620 frmt
= &(fsub
[F_PAX
]);
623 * Initialize the global extended header template.
625 tmp_name
= getenv("TMPDIR");
627 asprintf(&header_name_g
, "%s%s", tmp_name
, "/GlobalHead.%p.%n");
629 header_name_g
= "/tmp/GlobalHead.%p.%n";
633 * process the args as they are interpreted by the operation mode
638 for (; optind
< argc
; optind
++)
639 if (pat_add(argv
[optind
], NULL
) < 0)
643 if (optind
>= argc
) {
644 paxwarn(0, "Destination directory was not supplied");
652 for (; optind
< argc
; optind
++)
653 if (ftree_add(argv
[optind
], 0) < 0)
656 * no read errors allowed on updates/append operation!
666 * look at the user specified flags. set globals as required and check if
667 * the user specified a legal set of flags. If not, complain and exit
671 tar_options(int argc
, char **argv
)
677 int incfiles_max
= 0;
682 struct incfile
*incfiles
= NULL
;
685 * Set default values.
690 * process option flags
692 while ((c
= getoldopt(argc
, argv
,
693 "b:cef:hjmopqruts:vwxzBC:HI:LOPXZ014578")) != -1) {
697 * specify blocksize in 512-byte blocks
699 if ((wrblksz
= (int)str_offt(optarg
)) <= 0) {
700 paxwarn(1, "Invalid block size %s", optarg
);
703 wrblksz
*= 512; /* XXX - check for int oflow */
713 * stop after first error
719 * filename where the archive is stored
721 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
740 * use bzip2. Non standard option.
742 gzip_program
= BZIP2_CMD
;
746 * do not preserve modification time
758 * preserve uid/gid and file mode, regardless of umask
765 * select first match for a pattern only
772 * append to the archive
778 * file name substitution name pattern
780 if (rep_add(optarg
) < 0) {
787 * list contents of the tape
793 * verbose operation mode
799 * interactive file rename
805 * extract an archive, preserving mode,
806 * and mtime if possible.
813 * use gzip. Non standard option.
815 gzip_program
= GZIP_CMD
;
819 * Nothing to do here, this is pax default
828 * follow command line symlinks only
833 if (++nincfiles
> incfiles_max
) {
834 incfiles_max
= nincfiles
+ 3;
835 incfiles
= realloc(incfiles
,
836 sizeof(*incfiles
) * incfiles_max
);
837 if (incfiles
== NULL
) {
838 paxwarn(0, "Unable to allocate space "
843 incfiles
[nincfiles
- 1].file
= optarg
;
844 incfiles
[nincfiles
- 1].dir
= chdname
;
854 * do not remove leading '/' from pathnames
860 * do not pass over mount points in the file system
868 gzip_program
= COMPRESS_CMD
;
896 /* Traditional tar behaviour (pax uses stderr unless in list mode) */
897 if (fstdin
== 1 && act
== ARCHIVE
)
902 /* Traditional tar behaviour (pax wants to read file list from stdin) */
903 if ((act
== ARCHIVE
|| act
== APPND
) && argc
== 0 && nincfiles
== 0)
907 * process the args as they are interpreted by the operation mode
915 char *file
, *dir
= NULL
;
917 while (nincfiles
|| *argv
!= NULL
) {
919 * If we queued up any include files,
920 * pull them in now. Otherwise, check
921 * for -I and -C positional flags.
922 * Anything else must be a file to
926 file
= incfiles
->file
;
930 } else if (strcmp(*argv
, "-I") == 0) {
941 if (strcmp(file
, "-") == 0)
943 else if ((fp
= fopen(file
, "r")) == NULL
) {
944 paxwarn(1, "Unable to open file '%s' for read", file
);
947 while ((str
= pax_getline(fp
)) != NULL
) {
948 if (pat_add(str
, dir
) < 0)
952 if (strcmp(file
, "-") != 0)
955 paxwarn(1, "Problem with file '%s'", file
);
958 } else if (strcmp(*argv
, "-C") == 0) {
963 } else if (pat_add(*argv
++, chdname
) < 0)
969 * if patterns were added, we are doing chdir()
970 * on a file-by-file basis, else, just one
971 * global chdir (if any) after opening input.
979 frmt
= &(fsub
[Oflag
? F_OTAR
: F_TAR
]);
981 if (Oflag
== 2 && opt_add("write_opt=nodir") < 0)
984 if (chdname
!= NULL
) { /* initial chdir() */
985 if (ftree_add(chdname
, 1) < 0)
989 while (nincfiles
|| *argv
!= NULL
) {
990 char *file
, *dir
= NULL
;
993 * If we queued up any include files, pull them in
994 * now. Otherwise, check for -I and -C positional
995 * flags. Anything else must be a file to include
999 file
= incfiles
->file
;
1000 dir
= incfiles
->dir
;
1003 } else if (strcmp(*argv
, "-I") == 0) {
1004 if (*++argv
== NULL
)
1014 /* Set directory if needed */
1016 if (ftree_add(dir
, 1) < 0)
1020 if (strcmp(file
, "-") == 0)
1022 else if ((fp
= fopen(file
, "r")) == NULL
) {
1023 paxwarn(1, "Unable to open file '%s' for read", file
);
1026 while ((str
= pax_getline(fp
)) != NULL
) {
1027 if (ftree_add(str
, 0) < 0)
1030 if (strcmp(file
, "-") != 0)
1032 if (getline_error
) {
1033 paxwarn(1, "Problem with file '%s'",
1037 } else if (strcmp(*argv
, "-C") == 0) {
1038 if (*++argv
== NULL
)
1040 if (ftree_add(*argv
++, 1) < 0)
1043 } else if (ftree_add(*argv
++, 0) < 0)
1047 * no read errors allowed on updates/append operation!
1052 if (!fstdin
&& ((arcname
== NULL
) || (*arcname
== '\0'))) {
1053 arcname
= getenv("TAPE");
1054 if ((arcname
== NULL
) || (*arcname
== '\0'))
1055 arcname
= _PATH_DEFTAPE
;
1072 slash
+= strspn(slash
, "/");
1073 slash
+= strcspn(slash
, "/");
1075 done
= (*slash
== '\0');
1078 if (stat(path
, &sb
)) {
1079 if (errno
!= ENOENT
|| mkdir(path
, 0777)) {
1080 paxwarn(1, "%s", path
);
1083 } else if (!S_ISDIR(sb
.st_mode
)) {
1084 syswarn(1, ENOTDIR
, "%s", path
);
1096 * look at the user specified flags. set globals as required and check if
1097 * the user specified a legal set of flags. If not, complain and exit
1101 cpio_options(int argc
, char **argv
)
1117 while ((c
=getopt(argc
,argv
,"abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
1121 * preserve access time on files read
1127 * swap bytes and half-words when reading data
1134 frmt
= &(fsub
[F_ACPIO
]);
1138 * create directories as needed
1144 * invert meaning of pattern list
1150 * restore an archive
1156 * use bzip2. Non standard option.
1158 gzip_program
= BZIP2_CMD
;
1164 * use links instead of copies when possible
1170 * preserve modification time
1179 frmt
= &(fsub
[F_CPIO
]);
1189 * interactively rename files
1195 * swap bytes after reading data
1200 * list contents of archive
1207 * replace newer files
1213 * verbose operation mode
1219 * use gzip. Non standard option.
1221 gzip_program
= GZIP_CMD
;
1231 * Use 5120 byte block size
1237 * set block size in bytes
1239 wrblksz
= atoi(optarg
);
1243 * file with patterns to extract or list
1245 if ((fp
= fopen(optarg
, "r")) == NULL
) {
1246 paxwarn(1, "Unable to open file '%s' for read", optarg
);
1249 while ((str
= pax_getline(fp
)) != NULL
) {
1253 if (getline_error
) {
1254 paxwarn(1, "Problem with file '%s'", optarg
);
1262 * filename where the archive is stored
1264 if ((optarg
[0] == '-') && (optarg
[1]== '\0')) {
1266 * treat a - as stdin
1275 * specify an archive format on write
1278 n_fsub
= sizeof(fsub
)/sizeof(FSUB
);
1279 if ((frmt
= (FSUB
*)bsearch((void *)&tmp
, (void *)fsub
,
1280 n_fsub
, sizeof(FSUB
), c_frmt
)) != NULL
)
1282 paxwarn(1, "Unknown -H format: %s", optarg
);
1283 (void)fputs("cpio: Known -H formats are:", stderr
);
1284 for (i
= 0; i
< (sizeof(fsub
)/sizeof(FSUB
)); ++i
)
1285 (void)fprintf(stderr
, " %s", fsub
[i
].name
);
1286 (void)fputs("\n\n", stderr
);
1291 * follow symbolic links
1297 * swap halfwords after reading data
1302 * use compress. Non standard option.
1304 gzip_program
= COMPRESS_CMD
;
1308 * process Version 6 cpio format
1310 frmt
= &(fsub
[F_OCPIO
]);
1321 * process the args as they are interpreted by the operation mode
1326 while (*argv
!= NULL
)
1327 if (pat_add(*argv
++, NULL
) < 0)
1331 if (*argv
== NULL
) {
1332 paxwarn(0, "Destination directory was not supplied");
1336 if (mkpath(dirptr
) < 0)
1346 * no read errors allowed on updates/append operation!
1349 while ((str
= pax_getline(stdin
)) != NULL
) {
1352 if (getline_error
) {
1353 paxwarn(1, "Problem while reading stdin");
1365 * print out those invalid flag sets found to the user
1369 printflg(unsigned int flg
)
1374 (void)fprintf(stderr
,"%s: Invalid combination of options:", argv0
);
1375 while ((nxt
= ffs(flg
)) != 0) {
1378 (void)fprintf(stderr
, " -%c", flgch
[pos
-1]);
1380 (void)putc('\n', stderr
);
1385 * comparison routine used by bsearch to find the format specified
1390 c_frmt(const void *a
, const void *b
)
1392 return(strcmp(((const FSUB
*)a
)->name
, ((const FSUB
*)b
)->name
));
1397 * called by format specific options routines to get each format specific
1398 * flag and value specified with -o
1400 * pointer to next OPLIST entry or NULL (end of list).
1408 if ((opt
= ophead
) != NULL
)
1409 ophead
= ophead
->fow
;
1415 * generic routine used to complain about a format specific options
1416 * when the format does not support options.
1427 * print all we were given
1429 paxwarn(1,"These format options are not supported");
1430 while ((opt
= opt_next()) != NULL
) {
1431 if (opt
->separator
== SEP_EQ
) {
1432 (void)fprintf(stderr
, "\t%s = %s\n", opt
->name
, opt
->value
);
1433 } else if (opt
->separator
== SEP_COLONEQ
) {
1434 (void)fprintf(stderr
, "\t%s := %s\n", opt
->name
, opt
->value
);
1435 } else { /* SEP_NONE */
1436 (void)fprintf(stderr
, "\t%s\n", opt
->name
);
1445 * breaks the value supplied to -o into an option name and value. Options
1446 * are given to -o in the form -o name-value,name=value
1447 * multiple -o may be specified.
1449 * 0 if format in name=value format, -1 if -o is passed junk.
1453 opt_add(const char *str
)
1461 if ((str
== NULL
) || (*str
== '\0')) {
1462 paxwarn(0, "Invalid option name");
1465 if ((dstr
= strdup(str
)) == NULL
) {
1466 paxwarn(0, "Unable to allocate space for option list");
1472 * break into name and values pieces and stuff each one into a
1473 * OPLIST structure. When we know the format, the format specific
1474 * option function will go through this list
1476 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1477 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1479 if ((pt
= strchr(frpt
, '=')) == NULL
) {
1480 paxwarn(0, "Invalid options format");
1484 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1485 paxwarn(0, "Unable to allocate space for option list");
1492 opt
->separator
= SEP_EQ
;
1498 if (ophead
== NULL
) {
1499 optail
= ophead
= opt
;
1509 * pax_format_opt_add()
1510 * breaks the value supplied to -o into a option name and value. options
1511 * are given to -o in the form -o name-value,name=value
1512 * multiple -o may be specified.
1514 * 0 if format in name=value format, -1 if -o is passed junk
1518 pax_format_opt_add(register char *str
)
1520 register OPLIST
*opt
;
1521 register char *frpt
;
1523 register char *endpt
;
1524 register int separator
;
1526 if ((str
== NULL
) || (*str
== '\0')) {
1527 paxwarn(0, "Invalid option name");
1530 if ((str
= strdup(str
)) == NULL
) {
1531 paxwarn(0, "Unable to allocate space for option list");
1537 * break into name and values pieces and stuff each one into a
1538 * OPLIST structure. When we know the format, the format specific
1539 * option function will go through this list
1541 while ((frpt
!= NULL
) && (*frpt
!= '\0')) {
1542 if ((endpt
= strchr(frpt
, ',')) != NULL
)
1544 if ((pt
= strstr(frpt
, ":=")) != NULL
) {
1546 pt
++; /* beyond the := */
1547 separator
= SEP_COLONEQ
;
1548 } else if ((pt
= strchr(frpt
, '=')) != NULL
) {
1552 /* keyword with no value */
1553 separator
= SEP_NONE
;
1555 if ((opt
= (OPLIST
*)malloc(sizeof(OPLIST
))) == NULL
) {
1556 paxwarn(0, "Unable to allocate space for option list");
1562 opt
->separator
= separator
;
1568 if (ophead
== NULL
) {
1569 optail
= ophead
= opt
;
1580 * Convert an expression of the following forms to an off_t > 0.
1581 * 1) A positive decimal number.
1582 * 2) A positive decimal number followed by a b (mult by 512).
1583 * 3) A positive decimal number followed by a k (mult by 1024).
1584 * 4) A positive decimal number followed by a m (mult by 512).
1585 * 5) A positive decimal number followed by a w (mult by sizeof int)
1586 * 6) Two or more positive decimal numbers (with/without k,b or w).
1587 * separated by x (also * for backwards compatibility), specifying
1588 * the product of the indicated values.
1590 * 0 for an error, a positive value o.w.
1600 num
= strtol(val
, &expr
, 0);
1601 if ((num
== LONG_MAX
) || (num
<= 0) || (expr
== val
))
1603 num
= strtoq(val
, &expr
, 0);
1604 if ((num
== QUAD_MAX
) || (num
<= 0) || (expr
== val
))
1645 num
*= str_offt(expr
+ 1);
1656 pax_getline(FILE *f
)
1661 name
= fgetln(f
, &len
);
1663 getline_error
= ferror(f
) ? GETLINE_FILE_CORRUPT
: 0;
1666 if (name
[len
-1] != '\n')
1670 getline_error
= GETLINE_OUT_OF_MEM
;
1673 memcpy(temp
, name
, len
-1);
1680 * for those option functions where the archive format has nothing to do.
1693 * print the usage summary to the user
1700 "usage: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s replstr]\n"
1701 " [-T range] [-U user] [--insecure] [pattern ...]\n"
1702 " pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G group] [-o options]\n"
1703 " [-p string] [-s replstr] [-T range] [-U user] [--insecure] [pattern ...]\n"
1704 " pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1705 " [-G group] [-o options] [-s replstr] [-T range] [-U user]\n"
1706 " [-x format] [--insecure] [file ...]\n"
1707 " pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1708 " [-T range] [-U user] [--insecure] [file ...] directory\n",
1715 * print the usage summary to the user
1722 "usage: tar {crtux}[014578befHhjLmOoPpqsvwXZz]\n"
1723 " [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
1725 " tar {-crtux} [-014578eHhjLmOoPpqvwXZz] [-b blocking-factor]\n"
1726 " [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
1733 * print the usage summary to the user
1740 "usage: cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format]\n"
1741 " [-O archive] < name-list [> archive]\n"
1742 " cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]\n"
1743 " [-I archive] [pattern ...] [< archive]\n"
1744 " cpio -p [-adLlmuv] destination-directory < name-list\n",