ReactOS 0.4.16-dev-2613-g9533ad7
tif_win32.c File Reference
#include "tiffiop.h"
#include <stdlib.h>
#include <windows.h>
Include dependency graph for tif_win32.c:

Go to the source code of this file.

Functions

static thandle_t thandle_from_int (int ifd)
 
static int thandle_to_int (thandle_t fd)
 
static tmsize_t _tiffReadProc (thandle_t fd, void *buf, tmsize_t size)
 
static tmsize_t _tiffWriteProc (thandle_t fd, void *buf, tmsize_t size)
 
static uint64_t _tiffSeekProc (thandle_t fd, uint64_t off, int whence)
 
static int _tiffCloseProc (thandle_t fd)
 
static uint64_t _tiffSizeProc (thandle_t fd)
 
static int _tiffMapProc (thandle_t fd, void **pbase, toff_t *psize)
 
static void _tiffUnmapProc (thandle_t fd, void *base, toff_t size)
 
TIFFTIFFFdOpen (int ifd, const char *name, const char *mode)
 
TIFFTIFFFdOpenExt (int ifd, const char *name, const char *mode, TIFFOpenOptions *opts)
 
TIFFTIFFOpen (const char *name, const char *mode)
 
TIFFTIFFOpenExt (const char *name, const char *mode, TIFFOpenOptions *opts)
 
TIFFTIFFOpenW (const wchar_t *name, const char *mode)
 
TIFFTIFFOpenWExt (const wchar_t *name, const char *mode, TIFFOpenOptions *opts)
 
void_TIFFmalloc (tmsize_t s)
 
void_TIFFcalloc (tmsize_t nmemb, tmsize_t siz)
 
void _TIFFfree (void *p)
 
void_TIFFrealloc (void *p, tmsize_t s)
 
void _TIFFmemset (void *p, int v, tmsize_t c)
 
void _TIFFmemcpy (void *d, const void *s, tmsize_t c)
 
int _TIFFmemcmp (const void *p1, const void *p2, tmsize_t c)
 
static void Win32WarningHandler (const char *module, const char *fmt, va_list ap)
 
static void Win32ErrorHandler (const char *module, const char *fmt, va_list ap)
 

Variables

TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler
 
TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler
 

Function Documentation

◆ _TIFFcalloc()

void * _TIFFcalloc ( tmsize_t  nmemb,
tmsize_t  siz 
)

Definition at line 386 of file tif_win32.c.

387{
388 if (nmemb == 0 || siz == 0)
389 return ((void *)NULL);
390
391 return calloc((size_t)nmemb, (size_t)siz);
392}
#define NULL
Definition: types.h:112
#define calloc
Definition: rosglue.h:14

◆ _tiffCloseProc()

static int _tiffCloseProc ( thandle_t  fd)
static

Definition at line 150 of file tif_win32.c.

150{ return (CloseHandle(fd) ? 0 : -1); }
#define CloseHandle
Definition: compat.h:739
static int fd
Definition: io.c:51

Referenced by TIFFFdOpenExt().

◆ _TIFFfree()

void _TIFFfree ( void p)

Definition at line 394 of file tif_win32.c.

394{ free(p); }
#define free
Definition: debug_ros.c:5
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by TIFFOpenWExt().

◆ _TIFFmalloc()

void * _TIFFmalloc ( tmsize_t  s)

Definition at line 378 of file tif_win32.c.

379{
380 if (s == 0)
381 return ((void *)NULL);
382
383 return (malloc((size_t)s));
384}
#define malloc
Definition: debug_ros.c:4
GLdouble s
Definition: gl.h:2039

Referenced by TIFFOpenWExt().

◆ _tiffMapProc()

static int _tiffMapProc ( thandle_t  fd,
void **  pbase,
toff_t psize 
)
static

Definition at line 172 of file tif_win32.c.

173{
175 tmsize_t sizem;
176 HANDLE hMapFile;
177
179 sizem = (tmsize_t)size;
180 if (!size || (uint64_t)sizem != size)
181 return (0);
182
183 /* By passing in 0 for the maximum file size, it specifies that we
184 create a file mapping object for the full file size. */
185 hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL);
186 if (hMapFile == NULL)
187 return (0);
188 *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
189 CloseHandle(hMapFile);
190 if (*pbase == NULL)
191 return (0);
192 *psize = size;
193 return (1);
194}
UINT64 uint64_t
Definition: types.h:77
#define PAGE_READONLY
Definition: compat.h:138
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
GLsizeiptr size
Definition: glext.h:5919
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
static uint64_t _tiffSizeProc(thandle_t fd)
Definition: tif_win32.c:152
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:67
#define CreateFileMapping
Definition: winbase.h:3499

