aboutsummaryrefslogtreecommitdiff
path: root/archival/ar.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 14:50:04 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 14:50:04 +0000
commite2b345a6d8269048e2a310de70234b28745c42c1 (patch)
tree405335677a6dde5f184d81e000ef7a4eb0c90770 /archival/ar.c
parent437bf72785cdd8c9d689c241a94c79f1f71a2354 (diff)
downloadbusybox-w32-e2b345a6d8269048e2a310de70234b28745c42c1.tar.gz
busybox-w32-e2b345a6d8269048e2a310de70234b28745c42c1.tar.bz2
busybox-w32-e2b345a6d8269048e2a310de70234b28745c42c1.zip
Implemented new ar functionality unique to busybox ar (i think), the -R
option enable a Recursive extraction (or listing) to take place. i.e. if any files being extracted are themselves ar archives then busybox ar will extract their contents as well. e.g. take bar.deb and do (with GNU ar) ar -q foo.deb b.ar then with busybox ar can do ar -x b.ar data.tar.gz -R isnt used for anything in GNU ar so i think it should be ok, could have used long options This functionality will become (more) usufull with tar, gz support.
Diffstat (limited to 'archival/ar.c')
-rw-r--r--archival/ar.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 41750ac7c..5803ad1a7 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -43,6 +43,7 @@
43#define DISPLAY 4 /* display contents */ 43#define DISPLAY 4 /* display contents */
44#define EXT_TO_FILE 8 /* extract contents of archive */ 44#define EXT_TO_FILE 8 /* extract contents of archive */
45#define EXT_TO_STDOUT 16 /* extract to stdout */ 45#define EXT_TO_STDOUT 16 /* extract to stdout */
46#define RECURSIVE 32
46 47
47#define MAX_NAME_LENGTH 100 48#define MAX_NAME_LENGTH 100
48 49
@@ -168,34 +169,26 @@ static int readArEntry(int srcFd, headerL_t *newEntry)
168/* 169/*
169 * return the headerL_t struct for the specified filename 170 * return the headerL_t struct for the specified filename
170 */ 171 */
171static headerL_t *getHeaders(int srcFd, headerL_t *head) 172static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
172{ 173{
173 int arEntry=FALSE;
174 headerL_t *list; 174 headerL_t *list;
175 list = (headerL_t *) malloc(sizeof(headerL_t)); 175 list = (headerL_t *) malloc(sizeof(headerL_t));
176 176
177 if (checkArMagic(srcFd)==TRUE) 177 if (checkArMagic(srcFd)==TRUE) {
178 arEntry=TRUE; 178 printf("found ar header ");
179 else
180 errorMsg("isnt an ar archive\n");
181
182 if (arEntry==TRUE) {
183 while(readArEntry(srcFd, list) == TRUE) { 179 while(readArEntry(srcFd, list) == TRUE) {
184 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 180 list->next = (headerL_t *) malloc(sizeof(headerL_t));
185 *list->next = *head; 181 *list->next = *head;
186 *head = *list; 182 *head = *list;
187 183
188 /* recursive check for sub-archives */ 184 /* recursive check for sub-archives */
189 lseek(srcFd, list->size, SEEK_CUR); 185 if ((funct & RECURSIVE) == RECURSIVE)
190/* printf("checking for sub headers\n"); 186 head = getHeaders(srcFd, head, funct);
191 if ((subList = getHeaders(srcFd, list->next)) != NULL) { 187 lseek(srcFd, head->offset + head->size, SEEK_SET);
192 printf("found a sub archive !\n");
193 }
194 else
195 printf("didnt find a sub header\n"); */
196 } 188 }
197 } 189 }
198 190 else
191 printf("not an ar header\n");
199 return(head); 192 return(head);
200} 193}
201 194
@@ -239,7 +232,7 @@ extern int ar_main(int argc, char **argv)
239 int srcFd=0, dstFd=0; 232 int srcFd=0, dstFd=0;
240 headerL_t *header, *entry, *extractList; 233 headerL_t *header, *entry, *extractList;
241 234
242 while ((opt = getopt(argc, argv, "ovtpx")) != -1) { 235 while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
243 switch (opt) { 236 switch (opt) {
244 case 'o': 237 case 'o':
245 funct = funct | PRESERVE_DATE; 238 funct = funct | PRESERVE_DATE;
@@ -256,6 +249,9 @@ extern int ar_main(int argc, char **argv)
256 case 'p': 249 case 'p':
257 funct = funct | EXT_TO_STDOUT; 250 funct = funct | EXT_TO_STDOUT;
258 break; 251 break;
252 case 'R':
253 funct = funct | RECURSIVE;
254 break;
259 default: 255 default:
260 usage(ar_usage); 256 usage(ar_usage);
261 } 257 }
@@ -276,7 +272,7 @@ extern int ar_main(int argc, char **argv)
276 header = (headerL_t *) malloc(sizeof(headerL_t)); 272 header = (headerL_t *) malloc(sizeof(headerL_t));
277 extractList = (headerL_t *) malloc(sizeof(headerL_t)); 273 extractList = (headerL_t *) malloc(sizeof(headerL_t));
278 274
279 header = getHeaders(srcFd, header); 275 header = getHeaders(srcFd, header, funct);
280 276
281 /* find files to extract or display */ 277 /* find files to extract or display */
282 if (optind<argc) { 278 if (optind<argc) {