summaryrefslogtreecommitdiff
path: root/contrib/untgz
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--contrib/untgz/untgz.c64
1 files changed, 54 insertions, 10 deletions
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 @@
9#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h> 10#include <string.h>
11#include <time.h> 11#include <time.h>
12#include <utime.h>
13#include <errno.h> 12#include <errno.h>
14#include <fcntl.h> 13#include <fcntl.h>
15#ifdef unix 14#ifdef unix
@@ -21,6 +20,23 @@
21 20
22#include "zlib.h" 21#include "zlib.h"
23 22
23#ifdef WIN32
24# ifndef F_OK
25# define F_OK (0)
26# endif
27# ifdef _MSC_VER
28# define mkdir(dirname,mode) _mkdir(dirname)
29# define strdup(str) _strdup(str)
30# define unlink(fn) _unlink(fn)
31# define access(path,mode) _access(path,mode)
32# else
33# define mkdir(dirname,mode) _mkdir(dirname)
34# endif
35#else
36# include <utime.h>
37#endif
38
39
24/* Values used in typeflag field. */ 40/* Values used in typeflag field. */
25 41
26#define REGTYPE '0' /* regular file */ 42#define REGTYPE '0' /* regular file */
@@ -83,7 +99,7 @@ char *prog;
83 99
84/* This will give a benign warning */ 100/* This will give a benign warning */
85 101
86static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", NULL }; 102static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar", NULL };
87 103
88/* Return the real name of the TGZ archive */ 104/* Return the real name of the TGZ archive */
89/* or NULL if it does not exist. */ 105/* or NULL if it does not exist. */
@@ -272,14 +288,6 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
272 if (len < 0) 288 if (len < 0)
273 error (gzerror(in, &err)); 289 error (gzerror(in, &err));
274 /* 290 /*
275 * if we met the end of the tar
276 * or the end-of-tar block,
277 * we are done
278 */
279 if ((len == 0) || (buffer.header.name[0]== 0))
280 break;
281
282 /*
283 * Always expect complete blocks to process 291 * Always expect complete blocks to process
284 * the tar information. 292 * the tar information.
285 */ 293 */
@@ -291,6 +299,13 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
291 */ 299 */
292 if (getheader == 1) 300 if (getheader == 1)
293 { 301 {
302 /*
303 * if we met the end of the tar
304 * or the end-of-tar block,
305 * we are done
306 */
307 if ((len == 0) || (buffer.header.name[0]== 0)) break;
308
294 tartime = (time_t)getoct(buffer.header.mtime,12); 309 tartime = (time_t)getoct(buffer.header.mtime,12);
295 strcpy(fname,buffer.header.name); 310 strcpy(fname,buffer.header.name);
296 311
@@ -360,6 +375,34 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
360 getheader = 1; 375 getheader = 1;
361 if ((action == TGZ_EXTRACT) && (outfile != NULL)) 376 if ((action == TGZ_EXTRACT) && (outfile != NULL))
362 { 377 {
378#ifdef WIN32
379 HANDLE hFile;
380 FILETIME ftm,ftLocal;
381 SYSTEMTIME st;
382 struct tm localt;
383
384 fclose(outfile);
385
386 localt = *localtime(&tartime);
387
388 hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
389 0, NULL, OPEN_EXISTING, 0, NULL);
390
391 st.wYear = (WORD)localt.tm_year+1900;
392 st.wMonth = (WORD)localt.tm_mon;
393 st.wDayOfWeek = (WORD)localt.tm_wday;
394 st.wDay = (WORD)localt.tm_mday;
395 st.wHour = (WORD)localt.tm_hour;
396 st.wMinute = (WORD)localt.tm_min;
397 st.wSecond = (WORD)localt.tm_sec;
398 st.wMilliseconds = 0;
399 SystemTimeToFileTime(&st,&ftLocal);
400 LocalFileTimeToFileTime(&ftLocal,&ftm);
401 SetFileTime(hFile,&ftm,NULL,&ftm);
402 CloseHandle(hFile);
403
404 outfile = NULL;
405#else
363 struct utimbuf settime; 406 struct utimbuf settime;
364 407
365 settime.actime = settime.modtime = tartime; 408 settime.actime = settime.modtime = tartime;
@@ -367,6 +410,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
367 fclose(outfile); 410 fclose(outfile);
368 outfile = NULL; 411 outfile = NULL;
369 utime(fname,&settime); 412 utime(fname,&settime);
413#endif
370 } 414 }
371 } 415 }
372 } 416 }