]> git.lizzy.rs Git - plan9front.git/blob - sys/src/ape/cmd/pax/cpio.c
ape: bring strtod() in line with plan9's libc version
[plan9front.git] / sys / src / ape / cmd / pax / cpio.c
1 /* $Source: /u/mark/src/pax/RCS/cpio.c,v $
2  *
3  * $Revision: 1.2 $
4  *
5  * cpio.c - Cpio specific functions for archive handling
6  *
7  * DESCRIPTION
8  *
9  *      These function provide a cpio conformant interface to the pax
10  *      program.
11  *
12  * AUTHOR
13  *
14  *     Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
15  *
16  * Sponsored by The USENIX Association for public distribution. 
17  *
18  * Copyright (c) 1989 Mark H. Colburn.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms are permitted
22  * provided that the above copyright notice is duplicated in all such 
23  * forms and that any documentation, advertising materials, and other 
24  * materials related to such distribution and use acknowledge that the 
25  * software was developed * by Mark H. Colburn and sponsored by The 
26  * USENIX Association. 
27  *
28  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
29  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31  *
32  * $Log:        cpio.c,v $
33  * Revision 1.2  89/02/12  10:04:13  mark
34  * 1.2 release fixes
35  * 
36  * Revision 1.1  88/12/23  18:02:05  mark
37  * Initial revision
38  * 
39  */
40
41 #ifndef lint
42 static char *ident = "$Id: cpio.c,v 1.2 89/02/12 10:04:13 mark Exp $";
43 static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
44 #endif /* ! lint */
45
46
47 /* Headers */
48
49 #include "pax.h"
50
51
52 /* Function Prototypes */
53
54 #ifdef __STDC__
55 static void     usage(void);
56 #else /* !__STDC__ */
57 static void     usage();
58 #endif /* __STDC__ */
59
60
61 /* do_cpio - handle cpio format archives
62  *
63  * DESCRIPTION
64  *
65  *      Do_cpio provides a standard CPIO interface to the PAX program.  All
66  *      of the standard cpio flags are available, and the behavior of the
67  *      program mimics traditonal cpio.
68  *
69  * PARAMETERS
70  *
71  *      int     argc    - command line argument count
72  *      char    **argv  - pointer to command line arguments
73  *
74  * RETURNS
75  *
76  *      Nothing.
77  */
78
79 #ifdef __STDC__
80
81 int do_cpio(int argc, char **argv)
82
83 #else
84
85 int do_cpio(argc, argv)
86 int             argc;
87 char          **argv;
88
89 #endif
90 {
91     int             c;
92     char           *dirname;
93     Stat            st;
94
95     /* default input/output file for CPIO is STDIN/STDOUT */
96     ar_file = "-";
97     names_from_stdin = 1;
98
99     /* set up the flags to reflect the default CPIO inteface. */
100     blocksize = BLOCKSIZE;
101     ar_interface = CPIO;
102     ar_format = CPIO;
103     msgfile=stderr;
104
105     while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
106         switch (c) {
107         case 'i':
108             f_extract = 1;
109             break;
110         case 'o':
111             f_create = 1;
112             break;
113         case 'p':
114             f_pass = 1;
115             dirname = argv[--argc];
116
117             /* check to make sure that the argument is a directory */
118             if (LSTAT(dirname, &st) < 0) {
119                 fatal(strerror());
120             }
121             if ((st.sb_mode & S_IFMT) != S_IFDIR) {
122                 fatal("Not a directory");
123             }
124             break;
125         case 'B':
126             blocksize = BLOCK;
127             break;
128         case 'a':
129             f_access_time = 1;
130             break;
131         case 'c':
132             break;
133         case 'D':
134             ar_file = optarg;
135             break;
136         case 'd':
137             f_dir_create = 1;
138             break;
139         case 'f':
140             f_reverse_match = 1;
141             break;
142         case 'l':
143             f_link = 1;
144             break;
145         case 'm':
146             f_mtime = 1;
147             break;
148         case 'r':
149             f_interactive = 1;
150             break;
151         case 't':
152             f_list = 1;
153             break;
154         case 'u':
155             f_unconditional = 1;
156             break;
157         case 'v':
158             f_verbose = 1;
159             break;
160         default:
161             usage();
162         }
163     }
164
165     if (f_create + f_pass + f_extract != 1) {
166         usage();
167     }
168     if (!f_pass) {
169         buf_allocate((OFFSET) blocksize);
170     }
171     if (f_extract) {
172         open_archive(AR_READ);  /* Open for reading */
173         read_archive();
174     } else if (f_create) {
175         open_archive(AR_WRITE);
176         create_archive();
177     } else if (f_pass) {
178         pass(dirname);
179     }
180
181     /* print out the total block count transfered */
182     fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
183     
184     exit(0);
185     /* NOTREACHED */
186 }
187
188
189 /* usage - print a helpful message and exit
190  *
191  * DESCRIPTION
192  *
193  *      Usage prints out the usage message for the CPIO interface and then
194  *      exits with a non-zero termination status.  This is used when a user
195  *      has provided non-existant or incompatible command line arguments.
196  *
197  * RETURNS
198  *
199  *      Returns an exit status of 1 to the parent process.
200  *
201  */
202
203 #ifdef __STDC__
204
205 static void usage(void)
206
207 #else
208
209 static void usage()
210
211 #endif
212 {
213     fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
214     fprintf(stderr, "       %s -i[Bcdmrtuvf] [pattern...]\n", myname);
215     fprintf(stderr, "       %s -p[adlmruv] directory\n", myname);
216     exit(1);
217 }