Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/tiff/libtiff/tif_open.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 1988-1997 Sam Leffler
3
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software and 
6
 * its documentation for any purpose is hereby granted without fee, provided
7
 * that (i) the above copyright notices and this permission notice appear in
8
 * all copies of the software and related documentation, and (ii) the names of
9
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10
 * publicity relating to the software without the specific, prior written
11
 * permission of Sam Leffler and Silicon Graphics.
12
 * 
13
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
14
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
15
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
16
 * 
17
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
21
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
22
 * OF THIS SOFTWARE.
23
 */
24
25
/*
26
 * TIFF Library.
27
 */
28
#include "tiffiop.h"
29
30
/*
31
 * Dummy functions to fill the omitted client procedures.
32
 */
33
static int
34
_tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize)
35
0
{
36
0
  (void) fd; (void) pbase; (void) psize;
37
0
  return (0);
38
0
}
39
40
static void
41
_tiffDummyUnmapProc(thandle_t fd, void* base, toff_t size)
42
0
{
43
0
  (void) fd; (void) base; (void) size;
44
0
}
45
46
int
47
_TIFFgetMode(const char* mode, const char* module)
48
2.19k
{
49
2.19k
  int m = -1;
50
51
2.19k
  switch (mode[0]) {
52
0
  case 'r':
53
0
    m = O_RDONLY;
54
0
    if (mode[1] == '+')
55
0
      m = O_RDWR;
56
0
    break;
57
2.19k
  case 'w':
58
2.19k
  case 'a':
59
2.19k
    m = O_RDWR|O_CREAT;
60
2.19k
    if (mode[0] == 'w')
61
2.19k
      m |= O_TRUNC;
62
2.19k
    break;
63
0
  default:
64
0
    TIFFErrorExt(0, module, "\"%s\": Bad mode", mode);
65
0
    break;
66
2.19k
  }
67
2.19k
  return (m);
68
2.19k
}
69
70
TIFF*
71
TIFFClientOpen(
72
  const char* name, const char* mode,
73
  thandle_t clientdata,
74
  TIFFReadWriteProc readproc,
75
  TIFFReadWriteProc writeproc,
76
  TIFFSeekProc seekproc,
77
  TIFFCloseProc closeproc,
78
  TIFFSizeProc sizeproc,
79
  TIFFMapFileProc mapproc,
80
  TIFFUnmapFileProc unmapproc
81
)
82
2.19k
{
83
2.19k
  static const char module[] = "TIFFClientOpen";
84
2.19k
  TIFF *tif;
85
2.19k
  int m;
86
2.19k
  const char* cp;
87
88
  /* The following are configuration checks. They should be redundant, but should not
89
   * compile to any actual code in an optimised release build anyway. If any of them
90
   * fail, (makefile-based or other) configuration is not correct */
91
2.19k
  assert(sizeof(uint8_t) == 1);
92
2.19k
  assert(sizeof(int8_t) == 1);
93
2.19k
  assert(sizeof(uint16_t) == 2);
94
2.19k
  assert(sizeof(int16_t) == 2);
95
2.19k
  assert(sizeof(uint32_t) == 4);
96
2.19k
  assert(sizeof(int32_t) == 4);
97
2.19k
  assert(sizeof(uint64_t) == 8);
98
2.19k
  assert(sizeof(int64_t) == 8);
99
2.19k
  assert(sizeof(tmsize_t)==sizeof(void*));
100
2.19k
  {
101
2.19k
    union{
102
2.19k
      uint8_t a8[2];
103
2.19k
      uint16_t a16;
104
2.19k
    } n;
105
2.19k
    n.a8[0]=1;
106
2.19k
    n.a8[1]=0;
107
2.19k
                (void)n;
108
    #ifdef WORDS_BIGENDIAN
109
    assert(n.a16==256);
110
    #else
111
2.19k
    assert(n.a16==1);
112
2.19k
    #endif
113
2.19k
  }
114
115
2.19k
  m = _TIFFgetMode(mode, module);
116
2.19k
  if (m == -1)
117
0
    goto bad2;
118
2.19k
  tif = (TIFF *)_TIFFmalloc((tmsize_t)(sizeof (TIFF) + strlen(name) + 1));
119
2.19k
  if (tif == NULL) {
120
0
    TIFFErrorExt(clientdata, module, "%s: Out of memory (TIFF structure)", name);
121
0
    goto bad2;
122
0
  }
123
2.19k
  _TIFFmemset(tif, 0, sizeof (*tif));
124
2.19k
  tif->tif_name = (char *)tif + sizeof (TIFF);
125
2.19k
  strcpy(tif->tif_name, name);
126
2.19k
  tif->tif_mode = m &~ (O_CREAT|O_TRUNC);
127
2.19k
  tif->tif_curdir = (uint16_t) -1;    /* non-existent directory */
128
2.19k
  tif->tif_curoff = 0;
129
2.19k
  tif->tif_curstrip = (uint32_t) -1;  /* invalid strip */
130
2.19k
  tif->tif_row = (uint32_t) -1;   /* read/write pre-increment */
131
2.19k
  tif->tif_clientdata = clientdata;
132
2.19k
  if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) {
133
0
    TIFFErrorExt(clientdata, module,
134
0
        "One of the client procedures is NULL pointer.");
135
0
    _TIFFfree(tif);
136
0
    goto bad2;
137
0
  }
