From 14763ac7c6c03bca62c39e35c03cf5bfc7728802 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 23:20:29 -0700 Subject: zlib 1.1.3 --- contrib/untgz/untgz.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'contrib/untgz') diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c index 6fa9a5d..4a431ff 100644 --- a/contrib/untgz/untgz.c +++ b/contrib/untgz/untgz.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #ifdef unix @@ -21,6 +20,23 @@ #include "zlib.h" +#ifdef WIN32 +# ifndef F_OK +# define F_OK (0) +# endif +# ifdef _MSC_VER +# define mkdir(dirname,mode) _mkdir(dirname) +# define strdup(str) _strdup(str) +# define unlink(fn) _unlink(fn) +# define access(path,mode) _access(path,mode) +# else +# define mkdir(dirname,mode) _mkdir(dirname) +# endif +#else +# include +#endif + + /* Values used in typeflag field. */ #define REGTYPE '0' /* regular file */ @@ -83,7 +99,7 @@ char *prog; /* This will give a benign warning */ -static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", NULL }; +static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar", NULL }; /* Return the real name of the TGZ archive */ /* or NULL if it does not exist. */ @@ -271,14 +287,6 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) len = gzread(in, &buffer, BLOCKSIZE); if (len < 0) error (gzerror(in, &err)); - /* - * if we met the end of the tar - * or the end-of-tar block, - * we are done - */ - if ((len == 0) || (buffer.header.name[0]== 0)) - break; - /* * Always expect complete blocks to process * the tar information. @@ -291,6 +299,13 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) */ if (getheader == 1) { + /* + * if we met the end of the tar + * or the end-of-tar block, + * we are done + */ + if ((len == 0) || (buffer.header.name[0]== 0)) break; + tartime = (time_t)getoct(buffer.header.mtime,12); strcpy(fname,buffer.header.name); @@ -360,6 +375,34 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) getheader = 1; if ((action == TGZ_EXTRACT) && (outfile != NULL)) { +#ifdef WIN32 + HANDLE hFile; + FILETIME ftm,ftLocal; + SYSTEMTIME st; + struct tm localt; + + fclose(outfile); + + localt = *localtime(&tartime); + + hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, 0, NULL); + + st.wYear = (WORD)localt.tm_year+1900; + st.wMonth = (WORD)localt.tm_mon; + st.wDayOfWeek = (WORD)localt.tm_wday; + st.wDay = (WORD)localt.tm_mday; + st.wHour = (WORD)localt.tm_hour; + st.wMinute = (WORD)localt.tm_min; + st.wSecond = (WORD)localt.tm_sec; + st.wMilliseconds = 0; + SystemTimeToFileTime(&st,&ftLocal); + LocalFileTimeToFileTime(&ftLocal,&ftm); + SetFileTime(hFile,&ftm,NULL,&ftm); + CloseHandle(hFile); + + outfile = NULL; +#else struct utimbuf settime; settime.actime = settime.modtime = tartime; @@ -367,6 +410,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) fclose(outfile); outfile = NULL; utime(fname,&settime); +#endif } } } -- cgit v1.2.3-55-g6feb