17 #include <sys/types.h>
32 # define mkdir(dirname,mode) _mkdir(dirname)
33 # define strdup(str) _strdup(str)
34 # define unlink(fn) _unlink(fn)
35 # define access(path,mode) _access(path,mode)
37 # define mkdir(dirname,mode) _mkdir(dirname)
86 void TGZnotfound
OF((
const char *));
96 int tar
OF((
gzFile,
int,
int,
int,
char **));
99 int main OF((
int,
char **));
112 void TGZnotfound
OF((
const char *fname))
116 fprintf(stderr,
"%s : couldn't find ",prog);
117 for (i=0;TGZprefix[i];i++)
118 fprintf(stderr,(TGZprefix[i+1]) ?
"%s%s, " :
"or %s%s\n",
139 result = result * 8 + (c -
'0');
149 local = localtime(t);
150 sprintf(result,
"%2d/%02d/%4d %02d:%02d:%02d",
151 local->tm_mday, local->tm_mon+1, local->tm_year+1900,
152 local->tm_hour, local->tm_min, local->tm_sec);
159 #define ISSPECIAL(c) (((c) == '*') || ((c) == '/'))
169 if (*
string !=
'\\' && *
string !=
'/')
173 else if (*expr ==
'*')
177 while (*++
string != *expr)
184 if (*
string != *expr)
202 char *
buffer = strdup(newdir);
204 int len = (int)strlen(buffer);
210 if (buffer[len-1] ==
'/') {
211 buffer[len-1] =
'\0';
213 if (mkdir(buffer, 0775) == 0)
224 while(*p && *p !=
'\\' && *p !=
'/')
228 if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT))
230 fprintf(stderr,
"%s: couldn't create directory %s\n",prog,buffer);
242 int matchname (
int arg,
int argc,
char **argv,
char *fname)
258 union tar_buffer buffer;
263 FILE *outfile =
NULL;
276 error(
"gzread: incomplete block read");
281 if (getheader == 1) {
287 if ((len == 0) || (buffer.header.name[0]== 0))
break;
289 tartime = (time_t)
getoct(buffer.header.mtime,12);
291 if ((fname[strlen(fname)-1] !=
'/') && (fname[strlen(fname)-1] !=
'\\'))
293 strcat(fname, buffer.header.name);
295 switch (buffer.header.typeflag) {
301 remaining =
getoct(buffer.header.size,12);
303 outfile = fopen(fname,
"wb");
304 if (outfile ==
NULL) {
306 char *p = strrchr(fname,
'/');
311 outfile = fopen(fname,
"wb");
326 getheader = (remaining) ? 0 : 1;
335 if (outfile !=
NULL) {
336 if (fwrite(&buffer,
sizeof(
char),bytes,outfile) != bytes) {
337 fprintf(stderr,
"%s : error writing %s skipping...\n",prog,fname);
343 if (remaining == 0) {
345 if (outfile !=
NULL) {
348 FILETIME ftm,ftLocal;
354 localt = *localtime(&tartime);
356 hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
359 st.wYear = (WORD)localt.tm_year+1900;
360 st.wMonth = (WORD)localt.tm_mon;
361 st.wDayOfWeek = (WORD)localt.tm_wday;
362 st.wDay = (WORD)localt.tm_mday;
363 st.wHour = (WORD)localt.tm_hour;
364 st.wMinute = (WORD)localt.tm_min;
365 st.wSecond = (WORD)localt.tm_sec;
366 st.wMilliseconds = 0;
367 SystemTimeToFileTime(&st,&ftLocal);
368 LocalFileTimeToFileTime(&ftLocal,&ftm);
369 SetFileTime(hFile,&ftm,
NULL,&ftm);
374 struct utimbuf settime;
376 settime.actime = settime.modtime = tartime;
380 utime(fname,&settime);
396 " an sample application of zlib 1.0.4\n\n"
397 "Usage : untgz TGZfile to extract all files\n"
398 " untgz TGZfile fname ... to extract selected files\n"
399 " untgz -l TGZfile to list archive contents\n"
400 " untgz -h to display this help\n\n");
406 fprintf(stderr,
"%s: %s\n", prog, msg);
416 fprintf(stderr,
"%s: Couldn't gzopen file\n", prog);
420 return untar(f, dest);
int matchname(int arg, int argc, char **argv, char *fname)
int makedir(char *newdir)
static char * TGZprefix[]
char * strtime(time_t *t)
void error(const char *msg)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
int getoct(char *p, int width)
int ExprMatch(char *string, char *expr)
int untargz(int fd, const char *dest)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
int untar(gzFile in, const char *dest)