138
2.19k
  tif->tif_readproc = readproc;
139
2.19k
  tif->tif_writeproc = writeproc;
140
2.19k
  tif->tif_seekproc = seekproc;
141
2.19k
  tif->tif_closeproc = closeproc;
142
2.19k
  tif->tif_sizeproc = sizeproc;
143
2.19k
  if (mapproc)
144
2.19k
    tif->tif_mapproc = mapproc;
145
0
  else
146
0
    tif->tif_mapproc = _tiffDummyMapProc;
147
2.19k
  if (unmapproc)
148
2.19k
    tif->tif_unmapproc = unmapproc;
149
0
  else
150
0
    tif->tif_unmapproc = _tiffDummyUnmapProc;
151
2.19k
  _TIFFSetDefaultCompressionState(tif);    /* setup default state */
152
  /*
153
   * Default is to return data MSB2LSB and enable the
154
   * use of memory-mapped files and strip chopping when
155
   * a file is opened read-only.
156
   */
157
2.19k
  tif->tif_flags = FILLORDER_MSB2LSB;
158
2.19k
  if (m == O_RDONLY )
159
0
    tif->tif_flags |= TIFF_MAPPED;
160
161
2.19k
  #ifdef STRIPCHOP_DEFAULT
162
2.19k
  if (m == O_RDONLY || m == O_RDWR)
163
0
    tif->tif_flags |= STRIPCHOP_DEFAULT;
164
2.19k
  #endif
165
166
  /*
167
   * Process library-specific flags in the open mode string.
168
   * The following flags may be used to control intrinsic library
169
   * behavior that may or may not be desirable (usually for
170
   * compatibility with some application that claims to support
171
   * TIFF but only supports some brain dead idea of what the
172
   * vendor thinks TIFF is):
173
   *
174
   * 'l' use little-endian byte order for creating a file
175
   * 'b' use big-endian byte order for creating a file
176
   * 'L' read/write information using LSB2MSB bit order
177
   * 'B' read/write information using MSB2LSB bit order
178
   * 'H' read/write information using host bit order
179
   * 'M' enable use of memory-mapped files when supported
180
   * 'm' disable use of memory-mapped files
181
   * 'C' enable strip chopping support when reading
182
   * 'c' disable strip chopping support
183
   * 'h' read TIFF header only, do not load the first IFD
184
   * '4' ClassicTIFF for creating a file (default)
185
   * '8' BigTIFF for creating a file
186
         * 'D' enable use of deferred strip/tile offset/bytecount array loading.
187
         * 'O' on-demand loading of values instead of whole array loading (implies D)
188
   *
189
   * The use of the 'l' and 'b' flags is strongly discouraged.
190
   * These flags are provided solely because numerous vendors,
191
   * typically on the PC, do not correctly support TIFF; they
192
   * only support the Intel little-endian byte order.  This
193
   * support is not configured by default because it supports
194
   * the violation of the TIFF spec that says that readers *MUST*
195
   * support both byte orders.  It is strongly recommended that
196
   * you not use this feature except to deal with busted apps
197
   * that write invalid TIFF.  And even in those cases you should
198
   * bang on the vendors to fix their software.
199
   *
200
   * The 'L', 'B', and 'H' flags are intended for applications
201
   * that can optimize operations on data by using a particular
202
   * bit order.  By default the library returns data in MSB2LSB
203
   * bit order for compatibility with older versions of this
204
   * library.  Returning data in the bit order of the native CPU
205
   * makes the most sense but also requires applications to check
206
   * the value of the FillOrder tag; something they probably do
207
   * not do right now.
208
   *
209
   * The 'M' and 'm' flags are provided because some virtual memory
210
   * systems exhibit poor behavior when large images are mapped.
211
   * These options permit clients to control the use of memory-mapped
212
   * files on a per-file basis.
213
   *
214
   * The 'C' and 'c' flags are provided because the library support
215
   * for chopping up large strips into multiple smaller strips is not
216
   * application-transparent and as such can cause problems.  The 'c'
217
   * option permits applications that only want to look at the tags,
218
   * for example, to get the unadulterated TIFF tag information.
219
   */
