ReactOS 0.4.16-dev-2617-g01a0906
tif_unix.c File Reference
#include "tif_config.h"
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "tiffiop.h"
Include dependency graph for tif_unix.c:

Go to the source code of this file.

Classes

union  fd_as_handle_union
 

Macros

#define TIFF_IO_MAX   2147483647U
 

Typedefs

typedef union fd_as_handle_union fd_as_handle_union_t
 

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_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 fd, const char *name, const char *mode)
 
TIFFTIFFFdOpenExt (int fd, const char *name, const char *mode, TIFFOpenOptions *opts)
 
TIFFTIFFOpen (const char *name, const char *mode)
 
TIFFTIFFOpenExt (const char *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 unixWarningHandler (const char *module, const char *fmt, va_list ap)
 
static void unixErrorHandler (const char *module, const char *fmt, va_list ap)
 

Variables

TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler
 
TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler
 

Macro Definition Documentation

◆ TIFF_IO_MAX

#define TIFF_IO_MAX   2147483647U

Definition at line 60 of file tif_unix.c.

Typedef Documentation

◆ fd_as_handle_union_t

Function Documentation

◆ _TIFFcalloc()

void * _TIFFcalloc ( tmsize_t  nmemb,
tmsize_t  siz 
)

Definition at line 341 of file tif_unix.c.

342{
343 if (nmemb == 0 || siz == 0)
344 return ((void *)NULL);
345
346 return calloc((size_t)nmemb, (size_t)siz);
347}
#define NULL
Definition: types.h:112
#define calloc
Definition: rosglue.h:14

Referenced by _TIFFcallocExt(), and TIFFOpenOptionsAlloc().

◆ _tiffCloseProc()

static int _tiffCloseProc ( thandle_t  fd)
static

Definition at line 144 of file tif_unix.c.

145{
147 fdh.h = fd;
148 return (close(fdh.fd));
149}
#define close
Definition: acwin.h:98
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:65

Referenced by TIFFFdOpenExt().

◆ _TIFFfree()

void _TIFFfree ( void p)

Definition at line 349 of file tif_unix.c.

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

Referenced by _TIFFfreeExt(), and TIFFOpenOptionsFree().

◆ _TIFFmalloc()

void * _TIFFmalloc ( tmsize_t  s)

Definition at line 333 of file tif_unix.c.

334{
335 if (s == 0)
336 return ((void *)NULL);
337
338 return (malloc((size_t)s));
339}
#define malloc
Definition: debug_ros.c:4
GLdouble s
Definition: gl.h:2039

Referenced by _TIFFmallocExt().

◆ _tiffMapProc()

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

Definition at line 190 of file tif_unix.c.

191{
192 (void)fd;
193 (void)pbase;
194 (void)psize;
195 return (0);
196}
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569

Referenced by TIFFFdOpenExt().

◆ _TIFFmemcmp()

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

Definition at line 360 of file tif_unix.c.

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

Referenced by TIFFWriteDirectoryTagTransferfunction().

◆ _TIFFmemcpy()

◆ _TIFFmemset()

◆ _tiffReadProc()

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

Definition at line 68 of file tif_unix.c.

69{
71 const size_t bytes_total = (size_t)size;
72 size_t bytes_read;
73 tmsize_t count = -1;
74 if ((tmsize_t)bytes_total != size)
75 {
76 errno = EINVAL;
77 return (tmsize_t)-1;
78 }
79 fdh.h = fd;
80 for (bytes_read = 0; bytes_read < bytes_total; bytes_read += count)
81 {
82 char *buf_offset = (char *)buf + bytes_read;
83 size_t io_size = bytes_total - bytes_read;
84 if (io_size > TIFF_IO_MAX)
85 io_size = TIFF_IO_MAX;
86 /* Below is an obvious false positive of Coverity Scan */
87 /* coverity[overflow_sink] */
88 count = read(fdh.fd, buf_offset, (TIFFIOSize_t)io_size);
89 if (count <= 0)
90 break;
91 }
92 if (count < 0)
93 return (tmsize_t)-1;
94 /* Silence Coverity Scan warning about unsigned to signed underflow. */
95 /* coverity[return_overflow:SUPPRESS] */
96 return (tmsize_t)bytes_read;
97}
#define read
Definition: acwin.h:96
unsigned int size_t
Definition: corecrt.h:203
#define EINVAL
Definition: errno.h:44
#define errno
Definition: errno.h:120
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define TIFF_IO_MAX
Definition: tif_unix.c:60
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:67
size_t TIFFIOSize_t
Definition: tiffiop.h:374

Referenced by TIFFFdOpenExt().

◆ _TIFFrealloc()

void * _TIFFrealloc ( void p,
tmsize_t  s 
)

Definition at line 351 of file tif_unix.c.

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

Referenced by _TIFFreallocExt().

◆ _tiffSeekProc()

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

Definition at line 131 of file tif_unix.c.

132{
134 _TIFF_off_t off_io = (_TIFF_off_t)off;
135 if ((uint64_t)off_io != off)
136 {
137 errno = EINVAL;
138 return (uint64_t)-1; /* this is really gross */
139 }
140 fdh.h = fd;
141 return ((uint64_t)_TIFF_lseek_f(fdh.fd, off_io, whence));
142}
UINT64 uint64_t
Definition: types.h:77
#define _TIFF_lseek_f(fildes, offset, whence)
Definition: tiffiop.h:375
#define _TIFF_off_t
Definition: tiffiop.h:382

Referenced by TIFFFdOpenExt().

◆ _tiffSizeProc()

static uint64_t _tiffSizeProc ( thandle_t  fd)
static

Definition at line 151 of file tif_unix.c.

152{
155 fdh.h = fd;
156 if (_TIFF_fstat_f(fdh.fd, &sb) < 0)
157 return (0);
158 else
159 return ((uint64_t)sb.st_size);
160}
superblock * sb
Definition: btrfs.c:4261
#define _TIFF_fstat_f(fildes, stat_buff)
Definition: tiffiop.h:378
#define _TIFF_stat_s
Definition: tiffiop.h:381

Referenced by TIFFFdOpenExt().

◆ _tiffUnmapProc()

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

Definition at line 198 of file tif_unix.c.

199{
200 (void)fd;
201 (void)base;
202 (void)size;
203}

Referenced by TIFFFdOpenExt().

◆ _tiffWriteProc()

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

Definition at line 99 of file tif_unix.c.

100{
102 const size_t bytes_total = (size_t)size;
103 size_t bytes_written;
104 tmsize_t count = -1;
105 if ((tmsize_t)bytes_total != size)
106 {
107 errno = EINVAL;
108 return (tmsize_t)-1;
109 }
110 fdh.h = fd;
111 for (bytes_written = 0; bytes_written < bytes_total; bytes_written += count)
112 {
113 const char *buf_offset = (char *)buf + bytes_written;
114 size_t io_size = bytes_total - bytes_written;
115 if (io_size > TIFF_IO_MAX)
116 io_size = TIFF_IO_MAX;
117 /* Below is an obvious false positive of Coverity Scan */
118 /* coverity[overflow_sink] */
119 count = write(fdh.fd, buf_offset, (TIFFIOSize_t)io_size);
120 if (count <= 0)
121 break;
122 }
123 if (count < 0)
124 return (tmsize_t)-1;
125 /* Silence Coverity Scan warning about unsigned to signed underflow. */
126 /* coverity[return_overflow:SUPPRESS] */
127 return (tmsize_t)bytes_written;
128 /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */
129}
#define write
Definition: acwin.h:97

Referenced by TIFFFdOpenExt().

◆ TIFFFdOpen()

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

Definition at line 209 of file tif_unix.c.

210{
211 return TIFFFdOpenExt(fd, name, mode, NULL);
212}
GLenum mode
Definition: glext.h:6217
Definition: name.c:39
TIFF * TIFFFdOpenExt(int fd, const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_unix.c:214

◆ TIFFFdOpenExt()

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

Definition at line 214 of file tif_unix.c.

216{
217 TIFF *tif;
218
220 fdh.fd = fd;
224 if (tif)
225 tif->tif_fd = fd;
226 return (tif);
227}
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
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:68
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_unix.c:198
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:99
static uint64_t _tiffSeekProc(thandle_t fd, uint64_t off, int whence)
Definition: tif_unix.c:131
static int _tiffCloseProc(thandle_t fd)
Definition: tif_unix.c:144
static uint64_t _tiffSizeProc(thandle_t fd)
Definition: tif_unix.c:151
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_unix.c:190

Referenced by TIFFFdOpen(), and TIFFOpenExt().

◆ TIFFOpen()

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

Definition at line 232 of file tif_unix.c.

233{
234 return TIFFOpenExt(name, mode, NULL);
235}
TIFF * TIFFOpenExt(const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_unix.c:237

◆ TIFFOpenExt()

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

Definition at line 237 of file tif_unix.c.

238{
239 static const char module[] = "TIFFOpen";
240 int m, fd;
241 TIFF *tif;
242
243 m = _TIFFgetMode(opts, NULL, mode, module);
244 if (m == -1)
245 return ((TIFF *)0);
246
247/* for cygwin and mingw */
248#ifdef O_BINARY
249 m |= O_BINARY;
250#endif
251
252 fd = open(name, m, 0666);
253 if (fd < 0)
254 {
255 if (errno > 0 && strerror(errno) != NULL)
256 {
257 _TIFFErrorEarly(opts, NULL, module, "%s: %s", name,
258 strerror(errno));
259 }
260 else
261 {
262 _TIFFErrorEarly(opts, NULL, module, "%s: Cannot open", name);
263 }
264 return ((TIFF *)0);
265 }
266
267 tif = TIFFFdOpenExt((int)fd, name, mode, opts);
268 if (!tif)
269 close(fd);
270 return tif;
271}
char *CDECL strerror(int err)
Definition: errno.c:273
#define O_BINARY
Definition: fcntl.h:47
#define open
Definition: io.h:44
const GLfloat * m
Definition: glext.h:10848
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

Referenced by TIFFOpen().

◆ unixErrorHandler()

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

Definition at line 375 of file tif_unix.c.

376{
377 if (module != NULL)
378 fprintf(stderr, "%s: ", module);
380 fprintf(stderr, ".\n");
381}
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

◆ unixWarningHandler()

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

Definition at line 365 of file tif_unix.c.

366{
367 if (module != NULL)
368 fprintf(stderr, "%s: ", module);
369 fprintf(stderr, "Warning, ");
371 fprintf(stderr, ".\n");
372}

Variable Documentation

◆ _TIFFerrorHandler

◆ _TIFFwarningHandler

TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler

Definition at line 373 of file tif_unix.c.

Referenced by TIFFSetWarningHandler(), TIFFWarning(), TIFFWarningExt(), and TIFFWarningExtR().