tstFileAppendWin-1.cpp revision d58a25651be819045c8e77b89a2f563f0b8982b0
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync/* $Id$ */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync/** @file
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * IPRT Testcase - Exploration of File Appending on Windows.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync/*
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * available from http://www.virtualbox.org. This file is free software;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * General Public License (GPL) as published by the Free Software
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * The contents of this file may alternatively be used under the terms
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * of the Common Development and Distribution License Version 1.0
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * CDDL are applicable instead of those of the GPL.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * You may elect to license modified versions of this file under the
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * terms and conditions of either the GPL or the CDDL or both.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * additional information or have any questions.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync/*******************************************************************************
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync* Header Files *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync*******************************************************************************/
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync#include <Windows.h>
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync#include <stdio.h>
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync#include <string.h>
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync#include <stdarg.h>
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync/*******************************************************************************
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync* Global Variables *
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync*******************************************************************************/
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsyncstatic int g_cErrors = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsyncstatic int MyFailure(const char *pszFormat, ...)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync{
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_list va;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: FATAL: ");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_start(va, pszFormat);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync vprintf(pszFormat, va);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_end(va);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync g_cErrors++;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return 1;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync}
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsyncvoid MyError(const char *pszFormat, ...)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync{
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_list va;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: ERROR: ");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_start(va, pszFormat);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync vprintf(pszFormat, va);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync va_end(va);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync g_cErrors++;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync}
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsyncint main()
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync{
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync HANDLE hFile;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync LARGE_INTEGER off;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync DWORD cb;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync char szBuf[256];
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: TESTING...\n");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync /*
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Open it write only and do some appending.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Checking that read fails and that the file position changes after the read.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync DeleteFile("tstFileAppendWin-1.tst");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync hFile = CreateFile("tstFileAppendWin-1.tst",
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA),
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_SHARE_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CREATE_ALWAYS,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_ATTRIBUTE_NORMAL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (hFile == INVALID_HANDLE_VALUE)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return MyFailure("1st CreateFile: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("1st SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 0)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on open: %ld - expected 0\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!WriteFile(hFile, "0123456789", 10, &cb, NULL))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("write fail: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("2nd SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 10)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on write: %ld - expected 10\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld after first write\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync SetLastError(0);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (ReadFile(hFile, szBuf, 1, &cb, NULL))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("read didn't fail! cb=%#lx lasterr=%d\n", (long)cb, GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 5;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_BEGIN))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("3rd SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 5)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position after set file pointer: %ld - expected 5\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CloseHandle(hFile);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync /*
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Open it write only and do some more appending.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Checking the initial position and that it changes after the write.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync hFile = CreateFile("tstFileAppendWin-1.tst",
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA),
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_SHARE_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync OPEN_EXISTING,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_ATTRIBUTE_NORMAL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (hFile == INVALID_HANDLE_VALUE)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return MyFailure("2nd CreateFile: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("4th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 0)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on open: %ld - expected 0\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld on 2nd open\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!WriteFile(hFile, "abcdefghij", 10, &cb, NULL))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("2nd write failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("5th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 20)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on 2nd write: %ld - expected 20\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld after 2nd write\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CloseHandle(hFile);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync /*
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Open it read/write.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Check the initial position and read stuff. Then append some more and
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * check the new position and see that read returns 0/EOF. Finally,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * do some seeking and read from a new position.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync hFile = CreateFile("tstFileAppendWin-1.tst",
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA) | GENERIC_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_SHARE_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync OPEN_EXISTING,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_ATTRIBUTE_NORMAL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (hFile == INVALID_HANDLE_VALUE)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return MyFailure("3rd CreateFile: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("6th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 0)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on open: %ld - expected 0\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld on 3rd open\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!ReadFile(hFile, szBuf, 10, &cb, NULL) || cb != 10)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("1st ReadFile failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (memcmp(szBuf, "0123456789", 10))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("read the wrong stuff: %.10s - expected 0123456789\n", szBuf);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("7th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 10)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on 1st read: %ld - expected 0\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld on 1st read\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!WriteFile(hFile, "klmnopqrst", 10, &cb, NULL))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("3rd write failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("8th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 30)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on 3rd write: %ld - expected 30\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld after 3rd write\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync SetLastError(0);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (ReadFile(hFile, szBuf, 1, &cb, NULL) && cb != 0)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("read after write didn't fail! cb=%#lx lasterr=%d\n", (long)cb, GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 15;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_BEGIN))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("9th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 15)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on 3rd write: %ld - expected 15\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync {
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!ReadFile(hFile, szBuf, 10, &cb, NULL) || cb != 10)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("1st ReadFile failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (memcmp(szBuf, "fghijklmno", 10))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("read the wrong stuff: %.10s - expected fghijklmno\n", szBuf);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync off.QuadPart = 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (!SetFilePointerEx(hFile, off, &off, FILE_CURRENT))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("10th SetFilePointerEx failed: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else if (off.QuadPart != 25)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("unexpected position on 2nd read: %ld - expected 25\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: off=%ld after 2nd read\n", (long)off.QuadPart);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync }
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CloseHandle(hFile);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync /*
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync * Open it read only + append and check that we cannot write to it.
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync */
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync hFile = CreateFile("tstFileAppendWin-1.tst",
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_APPEND_DATA | GENERIC_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_SHARE_READ,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CREATE_ALWAYS,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync FILE_ATTRIBUTE_NORMAL,
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync NULL);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (hFile == INVALID_HANDLE_VALUE)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return MyFailure("4th CreateFile: %d\n", GetLastError());
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync SetLastError(0);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (WriteFile(hFile, "pqrstuvwx", 10, &cb, NULL))
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync MyError("write didn't on read-only+append open: %d cb=%#lx\n", GetLastError(), (long)cb);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync CloseHandle(hFile);
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync DeleteFile("tstfileAppendWin-1.tst");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync if (g_cErrors)
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: FAILED\n");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync else
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync printf("tstFileAppendWin-1: SUCCESS\n");
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync return g_cErrors ? 1 : 0;
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync}
d58a25651be819045c8e77b89a2f563f0b8982b0vboxsync