1
/* "$Header: /cvsroot/osrs/libtiff/libtiff/tif_atari.c,v 1.1.1.1 1999/07/27 21:50:27 mike Exp $" */
4
* Copyright (c) 1988-1997 Sam Leffler
5
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
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.
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.
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
28
* TIFF Library ATARI-specific Routines.
31
#if defined(__TURBOC__)
48
_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
52
r = Fread((int) fd, size, buf);
61
_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
65
r = Fwrite((int) fd, size, buf);
74
_tiffSeekProc(thandle_t fd, off_t off, int whence)
77
long current_off, expected_off, new_off;
79
if (whence == SEEK_END || off <= 0)
80
return Fseek(off, (int) fd, whence);
81
current_off = Fseek(0, (int) fd, SEEK_CUR); /* find out where we are */
82
if (whence == SEEK_SET)
85
expected_off = off + current_off;
86
new_off = Fseek(off, (int) fd, whence);
87
if (new_off == expected_off)
89
/* otherwise extend file -- zero filling the hole */
90
if (new_off < 0) /* error? */
91
new_off = Fseek(0, (int) fd, SEEK_END); /* go to eof */
92
_TIFFmemset(buf, 0, sizeof(buf));
93
while (expected_off > new_off) {
94
off = expected_off - new_off;
95
if (off > sizeof(buf))
97
if ((current_off = Fwrite((int) fd, off, buf)) != off)
98
return (current_off > 0) ?
99
new_off + current_off : new_off;
106
_tiffCloseProc(thandle_t fd)
110
r = Fclose((int) fd);
119
_tiffSizeProc(thandle_t fd)
123
pos = Fseek(0, (int) fd, SEEK_CUR);
124
eof = Fseek(0, (int) fd, SEEK_END);
125
Fseek(pos, (int) fd, SEEK_SET);
130
_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
136
_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
141
* Open a TIFF file descriptor for read/writing.
144
TIFFFdOpen(int fd, const char* name, const char* mode)
148
tif = TIFFClientOpen(name, mode,
150
_tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
151
_tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
158
* Open a TIFF file for read/writing.
161
TIFFOpen(const char* name, const char* mode)
163
static const char module[] = "TIFFOpen";
167
m = _TIFFgetMode(mode, module);
171
fd = Fcreate(name, 0);
173
fd = Fopen(name, m & O_ACCMODE);
174
if (fd == AEFILNF && m & O_CREAT)
175
fd = Fcreate(name, 0);
180
TIFFError(module, "%s: Cannot open", name);
183
return (TIFFFdOpen(fd, name, mode));
189
_TIFFmalloc(tsize_t s)
191
return (malloc((size_t) s));
201
_TIFFrealloc(tdata_t p, tsize_t s)
203
return (realloc(p, (size_t) s));
207
_TIFFmemset(tdata_t p, int v, size_t c)
209
memset(p, v, (size_t) c);
213
_TIFFmemcpy(tdata_t d, const tdata_t s, size_t c)
215
memcpy(d, s, (size_t) c);
219
_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
221
return (memcmp(p1, p2, (size_t) c));
225
atariWarningHandler(const char* module, const char* fmt, va_list ap)
228
fprintf(stderr, "%s: ", module);
229
fprintf(stderr, "Warning, ");
230
vfprintf(stderr, fmt, ap);
231
fprintf(stderr, ".\n");
233
TIFFErrorHandler _TIFFwarningHandler = atariWarningHandler;
236
atariErrorHandler(const char* module, const char* fmt, va_list ap)
239
fprintf(stderr, "%s: ", module);
240
vfprintf(stderr, fmt, ap);
241
fprintf(stderr, ".\n");
243
TIFFErrorHandler _TIFFerrorHandler = atariErrorHandler;