220
6.57k
  for (cp = mode; *cp; cp++)
221
4.38k
    switch (*cp) {
222
0
      case 'b':
223
0
        #ifndef WORDS_BIGENDIAN
224
0
        if (m&O_CREAT)
225
0
          tif->tif_flags |= TIFF_SWAB;
226
0
        #endif
227
0
        break;
228
2.19k
      case 'l':
229
        #ifdef WORDS_BIGENDIAN
230
        if ((m&O_CREAT))
231
          tif->tif_flags |= TIFF_SWAB;
232
        #endif
233
2.19k
        break;
234
0
      case 'B':
235
0
        tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
236
0
            FILLORDER_MSB2LSB;
237
0
        break;
238
0
      case 'L':
239
0
        tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
240
0
            FILLORDER_LSB2MSB;
241
0
        break;
242
0
      case 'H':
243
0
        tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
244
0
            HOST_FILLORDER;
245
0
        break;
246
0
      case 'M':
247
0
        if (m == O_RDONLY)
248
0
          tif->tif_flags |= TIFF_MAPPED;
249
0
        break;
250
0
      case 'm':
251
0
        if (m == O_RDONLY)
252
0
          tif->tif_flags &= ~TIFF_MAPPED;
253
0
        break;
254
0
      case 'C':
255
0
        if (m == O_RDONLY)
256
0
          tif->tif_flags |= TIFF_STRIPCHOP;
257
0
        break;
258
0
      case 'c':
259
0
        if (m == O_RDONLY)
260
0
          tif->tif_flags &= ~TIFF_STRIPCHOP;
261
0
        break;
262
0
      case 'h':
263
0
        tif->tif_flags |= TIFF_HEADERONLY;
264
0
        break;
265
0
      case '8':
266
0
        if (m&O_CREAT)
267
0
          tif->tif_flags |= TIFF_BIGTIFF;
268
0
        break;
269
0
      case 'D':
270
0
              tif->tif_flags |= TIFF_DEFERSTRILELOAD;
271
0
        break;
272
0
      case 'O':
273
0
        if( m == O_RDONLY )
274
0
          tif->tif_flags |= (TIFF_LAZYSTRILELOAD | TIFF_DEFERSTRILELOAD);
275
0
        break;
276
4.38k
    }
277
278
#ifdef DEFER_STRILE_LOAD
279
        /* Compatibility with old DEFER_STRILE_LOAD compilation flag */
280
        /* Probably unneeded, since to the best of my knowledge (E. Rouault) */
281
        /* GDAL was the only user of this, and will now use the new 'D' flag */
282
        tif->tif_flags |= TIFF_DEFERSTRILELOAD;
283
#endif
284
285
  /*
286
   * Read in TIFF header.
287
   */
