ReactOS 0.4.15-dev-8119-g4fb2fdb
tif_win32.c File Reference
#include <precomp.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <winnls.h>
Include dependency graph for tif_win32.c:

Go to the source code of this file.

Macros

#define vsnprintf   _vsnprintf
 

Functions

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 _tiffSeekProc (thandle_t fd, uint64 off, int whence)
 
static int _tiffCloseProc (thandle_t fd)
 
static uint64 _tiffSizeProc (thandle_t fd)
 
static int _tiffDummyMapProc (thandle_t fd, void **pbase, toff_t *psize)
 
static int _tiffMapProc (thandle_t fd, void **pbase, toff_t *psize)
 
static void _tiffDummyUnmapProc (thandle_t fd, void *base, toff_t size)
 
static void _tiffUnmapProc (thandle_t fd, void *base, toff_t size)
 
TIFFTIFFFdOpen (int ifd, const char *name, const char *mode)
 
TIFFTIFFOpen (const char *name, const char *mode)
 
TIFFTIFFOpenW (const wchar_t *name, const char *mode)
 
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
 

Macro Definition Documentation

◆ vsnprintf

#define vsnprintf   _vsnprintf

Definition at line 406 of file tif_win32.c.

Function Documentation

◆ _TIFFcalloc()

void * _TIFFcalloc ( tmsize_t  nmemb,
tmsize_t  siz 
)

Definition at line 365 of file tif_win32.c.

366{
367 if( nmemb == 0 || siz == 0 )
368 return ((void *) NULL);
369
370 return calloc((size_t) nmemb, (size_t)siz);
371}
#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.

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

Referenced by TIFFFdOpen().

◆ _tiffDummyMapProc()

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

Definition at line 164 of file tif_win32.c.

165{
166 (void) fd;
167 (void) pbase;
168 (void) psize;
169 return (0);
170}
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569

Referenced by TIFFFdOpen().

◆ _tiffDummyUnmapProc()

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

Definition at line 209 of file tif_win32.c.

210{
211 (void) fd;
212 (void) base;
213 (void) size;
214}
GLsizeiptr size
Definition: glext.h:5919

Referenced by TIFFFdOpen().

◆ _TIFFfree()

void _TIFFfree ( void p)

Definition at line 374 of file tif_win32.c.

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

Referenced by TIFFOpenW().

◆ _TIFFmalloc()

void * _TIFFmalloc ( tmsize_t  s)

Definition at line 357 of file tif_win32.c.

358{
359 if (s == 0)
360 return ((void *) NULL);
361
362 return (malloc((size_t) s));
363}
#define malloc
Definition: debug_ros.c:4
GLdouble s
Definition: gl.h:2039

Referenced by TIFFOpenW().

◆ _tiffMapProc()

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

Definition at line 184 of file tif_win32.c.

185{
186 uint64 size;
187 tmsize_t sizem;
188 HANDLE hMapFile;
189
191 sizem = (tmsize_t)size;
192 if ((uint64)sizem!=size)
193 return (0);
194
195 /* By passing in 0 for the maximum file size, it specifies that we
196 create a file mapping object for the full file size. */
197 hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL);
198 if (hMapFile == NULL)
199 return (0);
200 *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
201 CloseHandle(hMapFile);
202 if (*pbase == NULL)
203 return (0);
204 *psize = size;
205 return(1);
206}
#define PAGE_READONLY
Definition: compat.h:138
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
unsigned long long uint64
Definition: platform.h:18
static uint64 _tiffSizeProc(thandle_t fd)
Definition: tif_win32.c:156
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
#define CreateFileMapping
Definition: winbase.h:3750

Referenced by TIFFFdOpen().

◆ _TIFFmemcmp()

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

Definition at line 398 of file tif_win32.c.

399{
400 return (memcmp(p1, p2, (size_t) c));
401}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
const GLubyte * c
Definition: glext.h:8905

