win32i64.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. win32/win32i64.c - Zip 3
  3. Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
  4. See the accompanying file LICENSE, version 2005-Feb-10 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. #include "../zip.h"
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <limits.h>
  13. #include <time.h>
  14. #include <ctype.h>
  15. #include <windows.h>
  16. /* for LARGE_FILE_SUPPORT but may not be needed */
  17. #include <io.h>
  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. #if defined(LARGE_FILE_SUPPORT) && !defined(__CYGWIN__)
  32. /* 64-bit buffered ftello
  33. *
  34. * Win32 does not provide a 64-bit buffered
  35. * ftell (in the published api anyway) so below provides
  36. * hopefully close version.
  37. * We have not gotten _telli64 to work with buffered
  38. * streams. Below cheats by using fgetpos improperly and
  39. * may not work on other ports.
  40. */
  41. zoff_t zftello(stream)
  42. FILE *stream;
  43. {
  44. fpos_t fpos = 0;
  45. if (fgetpos(stream, &fpos) != 0) {
  46. return -1L;
  47. } else {
  48. return fpos;
  49. }
  50. }
  51. /* 64-bit buffered fseeko
  52. *
  53. * Win32 does not provide a 64-bit buffered
  54. * fseeko so use _lseeki64 and fflush. Note
  55. * that SEEK_CUR can lose track of location
  56. * if fflush is done between the last buffered
  57. * io and this call.
  58. */
  59. int zfseeko(stream, offset, origin)
  60. FILE *stream;
  61. zoff_t offset;
  62. int origin;
  63. {
  64. zoff_t location;
  65. location = zftello(stream);
  66. fflush(stream);
  67. if (origin == SEEK_CUR) {
  68. /* instead of synching up lseek easier just to figure and
  69. use an absolute offset */
  70. offset = location + offset;
  71. location = _lseeki64(fileno(stream), offset, SEEK_SET);
  72. } else {
  73. location = _lseeki64(fileno(stream), offset, origin);
  74. }
  75. if (location == -1L) {
  76. return -1L;
  77. } else {
  78. return 0;
  79. }
  80. }
  81. #endif /* Win32 LARGE_FILE_SUPPORT */
  82. #if 0
  83. FILE* zfopen(filename,mode)
  84. char *filename;
  85. char *mode;
  86. {
  87. FILE* fTemp;
  88. fTemp = fopen(filename,mode);
  89. if( fTemp == NULL )
  90. return NULL;
  91. /* sorry, could not make VC60 and its rtl work properly without setting the file buffer to NULL. the */
  92. /* problem seems to be _telli64 which seems to return the max stream position, comments are welcome */
  93. setbuf(fTemp,NULL);
  94. return fTemp;
  95. }
  96. #endif
  97. /* --------------------------------------------------- */