Referenced by TIFFFdOpenExt().

◆ _TIFFmemcmp()

int _TIFFmemcmp ( const void p1,
const void p2,
tmsize_t  c 
)

Definition at line 405 of file tif_win32.c.

406{
407 return (memcmp(p1, p2, (size_t)c));
408}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
const GLubyte * c
Definition: glext.h:8905

◆ _TIFFmemcpy()

void _TIFFmemcpy ( void d,
const void s,
tmsize_t  c 
)

Definition at line 400 of file tif_win32.c.

401{
402 memcpy(d, s, (size_t)c);
403}
#define d
Definition: ke_i.h:81
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ _TIFFmemset()

void _TIFFmemset ( void p,
int  v,
tmsize_t  c 
)

Definition at line 398 of file tif_win32.c.

398{ memset(p, v, (size_t)c); }
const GLdouble * v
Definition: gl.h:2040
#define memset(x, y, z)
Definition: compat.h:39

◆ _tiffReadProc()

static tmsize_t _tiffReadProc ( thandle_t  fd,
void buf,
tmsize_t  size 
)
static

Definition at line 64 of file tif_win32.c.

65{
66 /* tmsize_t is 64bit on 64bit systems, but the WinAPI ReadFile takes
67 * 32bit sizes, so we loop through the data in suitable 32bit sized
68 * chunks */
69 uint8_t *ma;
70 uint64_t mb;
71 DWORD n;
72 DWORD o;
73 tmsize_t p;
74 ma = (uint8_t *)buf;
75 mb = size;
76 p = 0;
77 while (mb > 0)
78 {
79 n = 0x80000000UL;
80 if ((uint64_t)n > mb)
81 n = (DWORD)mb;
82 if (!ReadFile(fd, (LPVOID)ma, n, &o, NULL))
83 return (0);
84 ma += o;
85 mb -= o;
86 p += o;
87 if (o != n)
88 break;
89 }
90 return (p);
91}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
unsigned char uint8_t
Definition: stdint.h:33
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by TIFFFdOpenExt().

◆ _TIFFrealloc()

void * _TIFFrealloc ( void p,
tmsize_t  s 
)

Definition at line 396 of file tif_win32.c.

396{ return (realloc(p, (size_t)s)); }
#define realloc
Definition: debug_ros.c:6

◆ _tiffSeekProc()

static uint64_t _tiffSeekProc ( thandle_t  fd,
uint64_t  off,
int  whence 
)
static

Definition at line 122 of file tif_win32.c.

123{
124 LARGE_INTEGER offli;
125 DWORD dwMoveMethod;
126 offli.QuadPart = off;
127 switch (whence)
128 {
129 case SEEK_SET:
130 dwMoveMethod = FILE_BEGIN;
131 break;
132 case SEEK_CUR:
133 dwMoveMethod = FILE_CURRENT;
134 break;
135 case SEEK_END:
136 dwMoveMethod = FILE_END;
137 break;
138 default:
139 dwMoveMethod = FILE_BEGIN;
140 break;
141 }
142 offli.LowPart =
143 SetFilePointer(fd, offli.LowPart, &offli.HighPart, dwMoveMethod);
144 if ((offli.LowPart == INVALID_SET_FILE_POINTER) &&
145 (GetLastError() != NO_ERROR))
146 offli.QuadPart = 0;
147 return (offli.QuadPart);
148}
#define SEEK_END
Definition: cabinet.c:29
#define NO_ERROR
Definition: dderror.h:5
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define SetFilePointer
Definition: compat.h:743
#define SEEK_CUR
Definition: stdio.h:44
#define SEEK_SET
Definition: jmemansi.c:26
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
#define FILE_END
Definition: winbase.h:116
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_CURRENT
Definition: winbase.h:115

Referenced by TIFFFdOpenExt().

◆ _tiffSizeProc()

static uint64_t _tiffSizeProc ( thandle_t  fd)
static

Definition at line 152 of file tif_win32.c.

153{
155 if (GetFileSizeEx(fd, &m))
156 return (m.QuadPart);
157 else
158 return (0);
159}
#define GetFileSizeEx
Definition: compat.h:757
const GLfloat * m
Definition: glext.h:10848

Referenced by _tiffMapProc(), and TIFFFdOpenExt().

◆ _tiffUnmapProc()

static void _tiffUnmapProc ( thandle_t  fd,
void base,
toff_t  size 
)
static

Definition at line 196 of file tif_win32.c.

197{
198 (void)fd;
199 (void)size;
201}
#define UnmapViewOfFile
Definition: compat.h:746

