home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / tiff / tif_unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  4.2 KB  |  180 lines  |  [TEXT/CWIE]

  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 UNIX-specific Routines.
  27.  */
  28.  
  29. /* $Id: tif_unix.c,v 1.12 2001/03/28 22:05:41 tm Exp $ */
  30.  
  31. #include "tiffiop.h"
  32. #include "p_config.h"
  33. #include <stdlib.h>
  34.  
  35. static tsize_t
  36. _tiffReadProc(FILE* fd, tdata_t buf, tsize_t size)
  37. {
  38.     return ((tsize_t) fread(buf, 1, (size_t) size, fd));
  39. }
  40.  
  41. static tsize_t
  42. _tiffWriteProc(FILE* fd, tdata_t buf, tsize_t size)
  43. {
  44.     return ((tsize_t) fwrite(buf, 1, (size_t) size, fd));
  45. }
  46.  
  47. static toff_t
  48. _tiffSeekProc(FILE* fd, toff_t off, int whence)
  49. {
  50.     return ((toff_t) fseek(fd, (off_t) off, whence));
  51. }
  52.  
  53. static int
  54. _tiffCloseProc(FILE* fd)
  55. {
  56.     return (fclose(fd));
  57. }
  58.  
  59. static toff_t
  60. _tiffSizeProc(FILE* fd)
  61. {
  62.     long fsize;
  63.     return ((fsize = fseek(fd, 0, SEEK_END)) < 0 ? 0 : fsize);
  64. }
  65.  
  66. static int
  67. _tiffMapProc(FILE* fd, tdata_t* pbase, toff_t* psize)
  68. {
  69.     (void) fd; (void) pbase; (void) psize;
  70.     return (0);
  71. }
  72.  
  73. static void
  74. _tiffUnmapProc(FILE* fd, tdata_t base, toff_t size)
  75. {
  76.     (void) fd; (void) base; (void) size;
  77. }
  78.  
  79. /*
  80.  * Open a TIFF file descriptor for read/writing.
  81.  */
  82. TIFF*
  83. TIFFFdOpen(FILE* fd, const char* name, const char* mode, void* pdflib_opaque,
  84.     TIFFmallocHandler malloc_h, TIFFreallocHandler realloc_h,
  85.     TIFFfreeHandler free_h, TIFFErrorHandler error_h,
  86.     TIFFErrorHandler warn_h)
  87. {
  88.     TIFF* tif;
  89.  
  90.     tif = TIFFClientOpen(name, mode, fd,
  91.         _tiffReadProc, _tiffWriteProc,
  92.         _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
  93.         _tiffMapProc, _tiffUnmapProc, pdflib_opaque,
  94.         malloc_h, realloc_h, free_h, error_h, warn_h);
  95.     if (tif)
  96.         tif->tif_fd = fd;
  97.     return (tif);
  98. }
  99.  
  100. /*
  101.  * Open a TIFF file for read/writing.
  102.  */
  103. TIFF*
  104. TIFFOpen(const char* name, const char* mode, void* pdflib_opaque,
  105.     TIFFmallocHandler malloc_h, TIFFreallocHandler realloc_h,
  106.     TIFFfreeHandler free_h, TIFFErrorHandler error_h,
  107.     TIFFErrorHandler warn_h)
  108. {
  109.     static const char module[] = "TIFFOpen";
  110.     FILE *fd;
  111.  
  112.     if ((fd = fopen(name, READMODE)) == NULL) {
  113.         TIFFError(module, "%s: Cannot open", name);
  114.         return ((TIFF *)0);
  115.     }
  116.     return (TIFFFdOpen(fd, name, mode, pdflib_opaque,
  117.             malloc_h, realloc_h, free_h, error_h, warn_h));
  118. }
  119.  
  120.  
  121. void*
  122. _TIFFmalloc(TIFF* tif, tsize_t s)
  123. {
  124.     (void) tif;
  125.     return (malloc((size_t) s));
  126. }
  127.  
  128. void
  129. _TIFFfree(TIFF* tif, tdata_t p)
  130. {
  131.     (void) tif;
  132.     free(p);
  133. }
  134.  
  135. void*
  136. _TIFFrealloc(TIFF* tif, tdata_t p, tsize_t s)
  137. {
  138.     (void) tif;
  139.     return (realloc(p, (size_t) s));
  140. }
  141.  
  142. void
  143. _TIFFmemset(tdata_t p, int v, tsize_t c)
  144. {
  145.     memset(p, v, (size_t) c);
  146. }
  147.  
  148. void
  149. _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
  150. {
  151.     memcpy(d, s, (size_t) c);
  152. }
  153.  
  154. int
  155. _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
  156. {
  157.     return (memcmp(p1, p2, (size_t) c));
  158. }
  159.  
  160. static void
  161. unixWarningHandler(const char* module, const char* fmt, va_list ap)
  162. {
  163.     if (module != NULL)
  164.         fprintf(stderr, "%s: ", module);
  165.     fprintf(stderr, "Warning, ");
  166.     vfprintf(stderr, fmt, ap);
  167.     fprintf(stderr, ".\n");
  168. }
  169. TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler;
  170.  
  171. static void
  172. unixErrorHandler(const char* module, const char* fmt, va_list ap)
  173. {
  174.     if (module != NULL)
  175.         fprintf(stderr, "%s: ", module);
  176.     vfprintf(stderr, fmt, ap);
  177.     fprintf(stderr, ".\n");
  178. }
  179. TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler;
  180.