kmadej_fast_excel_fork 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +28 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +70 -0
  7. data/Makefile +14 -0
  8. data/README.md +95 -0
  9. data/Rakefile +24 -0
  10. data/appveyor.yml +25 -0
  11. data/benchmarks/1k_rows.rb +59 -0
  12. data/benchmarks/20k_rows.rb +26 -0
  13. data/benchmarks/init.rb +59 -0
  14. data/benchmarks/memory.rb +49 -0
  15. data/examples/example.rb +42 -0
  16. data/examples/example_align.rb +23 -0
  17. data/examples/example_chart.rb +21 -0
  18. data/examples/example_colors.rb +37 -0
  19. data/examples/example_formula.rb +18 -0
  20. data/examples/example_image.rb +13 -0
  21. data/examples/example_styles.rb +27 -0
  22. data/examples/logo.png +0 -0
  23. data/extconf.rb +0 -0
  24. data/fast_excel.gemspec +20 -0
  25. data/lib/fast_excel.rb +600 -0
  26. data/lib/fast_excel/binding.rb +2819 -0
  27. data/lib/fast_excel/binding/chart.rb +2666 -0
  28. data/lib/fast_excel/binding/format.rb +1177 -0
  29. data/lib/fast_excel/binding/workbook.rb +338 -0
  30. data/lib/fast_excel/binding/worksheet.rb +1555 -0
  31. data/libxlsxwriter/.gitignore +49 -0
  32. data/libxlsxwriter/.indent.pro +125 -0
  33. data/libxlsxwriter/.travis.yml +25 -0
  34. data/libxlsxwriter/CONTRIBUTING.md +226 -0
  35. data/libxlsxwriter/Changes.txt +557 -0
  36. data/libxlsxwriter/LICENSE.txt +89 -0
  37. data/libxlsxwriter/Makefile +156 -0
  38. data/libxlsxwriter/Readme.md +78 -0
  39. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +30 -0
  40. data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +7 -0
  41. data/libxlsxwriter/include/xlsxwriter.h +23 -0
  42. data/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  43. data/libxlsxwriter/include/xlsxwriter/chart.h +3476 -0
  44. data/libxlsxwriter/include/xlsxwriter/common.h +372 -0
  45. data/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  46. data/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  47. data/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  48. data/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  49. data/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  50. data/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  51. data/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  52. data/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  53. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  54. data/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  55. data/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  56. data/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +214 -0
  57. data/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  58. data/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  59. data/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  60. data/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  61. data/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  62. data/libxlsxwriter/include/xlsxwriter/workbook.h +757 -0
  63. data/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  64. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  65. data/libxlsxwriter/lib/.gitignore +0 -0
  66. data/libxlsxwriter/libxlsxwriter.podspec +47 -0
  67. data/libxlsxwriter/src/Makefile +130 -0
  68. data/libxlsxwriter/src/app.c +443 -0
  69. data/libxlsxwriter/src/chart.c +6346 -0
  70. data/libxlsxwriter/src/content_types.c +345 -0
  71. data/libxlsxwriter/src/core.c +293 -0
  72. data/libxlsxwriter/src/custom.c +224 -0
  73. data/libxlsxwriter/src/drawing.c +746 -0
  74. data/libxlsxwriter/src/format.c +729 -0
  75. data/libxlsxwriter/src/hash_table.c +223 -0
  76. data/libxlsxwriter/src/packager.c +948 -0
  77. data/libxlsxwriter/src/relationships.c +245 -0
  78. data/libxlsxwriter/src/shared_strings.c +266 -0
  79. data/libxlsxwriter/src/styles.c +1088 -0
  80. data/libxlsxwriter/src/theme.c +348 -0
  81. data/libxlsxwriter/src/utility.c +515 -0
  82. data/libxlsxwriter/src/workbook.c +1930 -0
  83. data/libxlsxwriter/src/worksheet.c +5022 -0
  84. data/libxlsxwriter/src/xmlwriter.c +355 -0
  85. data/libxlsxwriter/third_party/minizip/Makefile +44 -0
  86. data/libxlsxwriter/third_party/minizip/Makefile.am +45 -0
  87. data/libxlsxwriter/third_party/minizip/Makefile.orig +25 -0
  88. data/libxlsxwriter/third_party/minizip/MiniZip64_Changes.txt +6 -0
  89. data/libxlsxwriter/third_party/minizip/MiniZip64_info.txt +74 -0
  90. data/libxlsxwriter/third_party/minizip/README.txt +5 -0
  91. data/libxlsxwriter/third_party/minizip/configure.ac +32 -0
  92. data/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  93. data/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  94. data/libxlsxwriter/third_party/minizip/ioapi.h +208 -0
  95. data/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  96. data/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  97. data/libxlsxwriter/third_party/minizip/make_vms.com +25 -0
  98. data/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  99. data/libxlsxwriter/third_party/minizip/miniunzip.1 +63 -0
  100. data/libxlsxwriter/third_party/minizip/minizip.1 +46 -0
  101. data/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  102. data/libxlsxwriter/third_party/minizip/minizip.pc.in +12 -0
  103. data/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  104. data/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  105. data/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  106. data/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  107. data/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  108. data/libxlsxwriter/third_party/minizip/zip.h +367 -0
  109. data/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  110. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  111. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  112. data/libxlsxwriter/version.txt +1 -0
  113. data/test/date_test.rb +22 -0
  114. data/test/default_format_test.rb +19 -0
  115. data/test/format_test.rb +171 -0
  116. data/test/test_helper.rb +52 -0
  117. data/test/tmpfile_test.rb +23 -0
  118. data/test/worksheet_test.rb +86 -0
  119. metadata +182 -0
