aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/openslide/fix-win-build.patch
blob: 3fc1ed84de41e253aa195d32191e6a9de2d4c207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
diff --git a/common/openslide-common-fd.c b/common/openslide-common-fd.c
index 3d3ce955f3c1..20127ce4bdd9 100644
--- a/common/openslide-common-fd.c
+++ b/common/openslide-common-fd.c
@@ -27,10 +27,13 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <glib.h>
 
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
 #ifdef __APPLE__
 #include <sys/param.h>  // MAXPATHLEN
 #include <libproc.h>
diff --git a/meson.build b/meson.build
index 0b4d7d47b695..ac106fb1001f 100644
--- a/meson.build
+++ b/meson.build
@@ -59,6 +59,17 @@ add_project_arguments(
   '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_MIN_REQUIRED',
   language : 'c'
 )
+if host_machine.system() == 'windows'
+  # Windows likes to warn about C and POSIX functions
+  foreach native : [false, true]
+    add_project_arguments(
+      '-D_CRT_NONSTDC_NO_DEPRECATE',
+      '-D_CRT_SECURE_NO_WARNINGS',
+      language : 'c',
+      native : native,
+    )
+  endforeach
+endif
 add_project_link_arguments(
   cc.get_supported_link_arguments(
     '-Wl,--no-undefined',
@@ -66,6 +77,13 @@ add_project_link_arguments(
   language : 'c'
 )
 
+# Functions
+foreach f : ['fseeko', 'ftello']
+  if cc.has_function(f)
+    conf.set('HAVE_' + f.to_upper(), 1)
+  endif
+endforeach
+
 # fopen cloexec flag
 if host_machine.system() in ['dragonfly', 'freebsd', 'linux', 'netbsd', 'openbsd']
   message('Using "e" flag for close-on-exec')
diff --git a/src/meson.build b/src/meson.build
index e886eea4b5c4..4be22f64aef7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -24,6 +24,8 @@ openslide_dll_rc = configure_file(
 if host_machine.system() == 'windows'
   openslide_dll_o = import('windows').compile_resources(
     openslide_dll_rc,
+    # https://github.com/llvm/llvm-project/issues/63426
+    args : [cc.get_argument_syntax() == 'msvc' ? '/c' : '-c', '65001'],
     depend_files : [openslide_dll_manifest],
   )
 else
diff --git a/src/openslide-decode-dicom.c b/src/openslide-decode-dicom.c
index 24dcfbfe4568..d5fa053e94ef 100644
--- a/src/openslide-decode-dicom.c
+++ b/src/openslide-decode-dicom.c
@@ -88,7 +88,7 @@ static int64_t vfs_seek(DcmError **dcm_error, DcmIO *io,
 
   // libdicom uses lseek(2) semantics, so it must always return the new file
   // pointer
-  off_t new_position = _openslide_ftell(dio->file, &err);
+  int64_t new_position = _openslide_ftell(dio->file, &err);
   if (new_position < 0) {
     propagate_gerror(dcm_error, err);
   }
diff --git a/src/openslide-decode-tifflike.c b/src/openslide-decode-tifflike.c
index 626cd4039110..3ca3e374f208 100644
--- a/src/openslide-decode-tifflike.c
+++ b/src/openslide-decode-tifflike.c
@@ -470,8 +470,9 @@ static struct tiff_directory *read_directory(struct _openslide_file *f,
       return NULL;
     }
 
-    // check for overflow
-    if (count > SSIZE_MAX / value_size) {
+    // compute total size
+    size_t value_len;
+    if (!g_size_checked_mul(&value_len, value_size, count)) {
       g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
                   "Value count too large");
       return NULL;
@@ -486,7 +487,7 @@ static struct tiff_directory *read_directory(struct _openslide_file *f,
     }
 
     // does value/offset contain the value?
-    if (value_size * count <= sizeof(value)) {
+    if (value_len <= sizeof(value)) {
       // yes
       fix_byte_order(value, value_size, count, big_endian);
       if (!set_item_values(item, value, err)) {
diff --git a/src/openslide-dll.rc.in b/src/openslide-dll.rc.in
index 0670ee539e02..47e4d729e2bd 100644
--- a/src/openslide-dll.rc.in
+++ b/src/openslide-dll.rc.in
@@ -10,16 +10,16 @@ FILETYPE VFT_DLL
 BEGIN
     BLOCK "StringFileInfo"
     BEGIN
-        BLOCK "040904e4"
+        BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription",  "OpenSlide library"
             VALUE "FileVersion", "@SUFFIXED_VERSION@"
             VALUE "InternalName", "OpenSlide"
-            VALUE "LegalCopyright", "Copyright \251 2007-2023 Carnegie Mellon University and others.  OpenSlide is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1."
+            VALUE "LegalCopyright", "Copyright © 2007-2023 Carnegie Mellon University and others.  OpenSlide is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1."
         END
     END
     BLOCK "VarFileInfo"
     BEGIN
-        VALUE "Translation", 0x0409, 0x04e4
+        VALUE "Translation", 0x0409, 0x04b0
     END
 END
diff --git a/src/openslide-file.c b/src/openslide-file.c
index 2763f38071dc..11b568913cfe 100644
--- a/src/openslide-file.c
+++ b/src/openslide-file.c
@@ -36,6 +36,13 @@
 #include <fcntl.h>
 #endif
 
+#if !defined(HAVE_FSEEKO) && defined(_WIN32)
+#define fseeko _fseeki64
+#endif
+#if !defined(HAVE_FTELLO) && defined(_WIN32)
+#define ftello _ftelli64
+#endif
+
 struct _openslide_file {
   FILE *fp;
 };
@@ -141,7 +148,7 @@ size_t _openslide_fread(struct _openslide_file *file, void *buf, size_t size) {
   return total;
 }
 
-bool _openslide_fseek(struct _openslide_file *file, off_t offset, int whence,
+bool _openslide_fseek(struct _openslide_file *file, int64_t offset, int whence,
                       GError **err) {
   if (fseeko(file->fp, offset, whence)) {
     g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errno),
@@ -151,8 +158,8 @@ bool _openslide_fseek(struct _openslide_file *file, off_t offset, int whence,
   return true;
 }
 
-off_t _openslide_ftell(struct _openslide_file *file, GError **err) {
-  off_t ret = ftello(file->fp);
+int64_t _openslide_ftell(struct _openslide_file *file, GError **err) {
+  int64_t ret = ftello(file->fp);
   if (ret == -1) {
     g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errno),
                 "%s", g_strerror(errno));
@@ -160,15 +167,15 @@ off_t _openslide_ftell(struct _openslide_file *file, GError **err) {
   return ret;
 }
 
-off_t _openslide_fsize(struct _openslide_file *file, GError **err) {
-  off_t orig = _openslide_ftell(file, err);
+int64_t _openslide_fsize(struct _openslide_file *file, GError **err) {
+  int64_t orig = _openslide_ftell(file, err);
   if (orig == -1) {
     return -1;
   }
   if (!_openslide_fseek(file, 0, SEEK_END, err)) {
     return -1;
   }
-  off_t ret = _openslide_ftell(file, err);
+  int64_t ret = _openslide_ftell(file, err);
   if (ret == -1) {
     return -1;
   }
diff --git a/src/openslide-private.h b/src/openslide-private.h
index 5ae36939b048..eb670427f6e4 100644
--- a/src/openslide-private.h
+++ b/src/openslide-private.h
@@ -186,10 +186,10 @@ struct _openslide_file;
 
 struct _openslide_file *_openslide_fopen(const char *path, GError **err);
 size_t _openslide_fread(struct _openslide_file *file, void *buf, size_t size);
-bool _openslide_fseek(struct _openslide_file *file, off_t offset, int whence,
+bool _openslide_fseek(struct _openslide_file *file, int64_t offset, int whence,
                       GError **err);
-off_t _openslide_ftell(struct _openslide_file *file, GError **err);
-off_t _openslide_fsize(struct _openslide_file *file, GError **err);
+int64_t _openslide_ftell(struct _openslide_file *file, GError **err);
+int64_t _openslide_fsize(struct _openslide_file *file, GError **err);
 void _openslide_fclose(struct _openslide_file *file);
 bool _openslide_fexists(const char *path, GError **err);
 
diff --git a/src/openslide-vendor-synthetic.c b/src/openslide-vendor-synthetic.c
index e3a44056900a..2966803ae6e8 100644
--- a/src/openslide-vendor-synthetic.c
+++ b/src/openslide-vendor-synthetic.c
@@ -156,13 +156,13 @@ static bool decode_png(const void *data, uint32_t len,
 
 struct mem_tiff {
   const uint8_t *data;
-  ssize_t offset;
-  ssize_t size;
+  int64_t offset;
+  int64_t size;
 };
 
 static tsize_t mem_tiff_read(thandle_t th, tdata_t buf, tsize_t size) {
   struct mem_tiff *mem = th;
-  ssize_t count = MIN(mem->size - mem->offset, size);
+  int64_t count = MIN(mem->size - mem->offset, size);
   memcpy(buf, mem->data + mem->offset, count);
   mem->offset += count;
   return count;
diff --git a/tools/slidetool-util.c b/tools/slidetool-util.c
index 28901eda611c..7a0de731245f 100644
--- a/tools/slidetool-util.c
+++ b/tools/slidetool-util.c
@@ -20,11 +20,16 @@
  */
 
 #include <stdio.h>
-#include <unistd.h>
 #include <errno.h>
 #include "openslide-common.h"
 #include "slidetool.h"
 
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
 struct output open_output(const char *filename) {
   struct output out;
   if (filename) {