◆ _TIFFmemcpy()

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

Definition at line 392 of file tif_win32.c.

393{
394 memcpy(d, s, (size_t) c);
395}
#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 386 of file tif_win32.c.

387{
388 memset(p, v, (size_t) c);
389}
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 63 of file tif_win32.c.

64{
65 /* tmsize_t is 64bit on 64bit systems, but the WinAPI ReadFile takes
66 * 32bit sizes, so we loop through the data in suitable 32bit sized
67 * chunks */
68 uint8* ma;
69 uint64 mb;
70 DWORD n;
71 DWORD o;
72 tmsize_t p;
73 ma=(uint8*)buf;
74 mb=size;
75 p=0;
76 while (mb>0)
77 {
78 n=0x80000000UL;
79 if ((uint64)n>mb)
80 n=(DWORD)mb;
81 if (!ReadFile(fd,(LPVOID)ma,n,&o,NULL))
82 return(0);
83 ma+=o;
84 mb-=o;
85 p+=o;
86 if (o!=n)
87 break;
88 }
89 return(p);
90}
unsigned char uint8
Definition: types.h:28
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
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 TIFFFdOpen().

◆ _TIFFrealloc()

void * _TIFFrealloc ( void p,
tmsize_t  s 
)

Definition at line 380 of file tif_win32.c.

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

◆ _tiffSeekProc()

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

Definition at line 123 of file tif_win32.c.

124{
125 LARGE_INTEGER offli;
126 DWORD dwMoveMethod;
127 offli.QuadPart = off;
128 switch(whence)
129 {
130 case SEEK_SET:
131 dwMoveMethod = FILE_BEGIN;
132 break;
133 case SEEK_CUR:
134 dwMoveMethod = FILE_CURRENT;
135 break;
136 case SEEK_END:
137 dwMoveMethod = FILE_END;
138 break;
139 default:
140 dwMoveMethod = FILE_BEGIN;
141 break;
142 }
143 offli.LowPart=SetFilePointer(fd,offli.LowPart,&offli.HighPart,dwMoveMethod);
145 offli.QuadPart=0;
146 return(offli.QuadPart);
147}
#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_SET
Definition: jmemansi.c:26
#define SEEK_CUR
Definition: util.h:63
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
#define FILE_END
Definition: winbase.h:114
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_CURRENT
Definition: winbase.h:113

Referenced by TIFFFdOpen().

◆ _tiffSizeProc()

static uint64 _tiffSizeProc ( thandle_t  fd)
static

Definition at line 156 of file tif_win32.c.

157{
159 m.LowPart=GetFileSize(fd,&m.HighPart);
160 return(m.QuadPart);
161}
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
const GLfloat * m
Definition: glext.h:10848

Referenced by _tiffMapProc(), and TIFFFdOpen().

◆ _tiffUnmapProc()

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

Definition at line 217 of file tif_win32.c.

218{
219 (void) fd;
220 (void) size;
222}
#define UnmapViewOfFile
Definition: compat.h:746

Referenced by TIFFFdOpen().

◆ _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* ma;
99 uint64 mb;
100 DWORD n;
101 DWORD o;
102 tmsize_t p;
103 ma=(uint8*)buf;
104 mb=size;
105 p=0;
106 while (mb>0)
107 {
108 n=0x80000000UL;
109 if ((uint64)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 TIFFFdOpen().

◆ TIFFFdOpen()

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

Definition at line 230 of file tif_win32.c.

231{
232 TIFF* tif;
233 int fSuppressMap;
234 int m;
235 fSuppressMap=0;
236 for (m=0; mode[m]!=0; m++)
237 {
238 if (mode[m]=='u')
239 {
240 fSuppressMap=1;
241 break;
242 }
243 }
244 tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */
247 fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
248 fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc);
249 if (tif)
250 tif->tif_fd = ifd;
251 return (tif);
252}
GLenum mode
Definition: glext.h:6217
Definition: name.c:39
Definition: tiffiop.h:115
int tif_fd
Definition: tiffiop.h:117
TIFF * TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc)
Definition: tif_open.c:71
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_win32.c:63
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_win32.c:217
static void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_win32.c:209
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_win32.c:93
static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence)
Definition: tif_win32.c:123
static int _tiffCloseProc(thandle_t fd)
Definition: tif_win32.c:150
static int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_win32.c:164
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_win32.c:184

