| 1 |
/* |
| 2 |
win32/win32i64.c - Zip 3 |
| 3 |
|
| 4 |
Copyright (c) 1990-2007 Info-ZIP. All rights reserved. |
| 5 |
|
| 6 |
See the accompanying file LICENSE, version 2005-Feb-10 or later |
| 7 |
(the contents of which are also included in zip.h) for terms of use. |
| 8 |
If, for some reason, all these files are missing, the Info-ZIP license |
| 9 |
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "../zip.h" |
| 13 |
|
| 14 |
#include <stdlib.h> |
| 15 |
#include <stdio.h> |
| 16 |
#include <limits.h> |
| 17 |
#include <time.h> |
| 18 |
#include <ctype.h> |
| 19 |
#include <windows.h> |
| 20 |
/* for LARGE_FILE_SUPPORT but may not be needed */ |
| 21 |
#include <io.h> |
| 22 |
|
| 23 |
|
| 24 |
/* --------------------------------------------------- */ |
| 25 |
/* Large File Support |
| 26 |
* |
| 27 |
* Initial functions by E. Gordon and R. Nausedat |
| 28 |
* 9/10/2003 |
| 29 |
* |
| 30 |
* These implement 64-bit file support for Windows. The |
| 31 |
* defines and headers are in win32/osdep.h. |
| 32 |
* |
| 33 |
* These moved from win32.c by Mike White to avoid conflicts |
| 34 |
* in WiZ of same name functions in UnZip and Zip libraries. |
| 35 |
* 9/25/04 EG |
| 36 |
*/ |
| 37 |
|
| 38 |
#if defined(LARGE_FILE_SUPPORT) && !defined(__CYGWIN__) |
| 39 |
|
| 40 |
/* 64-bit buffered ftello |
| 41 |
* |
| 42 |
* Win32 does not provide a 64-bit buffered |
| 43 |
* ftell (in the published api anyway) so below provides |
| 44 |
* hopefully close version. |
| 45 |
* We have not gotten _telli64 to work with buffered |
| 46 |
* streams. Below cheats by using fgetpos improperly and |
| 47 |
* may not work on other ports. |
| 48 |
*/ |
| 49 |
|
| 50 |
zoff_t zftello(stream) |
| 51 |
FILE *stream; |
| 52 |
{ |
| 53 |
fpos_t fpos = 0; |
| 54 |
|
| 55 |
if (fgetpos(stream, &fpos) != 0) { |
| 56 |
return -1L; |
| 57 |
} else { |
| 58 |
return fpos; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
/* 64-bit buffered fseeko |
| 64 |
* |
| 65 |
* Win32 does not provide a 64-bit buffered |
| 66 |
* fseeko so use _lseeki64 and fflush. Note |
| 67 |
* that SEEK_CUR can lose track of location |
| 68 |
* if fflush is done between the last buffered |
| 69 |
* io and this call. |
| 70 |
*/ |
| 71 |
|
| 72 |
int zfseeko(stream, offset, origin) |
| 73 |
FILE *stream; |
| 74 |
zoff_t offset; |
| 75 |
int origin; |
| 76 |
{ |
| 77 |
zoff_t location; |
| 78 |
|
| 79 |
location = zftello(stream); |
| 80 |
fflush(stream); |
| 81 |
if (origin == SEEK_CUR) { |
| 82 |
/* instead of synching up lseek easier just to figure and |
| 83 |
use an absolute offset */ |
| 84 |
offset = location + offset; |
| 85 |
location = _lseeki64(fileno(stream), offset, SEEK_SET); |
| 86 |
} else { |
| 87 |
location = _lseeki64(fileno(stream), offset, origin); |
| 88 |
} |
| 89 |
if (location == -1L) { |
| 90 |
return -1L; |
| 91 |
} else { |
| 92 |
return 0; |
| 93 |
} |
| 94 |
} |
| 95 |
#endif /* Win32 LARGE_FILE_SUPPORT */ |
| 96 |
|
| 97 |
#if 0 |
| 98 |
FILE* zfopen(filename,mode) |
| 99 |
char *filename; |
| 100 |
char *mode; |
| 101 |
{ |
| 102 |
FILE* fTemp; |
| 103 |
|
| 104 |
fTemp = fopen(filename,mode); |
| 105 |
if( fTemp == NULL ) |
| 106 |
return NULL; |
| 107 |
|
| 108 |
/* sorry, could not make VC60 and its rtl work properly without setting the file buffer to NULL. the */ |
| 109 |
/* problem seems to be _telli64 which seems to return the max stream position, comments are welcome */ |
| 110 |
setbuf(fTemp,NULL); |
| 111 |
|
| 112 |
return fTemp; |
| 113 |
} |
| 114 |
#endif |
| 115 |
/* --------------------------------------------------- */ |