annotate nt/minitar.c @ 5334:b249c479f9e1

Replace some C++ comments with C89-style /* */ comments, mc-alloc.c 2011-01-10 Aidan Kehoe <kehoea@parhasard.net> * mc-alloc.c (get_used_list_index): Replace some C++ comments with C-style /* comments.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 10 Jan 2011 20:00:57 +0000
parents b694dfd2f40e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
1
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
2 /* Minitar: extract .tar.gz files on Win32 platforms.
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
3 Uses zlib for decompression.
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
4
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
5 This is very simple-minded, it ignores checksums, and any type of file
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
6 that is not a plain file or a directory. Nonetheless it is useful.
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
7
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
8 Author: Charles G. Waldman (cgw@pgt.com), Aug 4 1998
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
9
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
10 This file is placed in the public domain; you can
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
11 do whatever you like with it. There is NO WARRANTY.
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
12 If it breaks, you get to keep both pieces */
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
13
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
14
2951
b694dfd2f40e [xemacs-hg @ 2005-09-26 08:13:00 by ben]
ben
parents: 1782
diff changeset
15 #ifdef HAVE_CONFIG_H
b694dfd2f40e [xemacs-hg @ 2005-09-26 08:13:00 by ben]
ben
parents: 1782
diff changeset
16 # include <config.h>
b694dfd2f40e [xemacs-hg @ 2005-09-26 08:13:00 by ben]
ben
parents: 1782
diff changeset
17 #endif
b694dfd2f40e [xemacs-hg @ 2005-09-26 08:13:00 by ben]
ben
parents: 1782
diff changeset
18
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
19 #include <stdio.h>
812
f846c2ef930d [xemacs-hg @ 2002-04-13 20:31:27 by jhar]
jhar
parents: 495
diff changeset
20 #include <stdlib.h>
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 434
diff changeset
21 #include <errno.h>
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
22 #include <string.h>
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
23 #include <io.h>
812
f846c2ef930d [xemacs-hg @ 2002-04-13 20:31:27 by jhar]
jhar
parents: 495
diff changeset
24 #ifdef WIN32_NATIVE
f846c2ef930d [xemacs-hg @ 2002-04-13 20:31:27 by jhar]
jhar
parents: 495
diff changeset
25 # include <direct.h> /* For mkdir */
f846c2ef930d [xemacs-hg @ 2002-04-13 20:31:27 by jhar]
jhar
parents: 495
diff changeset
26 #endif
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
27
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
28 #include <zlib.h>
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
29
1782
f5967016f79a [xemacs-hg @ 2003-11-06 22:53:31 by adrian]
adrian
parents: 1529
diff changeset
30 static void
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
31 Usage (char *name)
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
32 {
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
33 fprintf (stderr, "Usage: %s file.tar.gz [base-dir]\n", name);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
34 fprintf (stderr, "\tExtracts the contents compressed tar file to base-dir\n");
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
35 exit (-1);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
36 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
37
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
38
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
39 #define BLOCKSIZE 512
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
40 #define MAXNAMELEN 1024
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
41
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
42 static int
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
43 octal (char *str)
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
44 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
45 int ret = -1;
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
46 sscanf (str, "%o", &ret);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
47 return ret;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
48 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
49
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
50 /* this is like mkdir -p, except if there is no trailing slash,
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
51 the final component is assumed to be a file, rather than a
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
52 path component, so it is not created as a directory */
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
53
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
54 static int
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
55 makepath (char *path)
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
56 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
57 char tmp[MAXNAMELEN];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
58 char *cp;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
59
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
60 for (cp=path; cp; cp = (char*)strchr (cp+1, '/'))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
61 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
62 if (!*cp)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
63 break;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
64 if (*cp != '/')
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
65 continue;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
66 strncpy (tmp, path, cp-path);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
67 tmp[cp-path] = '\0';
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
68 if (strlen (tmp) == 0)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
69 continue;
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
70 #ifdef WIN32_NATIVE
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
71 if (mkdir (tmp))
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
72 #else
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
73 if (mkdir (tmp, 0777))
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
74 #endif
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
75 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
76 if (errno == EEXIST)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
77 continue;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
78 else
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
79 return -1;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
80 }
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
81 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
82 return 0;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
83 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
84
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
85
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
86
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 438
diff changeset
87 int
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
88 main (int argc, char **argv)
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
89 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
90 char fullname[MAXNAMELEN];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
91 char *basedir = ".";
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
92 char *tarfile;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
93 int size;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
94 char osize[13];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
95 char name[101];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
96 char magic[7];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
97 char type;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
98
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
99 gzFile *infile = (gzFile*)0;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
100 FILE *outfile = (FILE*)0;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
101
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
102 char block[BLOCKSIZE];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
103 int nbytes, nread, nwritten;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
104
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
105 int in_block = 0;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
106 int directory = 0;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
107
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
108 if (argc < 2 || argc > 3)
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
109 Usage (argv[0]);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
110
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
111 tarfile = argv[1];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
112 if (argc==3)
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
113 basedir = argv[2];
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
114
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
115 if (! (infile = gzopen (tarfile, "rb")))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
116 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
117 fprintf (stderr, "Cannot open %s\n", tarfile);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
118 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
119 }
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
120
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
121 while (1)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
122 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
123 nread = gzread (infile, block, 512);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
124
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
125 if (!in_block && nread == 0)
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
126 break;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
127
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
128 if (nread != BLOCKSIZE)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
129 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
130 fprintf (stderr, "Error: incomplete block read. Exiting.\n");
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
131 exit (-2);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
132 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
133
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
134 if (!in_block)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
135 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
136 if (block[0]=='\0') /* We're done */
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
137 break;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
138
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
139 strncpy (magic, block+257, 6);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
140 magic[6] = '\0';
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
141 if (strcmp (magic, "ustar "))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
142 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
143 fprintf (stderr,
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
144 "Error: incorrect magic number in tar header. Exiting\n");
1529
d4c017f833e2 [xemacs-hg @ 2003-06-15 13:25:46 by adrian]
adrian
parents: 812
diff changeset
145 exit (-2);
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
146 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
147
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
148 strncpy (name, block, 100);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
149 name[100] = '\0';
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
150 sprintf (fullname, "%s/%s", basedir, name);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
151 printf ("%s\n", fullname);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
152 type = block[156];
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
153
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
154 switch (type)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
155 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
156 case '0':
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
157 case '\0':
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
158 directory = 0;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
159 break;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
160 case '5':
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
161 directory = 1;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
162 break;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
163 default:
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
164 fprintf (stderr, "Error: unknown type flag %c. Exiting.\n", type);
1529
d4c017f833e2 [xemacs-hg @ 2003-06-15 13:25:46 by adrian]
adrian
parents: 812
diff changeset
165 exit (-2);
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
166 break;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
167 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
168
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
169 if (directory)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
170 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
171 in_block = 0;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
172
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
173 /* makepath will ignore the final path component, so make sure
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
174 dirnames have a trailing slash */
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
175
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
176 if (fullname[strlen (fullname)-1] != '/')
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
177 strcat (fullname, "/");
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
178 if (makepath (fullname))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
179 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
180 fprintf (stderr, "Error: cannot create directory %s. Exiting.\n",
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
181 fullname);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
182 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
183 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
184 continue;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
185 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
186 else
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
187 { /*file */
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
188 in_block = 1;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
189 if (outfile)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
190 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
191 if (fclose (outfile))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
192 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
193 fprintf (stderr, "Error: cannot close file %s. Exiting.\n",
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
194 fullname);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
195 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
196 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
197 outfile = (FILE*)0;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
198 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
199
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
200 if (!(outfile = fopen (fullname, "wb")))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
201 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
202 /*try creating the directory, maybe it's not there */
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
203 if (makepath (fullname))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
204 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
205 fprintf (stderr, "Error: cannot create file %s. Exiting.\n",
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
206 fullname);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
207 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
208 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
209 /* now try again to open the file */
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
210 if (!(outfile = fopen (fullname, "wb")))
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
211 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
212 fprintf (stderr, "Error: cannot create file %s. Exiting.\n",
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
213 fullname);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
214 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
215 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
216 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
217
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
218 strncpy (osize, block+124, 12);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
219 osize[12] = '\0';
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
220 size = octal (osize);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
221 if (size<0)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
222 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
223 fprintf (stderr, "Error: invalid size in tar header. Exiting.\n");
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
224 exit (-2);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
225 }
1529
d4c017f833e2 [xemacs-hg @ 2003-06-15 13:25:46 by adrian]
adrian
parents: 812
diff changeset
226 if (size==0) /* file of size 0 is done */
d4c017f833e2 [xemacs-hg @ 2003-06-15 13:25:46 by adrian]
adrian
parents: 812
diff changeset
227 in_block = 0;
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
228 }
1782
f5967016f79a [xemacs-hg @ 2003-11-06 22:53:31 by adrian]
adrian
parents: 1529
diff changeset
229 }
f5967016f79a [xemacs-hg @ 2003-11-06 22:53:31 by adrian]
adrian
parents: 1529
diff changeset
230 else
f5967016f79a [xemacs-hg @ 2003-11-06 22:53:31 by adrian]
adrian
parents: 1529
diff changeset
231 { /* write or continue writing file contents */
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
232 nbytes = size>512? 512:size;
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
233
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
234 nwritten = fwrite (block, 1, nbytes, outfile);
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
235 if (nwritten != nbytes)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
236 {
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
237 fprintf (stderr, "Error: only wrote %d bytes to file %s. Exiting.\n",
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
238 nwritten, fullname);
1529
d4c017f833e2 [xemacs-hg @ 2003-06-15 13:25:46 by adrian]
adrian
parents: 812
diff changeset
239 exit (-2);
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
240 }
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
241 size -= nbytes;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
242 if (size==0)
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
243 in_block = 0;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
244 }
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
245 }
495
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
246 return 0;
02f7a782086f [xemacs-hg @ 2001-05-01 09:36:44 by ben]
ben
parents: 464
diff changeset
247 }
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
248
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
249
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents:
diff changeset
250