comparison nt/minitar.c @ 464:5aa1854ad537 r21-2-47

Import from CVS: tag r21-2-47
author cvs
date Mon, 13 Aug 2007 11:45:51 +0200
parents 84b14dcb0985
children 02f7a782086f
comparison
equal deleted inserted replaced
463:a158004111cd 464:5aa1854ad537
12 If it breaks, you get to keep both pieces */ 12 If it breaks, you get to keep both pieces */
13 13
14 14
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <errno.h> 16 #include <errno.h>
17 #include <string.h>
18 #include <io.h>
17 19
18 #include <zlib.h> 20 #include <zlib.h>
19 21
22 static int
20 Usage(char *name) 23 Usage(char *name)
21 { 24 {
22 fprintf(stderr,"Usage: %s file.tar.gz [base-dir]\n",name); 25 fprintf(stderr,"Usage: %s file.tar.gz [base-dir]\n",name);
23 fprintf(stderr,"\tExtracts the contents compressed tar file to base-dir\n"); 26 fprintf(stderr,"\tExtracts the contents compressed tar file to base-dir\n");
24 exit(-1); 27 exit(-1);
26 29
27 30
28 #define BLOCKSIZE 512 31 #define BLOCKSIZE 512
29 #define MAXNAMELEN 1024 32 #define MAXNAMELEN 1024
30 33
31 int octal(char *str) 34 static int
35 octal(char *str)
32 { 36 {
33 int ret = -1; 37 int ret = -1;
34 sscanf(str,"%o",&ret); 38 sscanf(str,"%o",&ret);
35 return ret; 39 return ret;
36 } 40 }
37 41
38 /* this is like mkdir -p, except if there is no trailing slash, 42 /* this is like mkdir -p, except if there is no trailing slash,
39 the final component is assumed to be a file, rather than a 43 the final component is assumed to be a file, rather than a
40 path component, so it is not created as a directory */ 44 path component, so it is not created as a directory */
41 45
42 int makepath(char *path) 46 static int
47 makepath(char *path)
43 { 48 {
44 char tmp[MAXNAMELEN]; 49 char tmp[MAXNAMELEN];
45 char *cp; 50 char *cp;
46 51
47 for (cp=path; cp; cp = (char*)strchr(cp+1,'/')){ 52 for (cp=path; cp; cp = (char*)strchr(cp+1,'/')){
51 continue; 56 continue;
52 strncpy(tmp, path, cp-path); 57 strncpy(tmp, path, cp-path);
53 tmp[cp-path] = '\0'; 58 tmp[cp-path] = '\0';
54 if (strlen(tmp) == 0) 59 if (strlen(tmp) == 0)
55 continue; 60 continue;
61 #ifdef WIN32_NATIVE
62 if (mkdir(tmp)){
63 #else
56 if (mkdir(tmp,0777)){ 64 if (mkdir(tmp,0777)){
65 #endif
57 if (errno == EEXIST) 66 if (errno == EEXIST)
58 continue; 67 continue;
59 else 68 else
60 return -1; 69 return -1;
61 } 70 }
64 } 73 }
65 74
66 75
67 76
68 77
78 int
69 main(int argc, char **argv) 79 main(int argc, char **argv)
70 { 80 {
71 char fullname[MAXNAMELEN]; 81 char fullname[MAXNAMELEN];
72 char *basedir = "."; 82 char *basedir = ".";
73 char *tarfile; 83 char *tarfile;
74 char *cp;
75 int size; 84 int size;
76 char osize[13]; 85 char osize[13];
77 char name[101]; 86 char name[101];
78 char magic[7]; 87 char magic[7];
79 char type; 88 char type;