4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 * modifed for use with OS/2 by David Webster
9 * Permission to use, copy, modify, distribute, and sell this software and
10 * its documentation for any purpose is hereby granted without fee, provided
11 * that (i) the above copyright notices and this permission notice appear in
12 * all copies of the software and related documentation, and (ii) the names of
13 * Sam Leffler and Silicon Graphics may not be used in any advertising or
14 * publicity relating to the software without the specific, prior written
15 * permission of Sam Leffler and Silicon Graphics.
17 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
19 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
22 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
23 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
25 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
30 * TIFF Library OS/2-specific Routines. Adapted from tif_win32.c 2/16/00 by
31 * David Webster (dwebster@bhmi.com), Baldwin, Hackett, and Meeks, Inc., Omaha, NE USA
40 /* Some windows datatypes */
45 typedef const PCHAR LPCTSTR
;
47 #define GlobalAlloc(a,b) malloc(b)
48 #define LocalAlloc(a,b) malloc(b)
49 #define GlobalFree(b) free(b)
50 #define LocalFree(b) free(b)
51 #define GlobalReAlloc(p, s, t) realloc(p, s)
52 #define CopyMemory(p, v, s) memcpy(p, v, s)
53 #define FillMemory(p, c, s) memset(p, c, s)
54 #define GlobalSize(p) sizeof(p)
55 #define wsprintf sprintf
56 #define wvsprintf vsprintf
57 #define lstrlen strlen
59 static tsize_t LINKAGEMODE
60 _tiffReadProc(thandle_t fd
, tdata_t buf
, tsize_t size
)
63 if (!DosRead((HFILE
)fd
, buf
, size
, &dwSizeRead
))
65 return ((tsize_t
) dwSizeRead
);
68 static tsize_t LINKAGEMODE
69 _tiffWriteProc(thandle_t fd
, tdata_t buf
, tsize_t size
)
72 if (!DosWrite((HFILE
)fd
, buf
, size
, &dwSizeWritten
))
74 return ((tsize_t
) dwSizeWritten
);
77 static toff_t LINKAGEMODE
78 _tiffSeekProc(thandle_t fd
, toff_t off
, int whence
)
85 dwMoveMethod
= FILE_BEGIN
;
88 dwMoveMethod
= FILE_CURRENT
;
91 dwMoveMethod
= FILE_END
;
94 dwMoveMethod
= FILE_BEGIN
;
97 DosSetFilePtr((HFILE
)fd
, off
, dwMoveMethod
, &ibActual
);
98 return((toff_t
)ibActual
);
101 static int LINKAGEMODE
102 _tiffCloseProc(thandle_t fd
)
104 return (DosClose((HFILE
)fd
) ? 0 : -1);
107 static toff_t LINKAGEMODE
108 _tiffSizeProc(thandle_t fd
)
112 DosQueryFileInfo((HFILE
)fd
, FIL_STANDARD
, &vStatus
, sizeof(FILESTATUS3
));
113 return (vStatus
.cbFile
);
116 static int LINKAGEMODE
117 _tiffDummyMapProc(thandle_t fd
, tdata_t
* pbase
, toff_t
* psize
)
123 * From "Hermann Josef Hill" <lhill@rhein-zeitung.de>:
125 * Windows uses both a handle and a pointer for file mapping,
126 * but according to the SDK documentation and Richter's book
127 * "Advanced Windows Programming" it is safe to free the handle
128 * after obtaining the file mapping pointer
130 * This removes a nasty OS dependency and cures a problem
131 * with Visual C++ 5.0
133 static int LINKAGEMODE
134 _tiffMapProc(thandle_t fd
, tdata_t
* pbase
, toff_t
* psize
)
139 static void LINKAGEMODE
140 _tiffDummyUnmapProc(thandle_t fd
, tdata_t base
, toff_t size
)
144 static void LINKAGEMODE
145 _tiffUnmapProc(thandle_t fd
, tdata_t base
, toff_t size
)
150 * Open a TIFF file descriptor for read/writing.
151 * Note that TIFFFdOpen and TIFFOpen recognise the character 'u' in the mode
152 * string, which forces the file to be opened unmapped.
155 TIFFFdOpen(int ifd
, const char* name
, const char* mode
)
158 BOOL fSuppressMap
= (mode
[1] == 'u' || mode
[2] == 'u');
160 tif
= TIFFClientOpen(name
, mode
,
162 _tiffReadProc
, _tiffWriteProc
,
163 _tiffSeekProc
, _tiffCloseProc
, _tiffSizeProc
,
164 fSuppressMap
? _tiffDummyMapProc
: _tiffMapProc
,
165 fSuppressMap
? _tiffDummyUnmapProc
: _tiffUnmapProc
);
172 * Open a TIFF file for read/writing.
175 TIFFOpen(const char* name
, const char* mode
)
177 static const char module[] = "TIFFOpen";
185 m
= _TIFFgetMode(mode
, module);
190 dwOpenMode
= OPEN_ACCESS_READONLY
;
191 dwOpenFlags
= OPEN_ACTION_FAIL_IF_NEW
;
194 dwOpenMode
= OPEN_ACCESS_READWRITE
;
195 dwOpenFlags
= OPEN_ACTION_FAIL_IF_NEW
;
198 dwOpenMode
= OPEN_ACCESS_READWRITE
;
199 dwOpenFlags
= OPEN_ACTION_CREATE_IF_NEW
;
202 dwOpenMode
= OPEN_ACCESS_READWRITE
;
203 dwOpenFlags
= OPEN_ACTION_FAIL_IF_NEW
| OPEN_ACTION_OPEN_IF_EXISTS
;
205 case O_RDWR
|O_CREAT
|O_TRUNC
:
206 dwOpenMode
= OPEN_ACCESS_READWRITE
;
207 dwOpenFlags
= OPEN_ACTION_CREATE_IF_NEW
| OPEN_ACTION_REPLACE_IF_EXISTS
;
212 ulrc
= DosOpen( name
, (HFILE
*)&fd
, &dwAction
, FILE_ARCHIVED
|FILE_NORMAL
213 ,1000L, dwOpenFlags
, dwOpenMode
, NULL
215 if (fd
!= NO_ERROR
) {
216 TIFFError(module, "%s: Cannot open", name
);
219 return (TIFFFdOpen((int)fd
, name
, mode
));
223 _TIFFmalloc(tsize_t s
)
225 return ((tdata_t
)GlobalAlloc(GMEM_FIXED
, s
));
236 _TIFFrealloc(tdata_t p
, tsize_t s
)
239 if ((pvTmp
= GlobalReAlloc(p
, s
, 0)) == NULL
) {
240 if ((pvTmp
= GlobalAlloc(sGMEM_FIXED
, s
)) != NULL
) {
241 CopyMemory(pvTmp
, p
, GlobalSize(p
));
245 return ((tdata_t
)pvTmp
);
249 _TIFFmemset(void* p
, int v
, tsize_t c
)
251 FillMemory(p
, c
, (BYTE
)v
);
255 _TIFFmemcpy(void* d
, const tdata_t s
, tsize_t c
)
261 _TIFFmemcmp(const tdata_t p1
, const tdata_t p2
, tsize_t c
)
263 register const *pb1
= (const int*)p1
;
264 register const *pb2
= (const int*)p2
;
265 register DWORD dwTmp
= c
;
267 for (iTmp
= 0; dwTmp
-- && !iTmp
; iTmp
= (int)*pb1
++ - (int)*pb2
++)
272 static void LINKAGEMODE
273 Os2WarningHandler(const char* module, const char* fmt
, va_list ap
)
275 #ifndef TIF_PLATFORM_CONSOLE
278 LPCTSTR szTitleText
= "%s Warning";
279 LPCTSTR szDefaultModule
= "TIFFLIB";
280 szTmp
= (module == NULL
) ? (LPTSTR
)szDefaultModule
: (LPTSTR
)module;
281 if ((szTitle
= (LPTSTR
)LocalAlloc(LMEM_FIXED
, (lstrlen(szTmp
) +
282 lstrlen(szTitleText
) + lstrlen(fmt
) + 128)*sizeof(TCHAR
))) == NULL
)
284 wsprintf(szTitle
, szTitleText
, szTmp
);
285 szTmp
= szTitle
+ (lstrlen(szTitle
)+2)*sizeof(TCHAR
);
286 wvsprintf(szTmp
, fmt
, ap
);
287 WinMessageBox( HWND_DESKTOP
288 ,WinQueryFocus(HWND_DESKTOP
)
292 ,MB_OK
| MB_INFORMATION
298 fprintf(stderr
, "%s: ", module);
299 fprintf(stderr
, "Warning, ");
300 vfprintf(stderr
, fmt
, ap
);
301 fprintf(stderr
, ".\n");
304 TIFFErrorHandler _TIFFwarningHandler
= Os2WarningHandler
;
306 static void LINKAGEMODE
307 Os2ErrorHandler(const char* module, const char* fmt
, va_list ap
)
309 #ifndef TIF_PLATFORM_CONSOLE
312 LPCTSTR szTitleText
= "%s Error";
313 LPCTSTR szDefaultModule
= "TIFFLIB";
314 szTmp
= (module == NULL
) ? (LPTSTR
)szDefaultModule
: (LPTSTR
)module;
315 if ((szTitle
= (LPTSTR
)LocalAlloc(LMEM_FIXED
, (lstrlen(szTmp
) +
316 lstrlen(szTitleText
) + lstrlen(fmt
) + 128)*sizeof(TCHAR
))) == NULL
)
318 wsprintf(szTitle
, szTitleText
, szTmp
);
319 szTmp
= szTitle
+ (lstrlen(szTitle
)+2)*sizeof(TCHAR
);
320 wvsprintf(szTmp
, fmt
, ap
);
321 WinMessageBox( HWND_DESKTOP
322 ,WinQueryFocus(HWND_DESKTOP
)
326 ,MB_OK
| MB_ICONEXCLAMATION
332 fprintf(stderr
, "%s: ", module);
333 vfprintf(stderr
, fmt
, ap
);
334 fprintf(stderr
, ".\n");
337 TIFFErrorHandler _TIFFerrorHandler
= Os2ErrorHandler
;