Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
tif_msdos.c
Go to the documentation of this file.
1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_msdos.c,v 1.2 2005/12/21 12:23:13 joris Exp $ */
2 
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 
27 /*
28  * TIFF Library MSDOS-specific Routines.
29  */
30 #if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER)
31 #include <io.h> /* for open, close, etc. function prototypes */
32 #include <stdio.h>
33 #endif
34 #include "tiffiop.h"
35 
36 static tsize_t
37 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
38 {
39  return (read((int) fd, buf, size));
40 }
41 
42 static tsize_t
43 _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
44 {
45  return (write((int) fd, buf, size));
46 }
47 
48 static toff_t
49 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
50 {
51  return (lseek((int) fd, (off_t) off, whence));
52 }
53 
54 static int
55 _tiffCloseProc(thandle_t fd)
56 {
57  return (close((int) fd));
58 }
59 
60 #include <sys/stat.h>
61 
62 static toff_t
63 _tiffSizeProc(thandle_t fd)
64 {
65  struct stat sb;
66  return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
67 }
68 
69 static int
70 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
71 {
72  return (0);
73 }
74 
75 static void
76 _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
77 {
78 }
79 
80 /*
81  * Open a TIFF file descriptor for read/writing.
82  */
83 TIFF*
84 TIFFFdOpen(int fd, const char* name, const char* mode)
85 {
86  TIFF* tif;
87 
88  tif = TIFFClientOpen(name, mode,
89  (void*) fd,
90  _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
91  _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
92  if (tif)
93  tif->tif_fd = fd;
94  return (tif);
95 }
96 
97 /*
98  * Open a TIFF file for read/writing.
99  */
100 TIFF*
101 TIFFOpen(const char* name, const char* mode)
102 {
103  static const char module[] = "TIFFOpen";
104  int m, fd;
105 
106  m = _TIFFgetMode(mode, module);
107  if (m == -1)
108  return ((TIFF*)0);
109  fd = open(name, m|O_BINARY, 0666);
110  if (fd < 0) {
111  TIFFErrorExt(0, module, "%s: Cannot open", name);
112  return ((TIFF*)0);
113  }
114  return (TIFFFdOpen(fd, name, mode));
115 }
116 
117 #ifdef __GNUC__
118 extern char* malloc();
119 extern char* realloc();
120 #else
121 #include <malloc.h>
122 #endif
123 
124 tdata_t
126 {
127  return (malloc((size_t) s));
128 }
129 
130 void
132 {
133  free(p);
134 }
135 
136 tdata_t
138 {
139  return (realloc(p, (size_t) s));
140 }
141 
142 void
144 {
145  memset(p, v, (size_t) c);
146 }
147 
148 void
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 msdosWarningHandler(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 = msdosWarningHandler;
170 
171 static void
172 msdosErrorHandler(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 }
int32 tsize_t
Definition: tiffio.h:66
void * tdata_t
Definition: tiffio.h:67
TIFF * TIFFFdOpen(int fd, const char *name, const char *mode)
Definition: tif_msdos.c:84
GLfloat GLfloat p
int write(int fd, const char *buf, int nbytes)
Definition: tif_acorn.c:325
int read(int fd, char *buf, int nbytes)
Definition: tif_acorn.c:331
#define NULL
Definition: ftobjs.h:61
char * malloc()
int _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
Definition: tif_msdos.c:155
void(* TIFFErrorHandler)(const char *, const char *, va_list)
Definition: tiffio.h:259
TIFFErrorHandler _TIFFerrorHandler
Definition: tif_msdos.c:179
void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
Definition: tif_msdos.c:149
tdata_t _TIFFmalloc(tsize_t s)
Definition: tif_msdos.c:125
tdata_t _TIFFrealloc(tdata_t p, tsize_t s)
Definition: tif_msdos.c:137
Definition: tiffiop.h:95
int tif_fd
Definition: tiffiop.h:97
GLenum GLuint GLenum GLsizei const GLchar * buf
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:141
off_t lseek(int fd, off_t offset, int whence)
Definition: tif_acorn.c:337
void _TIFFfree(tdata_t p)
Definition: tif_msdos.c:131
TIFF * TIFFOpen(const char *name, const char *mode)
Definition: tif_msdos.c:101
TIFFErrorHandler _TIFFwarningHandler
Definition: tif_msdos.c:169
GLenum mode
const GLdouble * v
int close(int fd)
Definition: tif_acorn.c:320
const GLubyte * c
int free()
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:63
const GLfloat * m
GLuint const GLchar * name
int open(const char *name, int flags, int mode)
Definition: tif_acorn.c:285
int _TIFFgetMode(const char *mode, const char *module)
Definition: tif_open.c:117
uint32 toff_t
Definition: tiffio.h:68
GLdouble s
void _TIFFmemset(tdata_t p, int v, tsize_t c)
Definition: tif_msdos.c:143
GLsizeiptr size
void * thandle_t
Definition: tiffio.h:96