Referenced by TIFFFdOpenExt().

◆ _tiffWriteProc()

static tmsize_t _tiffWriteProc ( thandle_t  fd,
void buf,
tmsize_t  size 
)
static

Definition at line 93 of file tif_win32.c.

94{
95 /* tmsize_t is 64bit on 64bit systems, but the WinAPI WriteFile takes
96 * 32bit sizes, so we loop through the data in suitable 32bit sized
97 * chunks */
98 uint8_t *ma;
99 uint64_t mb;
100 DWORD n;
101 DWORD o;
102 tmsize_t p;
103 ma = (uint8_t *)buf;
104 mb = size;
105 p = 0;
106 while (mb > 0)
107 {
108 n = 0x80000000UL;
109 if ((uint64_t)n > mb)
110 n = (DWORD)mb;
111 if (!WriteFile(fd, (LPVOID)ma, n, &o, NULL))
112 return (0);
113 ma += o;
114 mb -= o;
115 p += o;
116 if (o != n)
117 break;
118 }
119 return (p);
120}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24

Referenced by TIFFFdOpenExt().

◆ thandle_from_int()

static thandle_t thandle_from_int ( int  ifd)
inlinestatic

Definition at line 57 of file tif_win32.c.

58{
59 return (thandle_t)(intptr_t)ifd;
60}
int intptr_t
Definition: corecrt.h:176

Referenced by TIFFFdOpenExt().

◆ thandle_to_int()

static int thandle_to_int ( thandle_t  fd)
inlinestatic

Definition at line 62 of file tif_win32.c.

62{ return (int)(intptr_t)fd; }

Referenced by TIFFOpenExt(), and TIFFOpenWExt().

◆ TIFFFdOpen()

TIFF * TIFFFdOpen ( int  ifd,
const char name,
const char mode 
)

Definition at line 208 of file tif_win32.c.