@@ -0,0 +1,208 @@
1
+ /* ioapi.h -- IO base function header for compress/uncompress .zip
2
+ part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3
+
4
+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5
+
6
+ Modifications for Zip64 support
7
+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8
+
9
+ For more info read MiniZip_info.txt
10
+
11
+ Changes
12
+
13
+ Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
14
+ Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
15
+ More if/def section may be needed to support other platforms
16
+ Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
17
+ (but you should use iowin32.c for windows instead)
18
+
19
+ */
20
+
21
+ #ifndef _ZLIBIOAPI64_H
22
+ #define _ZLIBIOAPI64_H
23
+
24
+ #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
25
+
26
+ // Linux needs this to support file operation on files larger then 4+GB
27
+ // But might need better if/def to select just the platforms that needs them.
28
+
29
+ #ifndef __USE_FILE_OFFSET64
30
+ #define __USE_FILE_OFFSET64
31
+ #endif
32
+ #ifndef __USE_LARGEFILE64
33
+ #define __USE_LARGEFILE64
34
+ #endif
35
+ #ifndef _LARGEFILE64_SOURCE
36
+ #define _LARGEFILE64_SOURCE
37
+ #endif
38
+ #ifndef _FILE_OFFSET_BIT
39
+ #define _FILE_OFFSET_BIT 64
40
+ #endif
41
+
42
+ #endif
43
+
44
+ #include <stdio.h>
45
+ #include <stdlib.h>
46
+ #include "zlib.h"
47
+
48
+ #if defined(USE_FILE32API)
49
+ #define fopen64 fopen
50
+ #define ftello64 ftell
51
+ #define fseeko64 fseek
52
+ #else
53
+ #if defined(__FreeBSD__) || defined(__OpenBSD__)
54
+ #define fopen64 fopen
55
+ #define ftello64 ftello
56
+ #define fseeko64 fseeko
57
+ #endif
58
+ #ifdef _MSC_VER
59
+ #define fopen64 fopen
60
+ #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
61
+ #define ftello64 _ftelli64
62
+ #define fseeko64 _fseeki64
63
+ #else // old MSC
64
+ #define ftello64 ftell
65
+ #define fseeko64 fseek
66
+ #endif
67
+ #endif
68
+ #endif
69
+
70
+ /*
71
+ #ifndef ZPOS64_T
72
+ #ifdef _WIN32
73
+ #define ZPOS64_T fpos_t
74
+ #else
75
+ #include <stdint.h>
76
+ #define ZPOS64_T uint64_t
77
+ #endif
78
+ #endif
79
+ */
80
+
81
+ #ifdef HAVE_MINIZIP64_CONF_H
82
+ #include "mz64conf.h"
83
+ #endif
84
+
85
+ /* a type choosen by DEFINE */
86
+ #ifdef HAVE_64BIT_INT_CUSTOM
87
+ typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
88
+ #else
89
+ #ifdef HAS_STDINT_H
90
+ #include "stdint.h"
91
+ typedef uint64_t ZPOS64_T;
92
+ #else
93
+
94
+ /* Maximum unsigned 32-bit value used as placeholder for zip64 */
95
+ #define MAXU32 0xffffffff
96
+
97
+ #if defined(_MSC_VER) || defined(__BORLANDC__)
98
+ typedef unsigned __int64 ZPOS64_T;
99
+ #else
100
+ typedef unsigned long long int ZPOS64_T;
101
+ #endif
102
+ #endif
103
+ #endif
104
+
105
+
106
+
107
+ #ifdef __cplusplus
108
+ extern "C" {
109
+ #endif
110
+
111
+
112
+ #define ZLIB_FILEFUNC_SEEK_CUR (1)
113
+ #define ZLIB_FILEFUNC_SEEK_END (2)
114
+ #define ZLIB_FILEFUNC_SEEK_SET (0)
115
+
116
+ #define ZLIB_FILEFUNC_MODE_READ (1)
117
+ #define ZLIB_FILEFUNC_MODE_WRITE (2)
118
+ #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
119
+
120
+ #define ZLIB_FILEFUNC_MODE_EXISTING (4)
121
+ #define ZLIB_FILEFUNC_MODE_CREATE (8)
122
+
123
+
124
+ #ifndef ZCALLBACK
125
+ #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
126
+ #define ZCALLBACK CALLBACK
127
+ #else
128
+ #define ZCALLBACK
129
+ #endif
130
+ #endif
131
+
132
+
133
+
134
+
135
+ typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
136
+ typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
137
+ typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
138
+ typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
139
+ typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
140
+
141
+ typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
142
+ typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
143
+
144
+
145
+ /* here is the "old" 32 bits structure structure */
146
+ typedef struct zlib_filefunc_def_s
147
+ {
148
+ open_file_func zopen_file;
149
+ read_file_func zread_file;
150
+ write_file_func zwrite_file;
151
+ tell_file_func ztell_file;
152
+ seek_file_func zseek_file;
153
+ close_file_func zclose_file;
154
+ testerror_file_func zerror_file;
155
+ voidpf opaque;
156
+ } zlib_filefunc_def;
157
+
158
+ typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
159
+ typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
160
+ typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
161
+
162
+ typedef struct zlib_filefunc64_def_s
163
+ {
164
+ open64_file_func zopen64_file;
165
+ read_file_func zread_file;
166
+ write_file_func zwrite_file;
167
+ tell64_file_func ztell64_file;
168
+ seek64_file_func zseek64_file;
169
+ close_file_func zclose_file;
170
+ testerror_file_func zerror_file;
171
+ voidpf opaque;
172
+ } zlib_filefunc64_def;
173
+
174
+ void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
175
+ void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
176
+
177
+ /* now internal definition, only for zip.c and unzip.h */
178
+ typedef struct zlib_filefunc64_32_def_s
179
+ {
180
+ zlib_filefunc64_def zfile_func64;
181
+ open_file_func zopen32_file;
182
+ tell_file_func ztell32_file;
183
+ seek_file_func zseek32_file;
184
+ } zlib_filefunc64_32_def;
185
+
186
+
187
+ #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
188
+ #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
189
+ /* #define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) */
190
+ /* #define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) */
191
+ #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
192
+ #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
193
+
194
+ voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
195
+ long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
196
+ ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
197
+
198
+ void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
199
+
200
+ #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
201
+ #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
202
+ #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
203
+
204
+ #ifdef __cplusplus
205
+ }
206
+ #endif
207
+
208
+ #endif
@@ -0,0 +1,456 @@
1
+ /* iowin32.c -- IO base function header for compress/uncompress .zip
2
+ Version 1.1, February 14h, 2010
3
+ part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4
+
5
+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6
+
7
+ Modifications for Zip64 support
8
+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
+
10
+ For more info read MiniZip_info.txt
11
+
12
+ */
13
+
14
+ #include <stdlib.h>
15
+
16
+ #include "zlib.h"
17
+ #include "ioapi.h"
18
+ #include "iowin32.h"
19
+
20
+ #ifndef INVALID_HANDLE_VALUE
21
+ #define INVALID_HANDLE_VALUE (0xFFFFFFFF)
22
+ #endif
23
+
24
+ #ifndef INVALID_SET_FILE_POINTER
25
+ #define INVALID_SET_FILE_POINTER ((DWORD)-1)
26
+ #endif
27
+
28
+
29
+
30
+ voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
31
+ uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
32
+ uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
33
+ ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
34
+ long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
35
+ int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
36
+ int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
37
+
38
+ typedef struct
39
+ {
40
+ HANDLE hf;
41
+ int error;
42
+ } WIN32FILE_IOWIN;
43
+
44
+
45
+ static void win32_translate_open_mode(int mode,
46
+ DWORD* lpdwDesiredAccess,
47
+ DWORD* lpdwCreationDisposition,
48
+ DWORD* lpdwShareMode,
49
+ DWORD* lpdwFlagsAndAttributes)
50
+ {
51
+ *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
52
+
53
+ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
54
+ {
55
+ *lpdwDesiredAccess = GENERIC_READ;
56
+ *lpdwCreationDisposition = OPEN_EXISTING;
57
+ *lpdwShareMode = FILE_SHARE_READ;
58
+ }
59
+ else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
60
+ {
61
+ *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
62
+ *lpdwCreationDisposition = OPEN_EXISTING;
63
+ }
64
+ else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
65
+ {
66
+ *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
67
+ *lpdwCreationDisposition = CREATE_ALWAYS;
68
+ }
69
+ }
70
+
71
+ static voidpf win32_build_iowin(HANDLE hFile)
72
+ {
73
+ voidpf ret=NULL;
74
+
75
+ if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
76
+ {
77
+ WIN32FILE_IOWIN w32fiow;
78
+ w32fiow.hf = hFile;
79
+ w32fiow.error = 0;
80
+ ret = malloc(sizeof(WIN32FILE_IOWIN));
81
+
82
+ if (ret==NULL)
83
+ CloseHandle(hFile);
84
+ else
85
+ *((WIN32FILE_IOWIN*)ret) = w32fiow;
86
+ }
87
+ return ret;
88
+ }
89
+
90
+ voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
91
+ {
92
+ const char* mode_fopen = NULL;
93
+ DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
94
+ HANDLE hFile = NULL;
95
+
96
+ win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
97
+
98
+ #ifdef IOWIN32_USING_WINRT_API
99
+ #ifdef UNICODE
100
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
101
+ hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
102
+ #else
103
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
104
+ {
105
+ WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
106
+ MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
107
+ hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
108
+ }
109
+ #endif
110
+ #else
111
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
112
+ hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
113
+ #endif
114
+
115
+ return win32_build_iowin(hFile);
116
+ }
117
+
118
+
119
+ voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
120
+ {
121
+ const char* mode_fopen = NULL;
122
+ DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
123
+ HANDLE hFile = NULL;
124
+
125
+ win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
126
+
127
+ #ifdef IOWIN32_USING_WINRT_API
128
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
129
+ {
130
+ WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
131
+ MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
132
+ hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
133
+ }
134
+ #else
135
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
136
+ hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
137
+ #endif
138
+
139
+ return win32_build_iowin(hFile);
140
+ }
141
+
142
+
143
+ voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
144
+ {
145
+ const char* mode_fopen = NULL;
146
+ DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
147
+ HANDLE hFile = NULL;
148
+
149
+ win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
150
+
151
+ #ifdef IOWIN32_USING_WINRT_API
152
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
153
+ hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL);
154
+ #else
155
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
156
+ hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
157
+ #endif
158
+
159
+ return win32_build_iowin(hFile);
160
+ }
161
+
162
+
163
+ voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
164
+ {
165
+ const char* mode_fopen = NULL;
166
+ DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
167
+ HANDLE hFile = NULL;
168
+
169
+ win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
170
+
171
+ #ifdef IOWIN32_USING_WINRT_API
172
+ #ifdef UNICODE
173
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
174
+ hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
175
+ #else
176
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
177
+ {
178
+ WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
179
+ MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
180
+ hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
181
+ }
182
+ #endif
183
+ #else
184
+ if ((filename!=NULL) && (dwDesiredAccess != 0))
185
+ hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
186
+ #endif
187
+
188
+ return win32_build_iowin(hFile);
189
+ }
190
+
191
+
192
+ uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
193
+ {
194
+ uLong ret=0;
195
+ HANDLE hFile = NULL;
196
+ if (stream!=NULL)
197
+ hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
198
+
199
+ if (hFile != NULL)
200
+ {
201
+ if (!ReadFile(hFile, buf, size, &ret, NULL))
202
+ {
203
+ DWORD dwErr = GetLastError();
204
+ if (dwErr == ERROR_HANDLE_EOF)
205
+ dwErr = 0;
206
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
207
+ }
208
+ }
209
+
210
+ return ret;
211
+ }
212
+
213
+
214
+ uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
215
+ {
216
+ uLong ret=0;
217
+ HANDLE hFile = NULL;
218
+ if (stream!=NULL)
219
+ hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
220
+
221
+ if (hFile != NULL)
222
+ {
223
+ if (!WriteFile(hFile, buf, size, &ret, NULL))
224
+ {
225
+ DWORD dwErr = GetLastError();
226
+ if (dwErr == ERROR_HANDLE_EOF)
227
+ dwErr = 0;
228
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
229
+ }
230
+ }
231
+
232
+ return ret;
233
+ }
234
+
235
+ static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
236
+ {
237
+ #ifdef IOWIN32_USING_WINRT_API
238
+ return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
239
+ #else
240
+ LONG lHigh = pos.HighPart;
241
+ DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
242
+ BOOL fOk = TRUE;
243
+ if (dwNewPos == 0xFFFFFFFF)
244
+ if (GetLastError() != NO_ERROR)
245
+ fOk = FALSE;
246
+ if ((newPos != NULL) && (fOk))
247
+ {
248
+ newPos->LowPart = dwNewPos;
249
+ newPos->HighPart = lHigh;
250
+ }
251
+ return fOk;
252
+ #endif
253
+ }
254
+
255
+ long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
256
+ {
257
+ long ret=-1;
258
+ HANDLE hFile = NULL;
259
+ if (stream!=NULL)
260
+ hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
261
+ if (hFile != NULL)
262
+ {
263
+ LARGE_INTEGER pos;
264
+ pos.QuadPart = 0;
265
+
266
+ if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
267
+ {
268
+ DWORD dwErr = GetLastError();
269
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
270
+ ret = -1;
271
+ }
272
+ else
273
+ ret=(long)pos.LowPart;
274
+ }
275
+ return ret;
276
+ }
277
+
278
+ ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
279
+ {
280
+ ZPOS64_T ret= (ZPOS64_T)-1;
281
+ HANDLE hFile = NULL;
282
+ if (stream!=NULL)
283
+ hFile = ((WIN32FILE_IOWIN*)stream)->hf;
284
+
285
+ if (hFile)
286
+ {
287
+ LARGE_INTEGER pos;
288
+ pos.QuadPart = 0;
289
+
290
+ if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
291
+ {
292
+ DWORD dwErr = GetLastError();
293
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
294
+ ret = (ZPOS64_T)-1;
295
+ }
296
+ else
297
+ ret=pos.QuadPart;
298
+ }
299
+ return ret;
300
+ }
301
+
302
+
303
+ long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
304
+ {
305
+ DWORD dwMoveMethod=0xFFFFFFFF;
306
+ HANDLE hFile = NULL;
307
+
308
+ long ret=-1;
309
+ if (stream!=NULL)
310
+ hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
311
+ switch (origin)
312
+ {
313
+ case ZLIB_FILEFUNC_SEEK_CUR :
314
+ dwMoveMethod = FILE_CURRENT;
315
+ break;
316
+ case ZLIB_FILEFUNC_SEEK_END :
317
+ dwMoveMethod = FILE_END;
318
+ break;
319
+ case ZLIB_FILEFUNC_SEEK_SET :
320
+ dwMoveMethod = FILE_BEGIN;
321
+ break;
322
+ default: return -1;
323
+ }
324
+
325
+ if (hFile != NULL)
326
+ {
327
+ LARGE_INTEGER pos;
328
+ pos.QuadPart = offset;
329
+ if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
330
+ {
331
+ DWORD dwErr = GetLastError();
332
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
333
+ ret = -1;
334
+ }
335
+ else
336
+ ret=0;
337
+ }
338
+ return ret;
339
+ }
340
+
341
+ long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
342
+ {
343
+ DWORD dwMoveMethod=0xFFFFFFFF;
344
+ HANDLE hFile = NULL;
345
+ long ret=-1;
346
+
347
+ if (stream!=NULL)
348
+ hFile = ((WIN32FILE_IOWIN*)stream)->hf;
349
+
350
+ switch (origin)
351
+ {
352
+ case ZLIB_FILEFUNC_SEEK_CUR :
353
+ dwMoveMethod = FILE_CURRENT;
354
+ break;
355
+ case ZLIB_FILEFUNC_SEEK_END :
356
+ dwMoveMethod = FILE_END;
357
+ break;
358
+ case ZLIB_FILEFUNC_SEEK_SET :
359
+ dwMoveMethod = FILE_BEGIN;
360
+ break;
361
+ default: return -1;
362
+ }
363
+
364
+ if (hFile)
365
+ {
366
+ LARGE_INTEGER pos;
367
+ pos.QuadPart = offset;
368
+ if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
369
+ {
370
+ DWORD dwErr = GetLastError();
371
+ ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
372
+ ret = -1;
373
+ }
374
+ else
375
+ ret=0;
376
+ }
377
+ return ret;
378
+ }
379
+
380
+ int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
381
+ {
382
+ int ret=-1;
383
+
384
+ if (stream!=NULL)
385
+ {
386
+ HANDLE hFile;
387
+ hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
388
+ if (hFile != NULL)
389
+ {
390
+ CloseHandle(hFile);
391
+ ret=0;
392
+ }
393
+ free(stream);
394
+ }
395
+ return ret;
396
+ }
397
+
398
+ int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
399
+ {
400
+ int ret=-1;
401
+ if (stream!=NULL)
402
+ {
403
+ ret = ((WIN32FILE_IOWIN*)stream) -> error;
404
+ }
405
+ return ret;
406
+ }
407
+
408
+ void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
409
+ {
410
+ pzlib_filefunc_def->zopen_file = win32_open_file_func;
411
+ pzlib_filefunc_def->zread_file = win32_read_file_func;
412
+ pzlib_filefunc_def->zwrite_file = win32_write_file_func;
413
+ pzlib_filefunc_def->ztell_file = win32_tell_file_func;
414
+ pzlib_filefunc_def->zseek_file = win32_seek_file_func;
415
+ pzlib_filefunc_def->zclose_file = win32_close_file_func;
416
+ pzlib_filefunc_def->zerror_file = win32_error_file_func;
417
+ pzlib_filefunc_def->opaque = NULL;
418
+ }
419
+
420
+ void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
421
+ {
422
+ pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
423
+ pzlib_filefunc_def->zread_file = win32_read_file_func;
424
+ pzlib_filefunc_def->zwrite_file = win32_write_file_func;
425
+ pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
426
+ pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
427
+ pzlib_filefunc_def->zclose_file = win32_close_file_func;
428
+ pzlib_filefunc_def->zerror_file = win32_error_file_func;
429
+ pzlib_filefunc_def->opaque = NULL;
430
+ }
431
+
432
+
433
+ void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
434
+ {
435
+ pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
436
+ pzlib_filefunc_def->zread_file = win32_read_file_func;
437
+ pzlib_filefunc_def->zwrite_file = win32_write_file_func;
438
+ pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
439
+ pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
440
+ pzlib_filefunc_def->zclose_file = win32_close_file_func;
441
+ pzlib_filefunc_def->zerror_file = win32_error_file_func;
442
+ pzlib_filefunc_def->opaque = NULL;
443
+ }
444
+
445
+
446
+ void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
447
+ {
448
+ pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
449
+ pzlib_filefunc_def->zread_file = win32_read_file_func;
450
+ pzlib_filefunc_def->zwrite_file = win32_write_file_func;
451
+ pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
452
+ pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
453
+ pzlib_filefunc_def->zclose_file = win32_close_file_func;
454
+ pzlib_filefunc_def->zerror_file = win32_error_file_func;
455
+ pzlib_filefunc_def->opaque = NULL;
456
+ }