Received: by smtp02.oce.nl (4.1/SMI-4.1)
	id AA17337; Mon, 28 Dec 98 23:10:32 +0100
Received: from gate7.olympiakos.com ([207.113.13.68])
	by oce.nl (8.9.0/8.9.0) with ESMTP id WAA25308;
	Mon, 28 Dec 1998 22:55:34 +0100 (MET)
Received: from localhost (bin@localhost)
	by gate7.olympiakos.com (8.8.7/8.8.7) with SMTP id QAA21121;
	Mon, 28 Dec 1998 16:39:57 -0500
Received: by gate7.olympiakos.com (bulk_mailer v1.9); Mon, 28 Dec 1998 16:38:37 -0500
Received: (from majordom@localhost)
	by gate7.olympiakos.com (8.8.7/8.8.7) id QAA21099
	for tiff-outgoing; Mon, 28 Dec 1998 16:38:36 -0500
X-Authentication-Warning: gate7.olympiakos.com: majordom set sender to owner-tiff@olympiakos.com using -f
Received: from ins3.netins.net (root@ins3.netins.net [167.142.225.3])
	by gate7.olympiakos.com (8.8.7/8.8.7) with ESMTP id QAA21096
	for <tiff@olympiakos.com>; Mon, 28 Dec 1998 16:38:33 -0500
Received: from nt133 (desm-14-42.dialup.netins.net [167.142.16.171])
	by ins3.netins.net (8.8.7/8.8.7) with SMTP id PAA20432
	for <tiff@olympiakos.com>; Mon, 28 Dec 1998 15:38:29 -0600
Message-Id: <3.0.2.32.19981228153524.010d44c0@wingate>
Reply-To: larry@polybytes.com
X-Sender: lcreeve#pop3.netins.net@wingate
X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.2 (32)
Date: Mon, 28 Dec 1998 15:35:24 -0600
To: tiff@olympiakos.com
From: Polybytes <lcreeve@netins.net>
Subject: TIFFOpen error in tif_win32.c
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Sender: owner-tiff@olympiakos.com

I have run into a problem with the TIFFOpen(tif_win32.c) function in the
v3.4beta037 distribution that causes a failure when the incoming mode
character is 'a' to append to an existing file. In this case the
_TIFFgetMode call returns O_RDWR|O_CREAT and the subsequent switch sets the
dwMode variable to CREATE_NEW. The Win32 CreateFile function then fails to
open the existing file because the dwCreationDisposition parameter of
CREATE_NEW fails the function on an existing file. Setting the dwMode
variable to OPEN_ALWAYS fixes this problem and the image can then be
appended to the existing image.

I have attached an updated version of the function.

Larry Reeve


/*
 * Open a TIFF file for read/writing.
 */
TIFF*
TIFFOpen(const char* name, const char* mode)
{
	static const char module[] = "TIFFOpen";
	thandle_t fd;
	int m;
	DWORD dwMode;

	m = _TIFFgetMode(mode, module);

	switch(m)
	{
	case O_RDONLY:
		dwMode = OPEN_EXISTING;
		break;
	case O_RDWR:
		dwMode = OPEN_ALWAYS;
		break;
	case O_RDWR|O_CREAT:
		dwMode = OPEN_ALWAYS;//CREATE_NEW;
		break;
	case O_RDWR|O_TRUNC:
		dwMode = CREATE_ALWAYS;
		break;
	case O_RDWR|O_CREAT|O_TRUNC:
		dwMode = CREATE_ALWAYS;
		break;
	default:
		return ((TIFF*)0);
	}
	fd = (thandle_t)CreateFile(name, (m == O_RDONLY) ? GENERIC_READ :
			(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ, NULL, dwMode,
			(m == O_RDONLY) ? FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL, NULL);
	if (fd == INVALID_HANDLE_VALUE) {
		TIFFError(module, "%s: Cannot open", name);
		return ((TIFF *)0);
	}
	return (TIFFFdOpen((int)fd, name, mode));
}