288
2.19k
  if ((m & O_TRUNC) ||
289
2.19k
      !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeaderClassic))) {
290
2.19k
    if (tif->tif_mode == O_RDONLY) {
291
0
      TIFFErrorExt(tif->tif_clientdata, name,
292
0
          "Cannot read TIFF header");
293
0
      goto bad;
294
0
    }
295
    /*
296
     * Setup header and write.
297
     */
298
    #ifdef WORDS_BIGENDIAN
299
    tif->tif_header.common.tiff_magic = (tif->tif_flags & TIFF_SWAB)
300
        ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN;
301
    #else
302
2.19k
    tif->tif_header.common.tiff_magic = (tif->tif_flags & TIFF_SWAB)
303
2.19k
        ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
304
2.19k
    #endif
305
2.19k
    if (!(tif->tif_flags&TIFF_BIGTIFF))
306
2.19k
    {
307
2.19k
      tif->tif_header.common.tiff_version = TIFF_VERSION_CLASSIC;
308
2.19k
      tif->tif_header.classic.tiff_diroff = 0;
309
2.19k
      if (tif->tif_flags & TIFF_SWAB)
310
0
        TIFFSwabShort(&tif->tif_header.common.tiff_version);
311
2.19k
      tif->tif_header_size = sizeof(TIFFHeaderClassic);
312
2.19k
    }
313
0
    else
314
0
    {
315
0
      tif->tif_header.common.tiff_version = TIFF_VERSION_BIG;
316
0
      tif->tif_header.big.tiff_offsetsize = 8;
317
0
      tif->tif_header.big.tiff_unused = 0;
318
0
      tif->tif_header.big.tiff_diroff = 0;
319
0
      if (tif->tif_flags & TIFF_SWAB)
320
0
      {
321
0
        TIFFSwabShort(&tif->tif_header.common.tiff_version);
322
0
        TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize);
323
0
      }
324
0
      tif->tif_header_size = sizeof (TIFFHeaderBig);
325
0
    }
326
    /*
327
     * The doc for "fopen" for some STD_C_LIBs says that if you
328
     * open a file for modify ("+"), then you must fseek (or
329
     * fflush?) between any freads and fwrites.  This is not
330
     * necessary on most systems, but has been shown to be needed
331
     * on Solaris.
332
     */
333
2.19k
    TIFFSeekFile( tif, 0, SEEK_SET );
334
2.19k
    if (!WriteOK(tif, &tif->tif_header, (tmsize_t)(tif->tif_header_size))) {
335
0
      TIFFErrorExt(tif->tif_clientdata, name,
336
0
          "Error writing TIFF header");
337
0
      goto bad;
338
0
    }
339
    /*
340
     * Setup the byte order handling.
341
     */
342
2.19k
    if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) {
343
0
      #ifndef WORDS_BIGENDIAN
344
0
      tif->tif_flags |= TIFF_SWAB;
345
0
      #endif
346
2.19k
    } else {
347
      #ifdef WORDS_BIGENDIAN
348
      tif->tif_flags |= TIFF_SWAB;
349
      #endif
350
2.19k
    }
351
    /*
352
     * Setup default directory.
353
     */
354
2.19k
    if (!TIFFDefaultDirectory(tif))
355
0
      goto bad;
356
2.19k
    tif->tif_diroff = 0;
357
2.19k
    tif->tif_dirlist = NULL;
358
2.19k
    tif->tif_dirlistsize = 0;
359
2.19k
    tif->tif_dirnumber = 0;
360
2.19k
    return (tif);
361
2.19k
  }
362
  /*
363
   * Setup the byte order handling.
364
   */
365
0
  if (tif->tif_header.common.tiff_magic != TIFF_BIGENDIAN &&
366
0
      tif->tif_header.common.tiff_magic != TIFF_LITTLEENDIAN
367
0
      #if MDI_SUPPORT
368
0
      &&
369
      #if HOST_BIGENDIAN
370
      tif->tif_header.common.tiff_magic != MDI_BIGENDIAN
371
      #else
372
0
      tif->tif_header.common.tiff_magic != MDI_LITTLEENDIAN
373
0
      #endif
374
0
      ) {
375
0
    TIFFErrorExt(tif->tif_clientdata, name,
376
0
        "Not a TIFF or MDI file, bad magic number %"PRIu16" (0x%"PRIx16")",
377
      #else
378
      ) {
379
    TIFFErrorExt(tif->tif_clientdata, name,
380
        "Not a TIFF file, bad magic number %"PRIu16" (0x%"PRIx16")",
381
      #endif
382
0
        tif->tif_header.common.tiff_magic,
383
0
        tif->tif_header.common.tiff_magic);
384
0
    goto bad;
385
0
  }
386
0
  if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) {
387
0
    #ifndef WORDS_BIGENDIAN
388
0
    tif->tif_flags |= TIFF_SWAB;
389
0
    #endif
390
0
  } else {
391
    #ifdef WORDS_BIGENDIAN
392
    tif->tif_flags |= TIFF_SWAB;
393
    #endif
394
0
  }
