Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/win32/win32.c view on Meta::CPAN
int fs_uses_loctime = FStampIsLocTime(__G__ G.filename);
/* Copy and/or convert time and date variables, if necessary;
* return a flag indicating which time stamps are available. */
#ifdef USE_EF_UT_TIME
if (G.extra_field &&
#ifdef IZ_CHECK_TZ
G.tz_is_valid &&
#endif
((eb_izux_flg = ef_scan_for_izux(G.extra_field,
G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
&z_utime, NULL)) & EB_UT_FL_MTIME))
{
TTrace((stderr, "getNTfiletime: Unix e.f. modif. time = %lu\n",
z_utime.mtime));
UTIME_2_IZFILETIME(z_utime.mtime, pModFT)
if (eb_izux_flg & EB_UT_FL_ATIME) {
UTIME_2_IZFILETIME(z_utime.atime, pAccFT)
}
if (eb_izux_flg & EB_UT_FL_CTIME) {
UTIME_2_IZFILETIME(z_utime.ctime, pCreFT)
}
return (int)eb_izux_flg;
}
#endif /* USE_EF_UT_TIME */
#ifndef NO_W32TIMES_IZFIX
if (!fs_uses_loctime) {
time_t ux_modtime;
ux_modtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
utime2NtfsFileTime(ux_modtime, pModFT);
} else
#endif /* NO_W32TIMES_IZFIX */
{
FILETIME lft;
DosDateTimeToFileTime((WORD)(G.lrec.last_mod_dos_datetime >> 16),
(WORD)(G.lrec.last_mod_dos_datetime & 0xFFFFL),
&lft);
LocalFileTimeToFileTime(&lft, pModFT);
}
*pAccFT = *pModFT;
return (EB_UT_FL_MTIME | EB_UT_FL_ATIME);
} /* end function getNTfiletime() */
/**************************/
/* Function SetFileSize() */
/**************************/
int SetFileSize(FILE *file, zusz_t filesize)
{
#ifdef __RSXNT__
/* RSXNT environment lacks a translation function from C file pointer
to Win32-API file handle. So, simply do nothing. */
return 0;
#else /* !__RSXNT__ */
/* not yet verified, if that really creates an unfragmented file
rommel@ars.de
*/
HANDLE os_fh;
#ifdef Z_UINT8_DEFINED
LARGE_INTEGER fsbuf;
#endif
/* Win9x supports FAT file system, only; presetting file size does
not help to prevent fragmentation. */
if (!IsWinNT()) return 0;
/* Win32-API calls require access to the Win32 file handle.
The interface function used to retrieve the Win32 handle for
a file opened by the C rtl is non-standard and may not be
available for every Win32 compiler environment.
(see also win32/win32.c of the Zip distribution)
*/
os_fh = (HANDLE)_get_osfhandle(fileno(file));
/* move file pointer behind the last byte of the expected file size */
#ifdef Z_UINT8_DEFINED
fsbuf.QuadPart = filesize;
if ((SetFilePointer(os_fh, fsbuf.LowPart, &fsbuf.HighPart, FILE_BEGIN)
== 0xFFFFFFFF) && GetLastError() != NO_ERROR)
#else
if (SetFilePointer(os_fh, (ulg)filesize, 0, FILE_BEGIN) == 0xFFFFFFFF)
#endif
return -1;
/* extend/truncate file to the current position */
if (SetEndOfFile(os_fh) == 0)
return -1;
/* move file position pointer back to the start of the file! */
return (SetFilePointer(os_fh, 0, 0, FILE_BEGIN) == 0xFFFFFFFF) ? -1 : 0;
#endif /* ?__RSXNT__ */
} /* end function SetFileSize() */
/****************************/
/* Function close_outfile() */
/****************************/
void close_outfile(__G)
__GDEF
{
FILETIME Modft; /* File time type defined in NT, `last modified' time */
FILETIME Accft; /* NT file time type, `last access' time */
FILETIME Creft; /* NT file time type, `file creation' time */
HANDLE hFile = INVALID_HANDLE_VALUE; /* File handle defined in NT */
int gotTime;
#ifdef NTSD_EAS
uch *ebSDptr;
unsigned ebSDlen;
#endif
#ifdef __RSXNT__ /* RSXNT/EMX C rtl uses OEM charset */
char *ansi_name = (char *)alloca(strlen(G.filename) + 1);
INTERN_TO_ISO(G.filename, ansi_name);
# define Ansi_Fname ansi_name
#else
# define Ansi_Fname G.filename
#endif
#ifndef __RSXNT__
if (IsWinNT()) {
/* Truncate the file to the current position.
* This is needed to remove excess allocation in case the
* extraction has failed or stopped prematurely. */
SetEndOfFile((HANDLE)_get_osfhandle(fileno(G.outfile)));
( run in 1.036 second using v1.01-cache-2.11-cpan-b16cb0d3907 )