1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_win3.c,v 1.2 2005/12/21 12:23:13 joris 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 Windows 3.x-specific Routines.
31 #if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER)
32 #include <io.h> /* for open, close, etc. function prototypes */
40 _tiffReadProc(thandle_t fd
, tdata_t buf
, tsize_t size
)
42 return (_hread(fd
, buf
, size
));
46 _tiffWriteProc(thandle_t fd
, tdata_t buf
, tsize_t size
)
48 return (_hwrite(fd
, buf
, size
));
52 _tiffSeekProc(thandle_t fd
, toff_t off
, int whence
)
54 return (_llseek(fd
, (off_t
) off
, whence
));
58 _tiffCloseProc(thandle_t fd
)
66 _tiffSizeProc(thandle_t fd
)
69 return (fstat((int) fd
, &sb
) < 0 ? 0 : sb
.st_size
);
73 _tiffMapProc(thandle_t fd
, tdata_t
* pbase
, toff_t
* psize
)
79 _tiffUnmapProc(thandle_t fd
, tdata_t base
, toff_t size
)
84 * Open a TIFF file descriptor for read/writing.
87 TIFFFdOpen(int fd
, const char* name
, const char* mode
)
91 tif
= TIFFClientOpen(name
, mode
,
93 _tiffReadProc
, _tiffWriteProc
, _tiffSeekProc
, _tiffCloseProc
,
94 _tiffSizeProc
, _tiffMapProc
, _tiffUnmapProc
);
101 * Open a TIFF file for read/writing.
104 TIFFOpen(const char* name
, const char* mode
)
106 static const char module[] = "TIFFOpen";
111 m
= _TIFFgetMode(mode
, module);
115 if ((m
& O_TRUNC
) || OpenFile(name
, &of
, OF_EXIST
) != HFILE_ERROR
)
122 fd
= OpenFile(name
, &of
, mm
);
124 TIFFErrorExt(0, module, "%s: Cannot open", name
);
127 return (TIFFFdOpen(fd
, name
, mode
));
131 _TIFFmalloc(tsize_t s
)
133 return (tdata_t
) GlobalAllocPtr(GHND
, (DWORD
) s
);
143 _TIFFrealloc(tdata_t p
, tsize_t s
)
145 return (tdata_t
) GlobalReAllocPtr(p
, (DWORD
) s
, GHND
);
149 _TIFFmemset(tdata_t p
, int v
, tsize_t c
)
151 char* pp
= (char*) p
;
154 tsize_t chunk
= 0x10000 - ((uint32
) pp
& 0xffff);/* What's left in segment */
155 if (chunk
> 0xff00) /* No more than 0xff00 */
157 if (chunk
> c
) /* No more than needed */
159 memset(pp
, v
, chunk
);
160 pp
= (char*) (chunk
+ (char huge
*) pp
);
166 _TIFFmemcpy(tdata_t d
, const tdata_t s
, tsize_t c
)
169 hmemcpy((void _huge
*) d
, (void _huge
*) s
, c
);
171 (void) memcpy(d
, s
, (size_t) c
);
175 _TIFFmemcmp(const tdata_t d
, const tdata_t s
, tsize_t c
)
177 char* dd
= (char*) d
;
178 char* ss
= (char*) s
;
179 tsize_t chunks
, chunkd
, chunk
;
183 chunks
= 0x10000 - ((uint32
) ss
& 0xffff); /* What's left in segment */
184 chunkd
= 0x10000 - ((uint32
) dd
& 0xffff); /* What's left in segment */
185 chunk
= c
; /* Get the largest of */
186 if (chunk
> chunks
) /* c, chunks, chunkd, */
187 chunk
= chunks
; /* 0xff00 */
192 result
= memcmp(dd
, ss
, chunk
);
195 dd
= (char*) (chunk
+ (char huge
*) dd
);
196 ss
= (char*) (chunk
+ (char huge
*) ss
);
203 win3WarningHandler(const char* module, const char* fmt
, va_list ap
)
205 char e
[512] = { '\0' };
207 strcat(strcpy(e
, module), ":");
208 vsprintf(e
+strlen(e
), fmt
, ap
);
210 MessageBox(GetActiveWindow(), e
, "LibTIFF Warning",
211 MB_OK
|MB_ICONEXCLAMATION
);
213 TIFFErrorHandler _TIFFwarningHandler
= win3WarningHandler
;
216 win3ErrorHandler(const char* module, const char* fmt
, va_list ap
)
218 char e
[512] = { '\0' };
220 strcat(strcpy(e
, module), ":");
221 vsprintf(e
+strlen(e
), fmt
, ap
);
223 MessageBox(GetActiveWindow(), e
, "LibTIFF Error", MB_OK
|MB_ICONSTOP
);
225 TIFFErrorHandler _TIFFerrorHandler
= win3ErrorHandler
;