395
0
  if (tif->tif_flags & TIFF_SWAB) 
396
0
    TIFFSwabShort(&tif->tif_header.common.tiff_version);
397
0
  if ((tif->tif_header.common.tiff_version != TIFF_VERSION_CLASSIC)&&
398
0
      (tif->tif_header.common.tiff_version != TIFF_VERSION_BIG)) {
399
0
    TIFFErrorExt(tif->tif_clientdata, name,
400
0
        "Not a TIFF file, bad version number %"PRIu16" (0x%"PRIx16")",
401
0
        tif->tif_header.common.tiff_version,
402
0
        tif->tif_header.common.tiff_version);
403
0
    goto bad;
404
0
  }
405
0
  if (tif->tif_header.common.tiff_version == TIFF_VERSION_CLASSIC)
406
0
  {
407
0
    if (tif->tif_flags & TIFF_SWAB)
408
0
      TIFFSwabLong(&tif->tif_header.classic.tiff_diroff);
409
0
    tif->tif_header_size = sizeof(TIFFHeaderClassic);
410
0
  }
411
0
  else
412
0
  {
413
0
    if (!ReadOK(tif, ((uint8_t*)(&tif->tif_header) + sizeof(TIFFHeaderClassic)), (sizeof(TIFFHeaderBig) - sizeof(TIFFHeaderClassic))))
414
0
    {
415
0
      TIFFErrorExt(tif->tif_clientdata, name,
416
0
          "Cannot read TIFF header");
417
0
      goto bad;
418
0
    }
419
0
    if (tif->tif_flags & TIFF_SWAB)
420
0
    {
421
0
      TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize);
422
0
      TIFFSwabLong8(&tif->tif_header.big.tiff_diroff);
423
0
    }
424
0
    if (tif->tif_header.big.tiff_offsetsize != 8)
425
0
    {
426
0
      TIFFErrorExt(tif->tif_clientdata, name,
427
0
          "Not a TIFF file, bad BigTIFF offsetsize %"PRIu16" (0x%"PRIx16")",
428
0
          tif->tif_header.big.tiff_offsetsize,
429
0
          tif->tif_header.big.tiff_offsetsize);
430
0
      goto bad;
431
0
    }
432
0
    if (tif->tif_header.big.tiff_unused != 0)
433
0
    {
434
0
      TIFFErrorExt(tif->tif_clientdata, name,
435
0
          "Not a TIFF file, bad BigTIFF unused %"PRIu16" (0x%"PRIx16")",
436
0
          tif->tif_header.big.tiff_unused,
437
0
          tif->tif_header.big.tiff_unused);
438
0
      goto bad;
439
0
    }
440
0
    tif->tif_header_size = sizeof(TIFFHeaderBig);
441
0
    tif->tif_flags |= TIFF_BIGTIFF;
442
0
  }
443
0
  tif->tif_flags |= TIFF_MYBUFFER;
444
0
  tif->tif_rawcp = tif->tif_rawdata = 0;
445
0
  tif->tif_rawdatasize = 0;
446
0
        tif->tif_rawdataoff = 0;
447
0
        tif->tif_rawdataloaded = 0;
