Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6725 | siemargl | 1 | /* |
2 | Copyright (c) 1990-2009 Info-ZIP. All rights reserved. |
||
3 | |||
4 | See the accompanying file LICENSE, version 2009-Jan-02 or later |
||
5 | (the contents of which are also included in zip.h) for terms of use. |
||
6 | If, for some reason, all these files are missing, the Info-ZIP license |
||
7 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
||
8 | */ |
||
9 | /*--------------------------------------------------------------------------- |
||
10 | |||
11 | win32/win32i64.c - UnZip 6 |
||
12 | |||
13 | 64-bit filesize support for WIN32 Zip and UnZip. |
||
14 | ---------------------------------------------------------------------------*/ |
||
15 | |||
16 | #include "../zip.h" |
||
17 | |||
18 | /* --------------------------------------------------- */ |
||
19 | /* Large File Support |
||
20 | * |
||
21 | * Initial functions by E. Gordon and R. Nausedat |
||
22 | * 9/10/2003 |
||
23 | * |
||
24 | * These implement 64-bit file support for Windows. The |
||
25 | * defines and headers are in win32/osdep.h. |
||
26 | * |
||
27 | * These moved from win32.c by Mike White to avoid conflicts |
||
28 | * in WiZ of same name functions in UnZip and Zip libraries. |
||
29 | * 9/25/04 EG |
||
30 | */ |
||
31 | |||
32 | #if defined(LARGE_FILE_SUPPORT) && !defined(__CYGWIN__) |
||
33 | # ifdef USE_STRM_INPUT |
||
34 | |||
35 | # ifndef zftello |
||
36 | /* 64-bit buffered ftello |
||
37 | * |
||
38 | * Win32 does not provide a 64-bit buffered |
||
39 | * ftell (in the published api anyway) so below provides |
||
40 | * hopefully close version. |
||
41 | * We have not gotten _telli64 to work with buffered |
||
42 | * streams. Below cheats by using fgetpos improperly and |
||
43 | * may not work on other ports. |
||
44 | */ |
||
45 | |||
46 | zoff_t zftello(stream) |
||
47 | FILE *stream; |
||
48 | { |
||
49 | fpos_t fpos = 0; |
||
50 | |||
51 | if (fgetpos(stream, &fpos) != 0) { |
||
52 | return -1L; |
||
53 | } else { |
||
54 | return fpos; |
||
55 | } |
||
56 | } |
||
57 | # endif /* ndef zftello */ |
||
58 | |||
59 | |||
60 | # ifndef zfseeko |
||
61 | /* 64-bit buffered fseeko |
||
62 | * |
||
63 | * Win32 does not provide a 64-bit buffered |
||
64 | * fseeko, so use _lseeki64 and fflush. Note |
||
65 | * that SEEK_CUR can lose track of location |
||
66 | * if fflush is done between the last buffered |
||
67 | * io and this call. |
||
68 | */ |
||
69 | |||
70 | int zfseeko(stream, offset, origin) |
||
71 | FILE *stream; |
||
72 | zoff_t offset; |
||
73 | int origin; |
||
74 | { |
||
75 | |||
76 | /* fseek() or its replacements are supposed to clear the eof status |
||
77 | of the stream. fflush() and _lseeki64() do not touch the stream's |
||
78 | eof flag, so we have to do it manually. */ |
||
79 | #if ((defined(_MSC_VER) && (_MSC_VER >= 1200)) || \ |
||
80 | (defined(__MINGW32__) && defined(__MSVCRT_VERSION__))) |
||
81 | /* For the MSC environment (VS 6 or higher), and for recent releases of |
||
82 | the MinGW environment, we "know" the internals of the FILE structure. |
||
83 | So, we can clear just the EOF bit of the status flag. */ |
||
84 | stream->_flag &= ~_IOEOF; |
||
85 | #else |
||
86 | /* Unfortunately, there is no standard "cleareof()" function, so we have |
||
87 | to use clearerr(). This has the unwanted side effect of clearing the |
||
88 | ferror() state as well. */ |
||
89 | clearerr(stream); |
||
90 | #endif |
||
91 | |||
92 | if (origin == SEEK_CUR) { |
||
93 | /* instead of synching up lseek easier just to figure and |
||
94 | use an absolute offset */ |
||
95 | offset += zftello(stream); |
||
96 | origin = SEEK_SET; |
||
97 | } |
||
98 | fflush(stream); |
||
99 | if (_lseeki64(fileno(stream), offset, origin) == (zoff_t)-1L) { |
||
100 | return -1; |
||
101 | } else { |
||
102 | return 0; |
||
103 | } |
||
104 | } |
||
105 | # endif /* ndef fseeko */ |
||
106 | # endif /* USE_STRM_INPUT */ |
||
107 | #endif /* Win32 LARGE_FILE_SUPPORT */ |
||
108 | |||
109 | #if 0 |
||
110 | FILE* zfopen(filename, mode) |
||
111 | const char *filename; |
||
112 | const char *mode; |
||
113 | { |
||
114 | FILE* fTemp; |
||
115 | |||
116 | fTemp = fopen(filename, mode); |
||
117 | if( fTemp == NULL ) |
||
118 | return NULL; |
||
119 | |||
120 | /* sorry, could not make VC60 and its rtl work properly without setting the |
||
121 | * file buffer to NULL. the problem seems to be _telli64 which seems to |
||
122 | * return the max stream position, comments are welcome |
||
123 | */ |
||
124 | setbuf(fTemp, NULL); |
||
125 | |||
126 | return fTemp; |
||
127 | } |
||
128 | #endif |
||
129 | /* --------------------------------------------------- */ |