ReactOS  0.4.14-dev-297-g23e575c
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 _tiffSeekProc (thandle_t fd, uint64 off, int whence)
 
static int _tiffCloseProc (thandle_t fd)
 
static uint64 _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)
 
TIFFTIFFOpen (const char *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 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 57 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 317 of file tif_unix.c.

318 {
319  if( nmemb == 0 || siz == 0 )
320  return ((void *) NULL);
321 
322  return calloc((size_t) nmemb, (size_t)siz);
323 }
smooth NULL
Definition: ftsmooth.c:416
#define calloc
Definition: rosglue.h:14

Referenced by TIFFReadBufferSetup(), and TIFFReadDirectory().

◆ _tiffCloseProc()

static int _tiffCloseProc ( thandle_t  fd)
static

Definition at line 138 of file tif_unix.c.

139 {
141  fdh.h = fd;
142  return(close(fdh.fd));
143 }
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
#define close
Definition: acwin.h:98

Referenced by TIFFFdOpen().

◆ _TIFFfree()

void _TIFFfree ( void p)

Definition at line 326 of file tif_unix.c.

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

Referenced by _TIFFCreateAnonField(), _TIFFRewriteField(), _TIFFSetupFields(), _TIFFVSetField(), ChopUpSingleUncompressedStrip(), EstimateStripByteCounts(), fpAcc(), fpDiff(), gtStripContig(), gtStripSeparate(), gtTileContig(), gtTileSeparate(), initCIELabConversion(), PredictorEncodeTile(), setByteArray(), setDoubleArrayOneValue(), setupMap(), TIFFCleanup(), TIFFDefaultDirectory(), TIFFDefaultTransferFunction(), TIFFFetchDirectory(), TIFFFetchNormalTag(), TIFFFetchStripThing(), TIFFFillStrip(), TIFFFillTile(), TIFFFreeDirectory(), TIFFGetConfiguredCODECs(), TIFFGrowStrips(), TIFFPrintDirectory(), TIFFReadAndRealloc(), TIFFReadBufferSetup(), TIFFReadCustomDirectory(), TIFFReadDirectory(), TIFFReadDirEntryArrayWithLimit(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntryPersampleShort(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRGBAImageEnd(), TIFFUnlinkDirectory(), TIFFUnRegisterCODEC(), TIFFUnsetField(), TIFFWriteBufferSetup(), TIFFWriteDirectorySec(), TIFFWriteDirectoryTagCheckedRationalArray(), TIFFWriteDirectoryTagCheckedSrationalArray(), TIFFWriteDirectoryTagColormap(), TIFFWriteDirectoryTagIfdIfd8Array(), TIFFWriteDirectoryTagLongLong8Array(), TIFFWriteDirectoryTagSampleformatArray(), TIFFWriteDirectoryTagShortPerSample(), TIFFWriteDirectoryTagSubifd(), and TIFFWriteDirectoryTagTransferfunction().

◆ _TIFFmalloc()

void* _TIFFmalloc ( tmsize_t  s)

Definition at line 309 of file tif_unix.c.

310 {
311  if (s == 0)
312  return ((void *) NULL);
313 
314  return (malloc((size_t) s));
315 }
smooth NULL
Definition: ftsmooth.c:416
GLdouble s
Definition: gl.h:2039
#define malloc
Definition: debug_ros.c:4

Referenced by _TIFFCreateAnonField(), _TIFFReadEncodedStripAndAllocBuffer(), _TIFFReadEncodedTileAndAllocBuffer(), BuildMapBitdepth16To8(), BuildMapUaToAa(), fpAcc(), fpDiff(), initCIELabConversion(), initYCbCrConversion(), makebwmap(), makecmap(), PredictorEncodeTile(), setByteArray(), setDoubleArrayOneValue(), setupMap(), TIFFClientOpen(), TIFFDefaultRefBlackWhite(), TIFFDefaultTransferFunction(), TIFFFetchNormalTag(), TIFFPrintDirectory(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRegisterCODEC(), TIFFRGBAImageBegin(), TIFFSetClientInfo(), TIFFWriteBufferSetup(), TIFFWriteDirectorySec(), TIFFWriteDirectoryTagCheckedRationalArray(), TIFFWriteDirectoryTagCheckedSrationalArray(), TIFFWriteDirectoryTagColormap(), TIFFWriteDirectoryTagIfdIfd8Array(), TIFFWriteDirectoryTagLongLong8Array(), TIFFWriteDirectoryTagSampleformatArray(), TIFFWriteDirectoryTagShortPerSample(), TIFFWriteDirectoryTagSubifd(), and TIFFWriteDirectoryTagTransferfunction().

◆ _tiffMapProc()

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

Definition at line 186 of file tif_unix.c.

187 {
188  (void) fd; (void) pbase; (void) psize;
189  return (0);
190 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
static int fd
Definition: io.c:51

Referenced by TIFFFdOpen().

◆ _TIFFmemcmp()

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

Definition at line 350 of file tif_unix.c.

351 {
352  return (memcmp(p1, p2, (size_t) c));
353 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
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 67 of file tif_unix.c.

68 {
70  const size_t bytes_total = (size_t) size;
71  size_t bytes_read;
72  tmsize_t count = -1;
73  if ((tmsize_t) bytes_total != size)
74  {
75  errno=EINVAL;
76  return (tmsize_t) -1;
77  }
78  fdh.h = fd;
79  for (bytes_read=0; bytes_read < bytes_total; bytes_read+=count)
80  {
81  char *buf_offset = (char *) buf+bytes_read;
82  size_t io_size = bytes_total-bytes_read;
83  if (io_size > TIFF_IO_MAX)
84  io_size = TIFF_IO_MAX;
85  count=read(fdh.fd, buf_offset, (TIFFIOSize_t) io_size);
86  if (count <= 0)
87  break;
88  }
89  if (count < 0)
90  return (tmsize_t)-1;
91  return (tmsize_t) bytes_read;
92 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
int errno
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
__kernel_size_t size_t
Definition: linux.h:237
GLsizeiptr size
Definition: glext.h:5919
size_t TIFFIOSize_t
Definition: tiffiop.h:305
#define TIFF_IO_MAX
Definition: tif_unix.c:57
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by TIFFFdOpen().

◆ _TIFFrealloc()

void* _TIFFrealloc ( void p,
tmsize_t  s 
)

Definition at line 332 of file tif_unix.c.

333 {
334  return (realloc(p, (size_t) s));
335 }
#define realloc
Definition: debug_ros.c:6
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by _TIFFCheckRealloc(), _TIFFVSetField(), TIFFGetConfiguredCODECs(), TIFFGrowStrips(), TIFFReadAndRealloc(), and TIFFReadDirEntryDataAndRealloc().

◆ _tiffSeekProc()

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

Definition at line 124 of file tif_unix.c.

125 {
127  _TIFF_off_t off_io = (_TIFF_off_t) off;
128  if ((uint64) off_io != off)
129  {
130  errno=EINVAL;
131  return (uint64) -1; /* this is really gross */
132  }
133  fdh.h = fd;
134  return((uint64)_TIFF_lseek_f(fdh.fd,off_io,whence));
135 }
unsigned long long uint64
Definition: platform.h:18
Definition: arc.h:39
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
int errno
#define _TIFF_lseek_f(fildes, offset, whence)
Definition: tiffiop.h:306
#define _TIFF_off_t
Definition: tiffiop.h:313
off
Definition: i386-dis.c:3909

Referenced by TIFFFdOpen().

◆ _tiffSizeProc()

static uint64 _tiffSizeProc ( thandle_t  fd)
static

Definition at line 146 of file tif_unix.c.

147 {
150  fdh.h = fd;
151  if (_TIFF_fstat_f(fdh.fd,&sb)<0)
152  return(0);
153  else
154  return((uint64)sb.st_size);
155 }
unsigned long long uint64
Definition: platform.h:18
superblock * sb
Definition: btrfs.c:4162
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
#define _TIFF_fstat_f(fildes, stat_buff)
Definition: tiffiop.h:309
#define _TIFF_stat_s
Definition: tiffiop.h:312

Referenced by TIFFFdOpen().

◆ _tiffUnmapProc()

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

Definition at line 193 of file tif_unix.c.

194 {
195  (void) fd; (void) base; (void) size;
196 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
static int fd
Definition: io.c:51
GLsizeiptr size
Definition: glext.h:5919

Referenced by TIFFFdOpen().

◆ _tiffWriteProc()

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

Definition at line 95 of file tif_unix.c.

96 {
98  const size_t bytes_total = (size_t) size;
99  size_t bytes_written;
100  tmsize_t count = -1;
101  if ((tmsize_t) bytes_total != size)
102  {
103  errno=EINVAL;
104  return (tmsize_t) -1;
105  }
106  fdh.h = fd;
107  for (bytes_written=0; bytes_written < bytes_total; bytes_written+=count)
108  {
109  const char *buf_offset = (char *) buf+bytes_written;
110  size_t io_size = bytes_total-bytes_written;
111  if (io_size > TIFF_IO_MAX)
112  io_size = TIFF_IO_MAX;
113  count=write(fdh.fd, buf_offset, (TIFFIOSize_t) io_size);
114  if (count <= 0)
115  break;
116  }
117  if (count < 0)
118  return (tmsize_t)-1;
119  return (tmsize_t) bytes_written;
120  /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */
121 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
int errno
#define write
Definition: acwin.h:97
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
__kernel_size_t size_t
Definition: linux.h:237
GLsizeiptr size
Definition: glext.h:5919
size_t TIFFIOSize_t
Definition: tiffiop.h:305
#define TIFF_IO_MAX
Definition: tif_unix.c:57

Referenced by TIFFFdOpen().

◆ TIFFFdOpen()

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

Definition at line 203 of file tif_unix.c.

204 {
205  TIFF* tif;
206 
208  fdh.fd = fd;
209  tif = TIFFClientOpen(name, mode,
210  fdh.h,
214  if (tif)
215  tif->tif_fd = fd;
216  return (tif);
217 }
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:67
static int fd
Definition: io.c:51
thandle_t h
Definition: tif_unix.c:63
Definition: tiffiop.h:102
int tif_fd
Definition: tiffiop.h:104
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:95
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:72
static int _tiffCloseProc(thandle_t fd)
Definition: tif_unix.c:138
static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence)
Definition: tif_unix.c:124
static uint64 _tiffSizeProc(thandle_t fd)
Definition: tif_unix.c:146
GLenum mode
Definition: glext.h:6217
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_unix.c:186
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_unix.c:193
Definition: name.c:36

Referenced by TIFFOpen().

◆ TIFFOpen()

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

Definition at line 223 of file tif_unix.c.

224 {
225  static const char module[] = "TIFFOpen";
226  int m, fd;
227  TIFF* tif;
228 
230  if (m == -1)
231  return ((TIFF*)0);
232 
233 /* for cygwin and mingw */
234 #ifdef O_BINARY
235  m |= O_BINARY;
236 #endif
237 
238  fd = open(name, m, 0666);
239  if (fd < 0) {
240  if (errno > 0 && strerror(errno) != NULL ) {
241  TIFFErrorExt(0, module, "%s: %s", name, strerror(errno) );
242  } else {
243  TIFFErrorExt(0, module, "%s: Cannot open", name);
244  }
245  return ((TIFF *)0);
246  }
247 
248  tif = TIFFFdOpen((int)fd, name, mode);
249  if(!tif)
250  close(fd);
251  return tif;
252 }
#define open
Definition: acwin.h:95
TIFF * TIFFFdOpen(int fd, const char *name, const char *mode)
Definition: tif_unix.c:203
static int fd
Definition: io.c:51
int errno
const char * strerror(int err)
Definition: compat_str.c:23
const GLfloat * m
Definition: glext.h:10848
Definition: tiffiop.h:102
smooth NULL
Definition: ftsmooth.c:416
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define close
Definition: acwin.h:98
GLenum mode
Definition: glext.h:6217
int _TIFFgetMode(const char *mode, const char *module)
Definition: tif_open.c:48
#define O_BINARY
Definition: acwin.h:109
Definition: name.c:36

◆ unixErrorHandler()

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

Definition at line 367 of file tif_unix.c.

368 {
369  if (module != NULL)
370  fprintf(stderr, "%s: ", module);
371  vfprintf(stderr, fmt, ap);
372  fprintf(stderr, ".\n");
373 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
FILE * stderr
_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

◆ unixWarningHandler()

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

Definition at line 356 of file tif_unix.c.

357 {
358  if (module != NULL)
359  fprintf(stderr, "%s: ", module);
360  fprintf(stderr, "Warning, ");
361  vfprintf(stderr, fmt, ap);
362  fprintf(stderr, ".\n");
363 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
FILE * stderr
_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

Variable Documentation

◆ _TIFFerrorHandler

TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler

Definition at line 374 of file tif_unix.c.

Referenced by TIFFError(), TIFFErrorExt(), and TIFFSetErrorHandler().

◆ _TIFFwarningHandler

TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler

Definition at line 364 of file tif_unix.c.

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