Referenced by TIFFOpen(), and TIFFOpenW().

◆ TIFFOpen()

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

Definition at line 260 of file tif_win32.c.

261{
262 static const char module[] = "TIFFOpen";
264 int m;
265 DWORD dwMode;
266 TIFF* tif;
267
269
270 switch(m) {
271 case O_RDONLY: dwMode = OPEN_EXISTING; break;
272 case O_RDWR: dwMode = OPEN_ALWAYS; break;
273 case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break;
274 case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break;
275 case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break;
276 default: return ((TIFF*)0);
277 }
278
283 NULL);
284 if (fd == INVALID_HANDLE_VALUE) {
285 TIFFErrorExt(0, module, "%s: Cannot open", name);
286 return ((TIFF *)0);
287 }
288
289 tif = TIFFFdOpen((int)fd, name, mode); /* FIXME: WIN64 cast from pointer to int warning */
290 if(!tif)
292 return tif;
293}
#define O_CREAT
Definition: acwin.h:110
#define O_RDONLY
Definition: acwin.h:108
#define O_TRUNC
Definition: acwin.h:112
#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_RDWR
Definition: fcntl.h:36
#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 TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
int _TIFFgetMode(const char *mode, const char *module)
Definition: tif_open.c:47
TIFF * TIFFFdOpen(int ifd, const char *name, const char *mode)
Definition: tif_win32.c:230
void * thandle_t
Definition: tiffio.h:104

◆ TIFFOpenW()

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

Definition at line 299 of file tif_win32.c.

300{
301 static const char module[] = "TIFFOpenW";
303 int m;
304 DWORD dwMode;
305 int mbsize;
306 char *mbname;
307 TIFF *tif;
308
310
311 switch(m) {
312 case O_RDONLY: dwMode = OPEN_EXISTING; break;
313 case O_RDWR: dwMode = OPEN_ALWAYS; break;
314 case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break;
315 case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break;
316 case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break;
317 default: return ((TIFF*)0);
318 }
319
324 NULL);
325 if (fd == INVALID_HANDLE_VALUE) {
326 TIFFErrorExt(0, module, "%S: Cannot open", name);
327 return ((TIFF *)0);
328 }
329
330 mbname = NULL;
331 mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
332 if (mbsize > 0) {
333 mbname = (char *)_TIFFmalloc(mbsize);
334 if (!mbname) {
336 "Can't allocate space for filename conversion buffer");
337 return ((TIFF*)0);
338 }
339
340 WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize,
341 NULL, NULL);
342 }
343
344 tif = TIFFFdOpen((int)fd, /* FIXME: WIN64 cast from pointer to int warning */
345 (mbname != NULL) ? mbname : "<unknown>", mode);
346 if(!tif)
348
349 _TIFFfree(mbname);
350
351 return tif;
352}
#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:374
void * _TIFFmalloc(tmsize_t s)
Definition: tif_win32.c:357

◆ Win32ErrorHandler()

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

Definition at line 421 of file tif_win32.c.

422{
423 if (module != NULL)
424 fprintf(stderr, "%s: ", module);
426 fprintf(stderr, ".\n");
427}
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
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 410 of file tif_win32.c.

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

Variable Documentation

◆ _TIFFerrorHandler

TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler

Definition at line 428 of file tif_win32.c.

◆ _TIFFwarningHandler

TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler

Definition at line 418 of file tif_win32.c.