29# define mkdir(dirname,mode) _mkdir(dirname)
31# define access(path,mode) _access(path,mode)
32# define chmod(path,mode) _chmod(path,mode)
33# define strdup(str) _strdup(str)
54#define GNUTYPE_DUMPDIR 'D'
55#define GNUTYPE_LONGLINK 'K'
56#define GNUTYPE_LONGNAME 'L'
57#define GNUTYPE_MULTIVOL 'M'
58#define GNUTYPE_NAMES 'N'
59#define GNUTYPE_SPARSE 'S'
60#define GNUTYPE_VOLHDR 'V'
66#define SHORTNAMESIZE 100
134 static char buffer[1024];
137 strcpy(buffer,arcname);
156 fprintf(stderr,
"%s: Couldn't find ",
prog);
158 fprintf(stderr,(
TGZsuffix[i+1]) ?
"%s%s, " :
"or %s%s\n",
180 if (c < '0' || c >
'7')
182 result = result * 8 + (c -
'0');
194 static char result[32];
197 sprintf(result,
"%4d/%02d/%02d %02d:%02d:%02d",
209 static int isWinNT = -1;
211 FILETIME locft, modft;
216 loctm = localtime(&ftime);
220 st.wYear = (WORD)loctm->tm_year + 1900;
221 st.wMonth = (WORD)loctm->tm_mon + 1;
222 st.wDayOfWeek = (WORD)loctm->tm_wday;
223 st.wDay = (WORD)loctm->tm_mday;
224 st.wHour = (WORD)loctm->tm_hour;
225 st.wMinute = (WORD)loctm->tm_min;
226 st.wSecond = (WORD)loctm->tm_sec;
227 st.wMilliseconds = 0;
228 if (!SystemTimeToFileTime(&st, &locft) ||
229 !LocalFileTimeToFileTime(&locft, &modft))
233 isWinNT = (GetVersion() < 0x80000000) ? 1 : 0;
234 hFile = CreateFile(fname, GENERIC_WRITE, 0,
NULL, OPEN_EXISTING,
235 (isWinNT ? FILE_FLAG_BACKUP_SEMANTICS : 0),
239 result = SetFileTime(hFile,
NULL,
NULL, &modft) ? 0 : -1;
246 return utime(fname,&settime);
259 error(
"Out of memory");
274 for (item = *list; item !=
NULL; )
288#define ISSPECIAL(c) (((c) == '*') || ((c) == '/'))
298 if (*
string !=
'\\' && *
string !=
'/')
302 else if (*expr ==
'*')
306 while (*++
string != *expr)
313 if (*
string != *expr)
330 char *buffer =
strdup(newdir);
338 if (buffer[
len-1] ==
'/') {
339 buffer[
len-1] =
'\0';
341 if (mkdir(buffer, 0755) == 0)
352 while(*p && *p !=
'\\' && *p !=
'/')
356 if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT))
358 fprintf(stderr,
"%s: Couldn't create directory %s\n",
prog,buffer);
400 printf(
" date time size file\n"
401 " ---------- -------- --------- -------------------------------------\n");
432 if (tarmode == -1 || tartime == (time_t)-1)
450 error(
"bad long name");
477 printf(
" %s %9d %s\n",
strtime(&tartime),remaining,
fname);
482 outfile = fopen(
fname,
"wb");
483 if (outfile ==
NULL) {
490 outfile = fopen(
fname,
"wb");
494 printf(
"Extracting %s\n",
fname);
496 fprintf(stderr,
"%s: Couldn't create %s",
prog,
fname);
506 if (remaining < 0 || remaining >=
BLOCKSIZE)
533 if (fwrite(&buffer,
sizeof(
char),bytes,outfile) != bytes)
536 "%s: Error writing %s -- skipping\n",
prog,
fname);
562 error(
"broken archive");
573 error(
"failed gzclose");
583 printf(
"untgz version 0.2.1\n"
584 " using zlib version %s\n\n",
586 printf(
"Usage: untgz file.tgz extract all files\n"
587 " untgz file.tgz fname ... extract selected files\n"
588 " untgz -l file.tgz list archive contents\n"
589 " untgz -h display this help\n");
595 fprintf(stderr,
"%s: %s\n",
prog, msg);
602#if defined(WIN32) && defined(__GNUC__)
634 if (strcmp(
argv[arg],
"-l") == 0)
640 else if (strcmp(
argv[arg],
"-h") == 0)
662 fprintf(stderr,
"%s: Couldn't gzopen %s\n",
prog,TGZfile);
669 error(
"Unknown option");
char * strrchr(const char *, const char)
unsigned in(void *in_desc, z_const unsigned char **buf)
int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
const char *ZEXPORT gzerror(gzFile file, int *errnum)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
#define INVALID_HANDLE_VALUE
size_t strlen(const char *)
char * strtime(time_t *t)
void TGZnotfound(const char *arcname)
int setfiletime(char *fname, time_t ftime)
int getoct(char *p, int width)
void error(const char *msg)
int tar(gzFile in, int action, int arg, int argc, char **argv)
int makedir(char *newdir)
char * TGZfname(const char *arcname)
void restore_attr(struct attr_item **list)
int matchname(int arg, int argc, char **argv, char *fname)
int ExprMatch(char *string, char *expr)
void push_attr(struct attr_item **list, char *fname, int mode, time_t time)
#define access(path, mode)
if((ID)(DISPID) nameid !=nameid)
const char *ZEXPORT zlibVersion()