209{
210 return TIFFFdOpenExt(ifd, name, mode, NULL);
211}
GLenum mode
Definition: glext.h:6217
Definition: name.c:39
TIFF * TIFFFdOpenExt(int ifd, const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_win32.c:213

◆ TIFFFdOpenExt()

TIFF * TIFFFdOpenExt ( int  ifd,
const char name,
const char mode,
TIFFOpenOptions opts 
)

Definition at line 213 of file tif_win32.c.

215{
216 TIFF *tif;
217 int fSuppressMap;
218 int m;
219
220 fSuppressMap = 0;
221 for (m = 0; mode[m] != 0; m++)
222 {
223 if (mode[m] == 'u')
224 {
225 fSuppressMap = 1;
226 break;
227 }
228 }
229
230 tif = TIFFClientOpenExt(
233 fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
234 fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc, opts);
235 if (tif)
236 tif->tif_fd = ifd;
237 return (tif);
238}
Definition: tiffiop.h:113
int tif_fd
Definition: tiffiop.h:115
TIFF * TIFFClientOpenExt(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc, TIFFOpenOptions *opts)
Definition: tif_open.c:300
int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_open.c:40
void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_open.c:48
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_win32.c:64
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_win32.c:196
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_win32.c:93
static thandle_t thandle_from_int(int ifd)
Definition: tif_win32.c:57
static uint64_t _tiffSeekProc(thandle_t fd, uint64_t off, int whence)
Definition: tif_win32.c:122
static int _tiffCloseProc(thandle_t fd)
Definition: tif_win32.c:150
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_win32.c:172

Referenced by TIFFFdOpen(), TIFFOpenExt(), and TIFFOpenWExt().

◆ TIFFOpen()

TIFF * TIFFOpen ( const char name,
const char mode 
)

Definition at line 245 of file tif_win32.c.

246{
247 return TIFFOpenExt(name, mode, NULL);
248}
TIFF * TIFFOpenExt(const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_win32.c:250

◆ TIFFOpenExt()

TIFF * TIFFOpenExt ( const char name,
const char mode,
TIFFOpenOptions opts 
)

Definition at line 250 of file tif_win32.c.

251{
252 static const char module[] = "TIFFOpen";
254 int m;
255 DWORD dwMode;
256 TIFF *tif;
257
258 m = _TIFFgetMode(opts, NULL, mode, module);
259
260 switch (m)
261 {
262 case O_RDONLY:
263 dwMode = OPEN_EXISTING;
264 break;
265 case O_RDWR:
266 dwMode = OPEN_EXISTING;
267 break;
268 case O_RDWR | O_CREAT:
269 dwMode = OPEN_ALWAYS;
270 break;
271 case O_RDWR | O_TRUNC:
272 dwMode = CREATE_ALWAYS;
273 break;
274 case O_RDWR | O_CREAT | O_TRUNC:
275 dwMode = CREATE_ALWAYS;
276 break;
277 default:
278 return ((TIFF *)0);
279 }
280
285 NULL);
287 {
288 _TIFFErrorEarly(opts, NULL, module, "%s: Cannot open", name);
289 return ((TIFF *)0);
290 }
291
292 tif = TIFFFdOpenExt(thandle_to_int(fd), name, mode, opts);
293 if (!tif)
295 return tif;
296}
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define O_CREAT
Definition: fcntl.h:43
#define O_RDONLY
Definition: fcntl.h:34
#define O_RDWR
Definition: fcntl.h:36
#define O_TRUNC
Definition: fcntl.h:44
#define CREATE_ALWAYS
Definition: disk.h:72
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define GENERIC_WRITE
Definition: nt_native.h:90
void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
Definition: tif_error.c:80
int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
Definition: tif_open.c:55
static int thandle_to_int(thandle_t fd)
Definition: tif_win32.c:62
void * thandle_t
Definition: tiffio.h:106

Referenced by TIFFOpen().

◆ TIFFOpenW()

TIFF * TIFFOpenW ( const wchar_t name,
const char mode 
)

Definition at line 301 of file tif_win32.c.

302{
303 return TIFFOpenWExt(name, mode, NULL);
304}
TIFF * TIFFOpenWExt(const wchar_t *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_win32.c:306

◆ TIFFOpenWExt()

TIFF * TIFFOpenWExt ( const wchar_t name,
const char mode,
TIFFOpenOptions opts 
)

Definition at line 306 of file tif_win32.c.

307{
308 static const char module[] = "TIFFOpenW";
310 int m;
311 DWORD dwMode;
312 int mbsize;
313 char *mbname;
314 TIFF *tif;
315
316 m = _TIFFgetMode(opts, NULL, mode, module);
317
318 switch (m)
319 {
320 case O_RDONLY:
321 dwMode = OPEN_EXISTING;
322 break;
323 case O_RDWR:
324 dwMode = OPEN_EXISTING;
325 break;
326 case O_RDWR | O_CREAT:
327 dwMode = OPEN_ALWAYS;
328 break;
329 case O_RDWR | O_TRUNC:
330 dwMode = CREATE_ALWAYS;
331 break;
332 case O_RDWR | O_CREAT | O_TRUNC:
333 dwMode = CREATE_ALWAYS;
334 break;
335 default:
336 return ((TIFF *)0);
337 }
338
343 NULL);
345 {
346 _TIFFErrorEarly(opts, NULL, module, "%S: Cannot open", name);
347 return ((TIFF *)0);
348 }
349
350 mbname = NULL;
351 mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
352 if (mbsize > 0)
353 {
354 mbname = (char *)_TIFFmalloc(mbsize);
355 if (!mbname)
356 {
358 opts, NULL, module,
359 "Can't allocate space for filename conversion buffer");
360 return ((TIFF *)0);
361 }
362
363 WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, NULL, NULL);
364 }
365
367 (mbname != NULL) ? mbname : "<unknown>", mode, opts);
368 if (!tif)
370
371 _TIFFfree(mbname);
372
373 return tif;
374}
#define CP_ACP
Definition: compat.h:109
#define CreateFileW
Definition: compat.h:741
#define WideCharToMultiByte
Definition: compat.h:111
void _TIFFfree(void *p)
Definition: tif_win32.c:394
void * _TIFFmalloc(tmsize_t s)
Definition: tif_win32.c:378

Referenced by TIFFOpenW().

◆ Win32ErrorHandler()

static void Win32ErrorHandler ( const char module,
const char fmt,
va_list  ap 
)
static

Definition at line 422 of file tif_win32.c.

423{
424 if (module != NULL)
425 fprintf(stderr, "%s: ", module);
427 fprintf(stderr, ".\n");
428}
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
Definition: file.c:5349
#define stderr
Definition: dsound.c:943
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ Win32WarningHandler()

static void Win32WarningHandler ( const char module,
const char fmt,
va_list  ap 
)
static

Definition at line 412 of file tif_win32.c.

413{
414 if (module != NULL)
415 fprintf(stderr, "%s: ", module);
416 fprintf(stderr, "Warning, ");
418 fprintf(stderr, ".\n");
419}

Variable Documentation

◆ _TIFFerrorHandler

TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler

Definition at line 429 of file tif_win32.c.

◆ _TIFFwarningHandler

TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler

Definition at line 420 of file tif_win32.c.