448
449
0
  switch (mode[0]) {
450
0
    case 'r':
451
0
      if (!(tif->tif_flags&TIFF_BIGTIFF))
452
0
        tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff;
453
0
      else
454
0
        tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff;
455
      /*
456
       * Try to use a memory-mapped file if the client
457
       * has not explicitly suppressed usage with the
458
       * 'm' flag in the open mode (see above).
459
       */
460
0
      if (tif->tif_flags & TIFF_MAPPED)
461
0
      {
462
0
        toff_t n;
463
0
        if (TIFFMapFileContents(tif,(void**)(&tif->tif_base),&n))
464
0
        {
465
0
          tif->tif_size=(tmsize_t)n;
466
0
          assert((toff_t)tif->tif_size==n);
467
0
        }
468
0
        else
469
0
          tif->tif_flags &= ~TIFF_MAPPED;
470
0
      }
471
      /*
472
       * Sometimes we do not want to read the first directory (for example,
473
       * it may be broken) and want to proceed to other directories. I this
474
       * case we use the TIFF_HEADERONLY flag to open file and return
475
       * immediately after reading TIFF header.
476
       */
477
0
      if (tif->tif_flags & TIFF_HEADERONLY)
478
0
        return (tif);
479
480
      /*
481
       * Setup initial directory.
482
       */
483
0
      if (TIFFReadDirectory(tif)) {
484
0
        tif->tif_rawcc = (tmsize_t)-1;
485
0
        tif->tif_flags |= TIFF_BUFFERSETUP;
486
0
        return (tif);
487
0
      }
488
0
      break;
489
0
    case 'a':
490
      /*
491
       * New directories are automatically append
492
       * to the end of the directory chain when they
493
       * are written out (see TIFFWriteDirectory).
494
       */
495
0
      if (!TIFFDefaultDirectory(tif))
496
0
        goto bad;
497
0
      return (tif);
498
0
  }
499
0
bad:
500
0
  tif->tif_mode = O_RDONLY; /* XXX avoid flush */
501
0
        TIFFCleanup(tif);
502
0
bad2:
503
0
  return ((TIFF*)0);
504
0
}
505
506
/*
507
 * Query functions to access private data.
508
 */
509
510
/*
511
 * Return open file's name.
512
 */
513
const char *
514
TIFFFileName(TIFF* tif)
515
914
{
516
914
  return (tif->tif_name);
517
914
}
518
519
/*
520
 * Set the file name.
521
 */
522
const char *
523
TIFFSetFileName(TIFF* tif, const char *name)
524
0
{
525
0
  const char* old_name = tif->tif_name;
526
0
  tif->tif_name = (char *)name;
527
0
  return (old_name);
528
0
}
529
530
/*
531
 * Return open file's I/O descriptor.
532
 */
533
int
534
TIFFFileno(TIFF* tif)
535
0
{
536
0
  return (tif->tif_fd);
537
0
}
538
539
/*
540
 * Set open file's I/O descriptor, and return previous value.
541
 */
542
int
543
TIFFSetFileno(TIFF* tif, int fd)
544
0
{
545
0
        int old_fd = tif->tif_fd;
546
0
  tif->tif_fd = fd;
547
0
  return old_fd;
548
0
}
549
550
/*
551
 * Return open file's clientdata.
552
 */
553
thandle_t
554
TIFFClientdata(TIFF* tif)
555
2.19k
{
556
2.19k
  return (tif->tif_clientdata);
557
2.19k
}
558
559
/*
560
 * Set open file's clientdata, and return previous value.
561
 */
562
thandle_t
563
TIFFSetClientdata(TIFF* tif, thandle_t newvalue)
564
0
{
565
0
  thandle_t m = tif->tif_clientdata;
566
0
  tif->tif_clientdata = newvalue;
567
0
  return m;
568
0
}
569
570
/*
571
 * Return read/write mode.
572
 */
573
int
574
TIFFGetMode(TIFF* tif)
575
0
{
576
0
  return (tif->tif_mode);
577
0
}
578
579
/*
580
 * Return read/write mode.
581
 */
582
int
583
TIFFSetMode(TIFF* tif, int mode)
584
0
{
585
0
  int old_mode = tif->tif_mode;
586
0
  tif->tif_mode = mode;
587
0
  return (old_mode);
588
0
}
589
590
/*
591
 * Return nonzero if file is organized in
592
 * tiles; zero if organized as strips.
593
 */
594
int
595
TIFFIsTiled(TIFF* tif)
596
0
{
597
0
  return (isTiled(tif));
598
0
}
599
600
/*
601
 * Return current row being read/written.
602
 */
603
uint32_t
604
TIFFCurrentRow(TIFF* tif)
605
0
{
606
0
  return (tif->tif_row);
607
0
}
608
609
/*
610
 * Return index of the current directory.
611
 */
612
uint16_t
613
TIFFCurrentDirectory(TIFF* tif)
614
0
{
615
0
  return (tif->tif_curdir);
616
0
}
617
618
/*
619
 * Return current strip.
620
 */
621
uint32_t
622
TIFFCurrentStrip(TIFF* tif)
623
0
{
624
0
  return (tif->tif_curstrip);
625
0
}
626
627
/*
628
 * Return current tile.
629
 */
630
uint32_t
631
TIFFCurrentTile(TIFF* tif)
632
0
{
633
0
  return (tif->tif_curtile);
634
0
}
635
636
/*
637
 * Return nonzero if the file has byte-swapped data.
638
 */
639
int
640
TIFFIsByteSwapped(TIFF* tif)
641
0
{
642
0
  return ((tif->tif_flags & TIFF_SWAB) != 0);
643
0
}
644
645
/*
646
 * Return nonzero if the data is returned up-sampled.
647
 */
648
int
649
TIFFIsUpSampled(TIFF* tif)
650
0
{
651
0
  return (isUpSampled(tif));
652
0
}
653
654
/*
655
 * Return nonzero if the data is returned in MSB-to-LSB bit order.
656
 */
657
int
658
TIFFIsMSB2LSB(TIFF* tif)
659
0
{
660
0
  return (isFillOrder(tif, FILLORDER_MSB2LSB));
661
0
}
662
663
/*
664
 * Return nonzero if given file was written in big-endian order.
665
 */
666
int
667
TIFFIsBigEndian(TIFF* tif)
668
0
{
669
0
  return (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN);
670
0
}
671
672
/*
673
 * Return pointer to file read method.
674
 */
675
TIFFReadWriteProc
676
TIFFGetReadProc(TIFF* tif)
677
0
{
678
0
  return (tif->tif_readproc);
679
0
}
680
681
/*
682
 * Return pointer to file write method.
683
 */
684
TIFFReadWriteProc
685
TIFFGetWriteProc(TIFF* tif)
686
0
{
687
0
  return (tif->tif_writeproc);
688
0
}
689
690
/*
691
 * Return pointer to file seek method.
692
 */
693
TIFFSeekProc
694
TIFFGetSeekProc(TIFF* tif)
695
0
{
696
0
  return (tif->tif_seekproc);
697
0
}
698
699
/*
700
 * Return pointer to file close method.
701
 */
702
TIFFCloseProc
703
TIFFGetCloseProc(TIFF* tif)
704
0
{
705
0
  return (tif->tif_closeproc);
706
0
}
707
708
/*
709
 * Return pointer to file size requesting method.
710
 */
711
TIFFSizeProc
712
TIFFGetSizeProc(TIFF* tif)
713
0
{
714
0
  return (tif->tif_sizeproc);
715
0
}
716
717
/*
718
 * Return pointer to memory mapping method.
719
 */
720
TIFFMapFileProc
721
TIFFGetMapFileProc(TIFF* tif)
722
0
{
723
0
  return (tif->tif_mapproc);
724
0
}
725
726
/*
727
 * Return pointer to memory unmapping method.
728
 */
729
TIFFUnmapFileProc
730
TIFFGetUnmapFileProc(TIFF* tif)
731
0
{
732
0
  return (tif->tif_unmapproc);
733
0
}
734
735
void
736
TIFFSetJpegMemFunction(TIFF *tif,
737
                       void *(*fn)(thandle_t))
738
0
{
739
0
    tif->get_jpeg_mem_ptr = fn;
740
0
}
741
742
743
/* vim: set ts=8 sts=8 sw=8 noet: */
744
/*
745
 * Local Variables:
746
 * mode: c
747
 * c-basic-offset: 8
748
 * fill-column: 78
749
 * End:
750
 */