bigfile2.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2362N/A/* ***** BEGIN LICENSE BLOCK *****
0N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0N/A *
0N/A * The contents of this file are subject to the Mozilla Public License Version
0N/A * 1.1 (the "License"); you may not use this file except in compliance with
2362N/A * the License. You may obtain a copy of the License at
0N/A * http://www.mozilla.org/MPL/
2362N/A *
0N/A * Software distributed under the License is distributed on an "AS IS" basis,
0N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0N/A * for the specific language governing rights and limitations under the
0N/A * License.
0N/A *
0N/A * The Original Code is the Netscape Portable Runtime (NSPR).
0N/A *
0N/A * The Initial Developer of the Original Code is
0N/A * Netscape Communications Corporation.
0N/A * Portions created by the Initial Developer are Copyright (C) 1998-2000
0N/A * the Initial Developer. All Rights Reserved.
2362N/A *
2362N/A * Contributor(s):
2362N/A *
0N/A * Alternatively, the contents of this file may be used under the terms of
0N/A * either the GNU General Public License Version 2 or later (the "GPL"), or
0N/A * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0N/A * in which case the provisions of the GPL or the LGPL are applicable instead
0N/A * of those above. If you wish to allow use of your version of this file only
0N/A * under the terms of either the GPL or the LGPL, and not to allow others to
0N/A * use your version of this file under the terms of the MPL, indicate your
0N/A * decision by deleting the provisions above and replace them with the notice
0N/A * and other provisions required by the GPL or the LGPL. If you do not delete
0N/A * the provisions above, a recipient may use your version of this file under
0N/A * the terms of any one of the MPL, the GPL or the LGPL.
0N/A *
0N/A * ***** END LICENSE BLOCK ***** */
0N/A
0N/A#include "nspr.h"
0N/A
0N/A#include <stdio.h>
0N/A#include <stdlib.h>
0N/A#include <string.h>
0N/A#ifdef _WIN32
0N/A#include <windows.h>
0N/A#endif
0N/A
0N/A#define TEST_FILE_NAME "bigfile2.txt"
0N/A
0N/A#define MESSAGE "Hello world!"
0N/A#define MESSAGE_SIZE 13
0N/A
0N/Aint main(int argc, char **argv)
0N/A{
0N/A PRFileDesc *fd;
0N/A PRInt64 offset, position;
0N/A PRInt32 nbytes;
0N/A char buf[MESSAGE_SIZE];
0N/A#ifdef _WIN32
0N/A HANDLE hFile;
0N/A LARGE_INTEGER li;
0N/A#endif /* _WIN32 */
0N/A
0N/A LL_I2L(offset, 1);
0N/A LL_SHL(offset, offset, 32);
0N/A
0N/A fd = PR_Open(TEST_FILE_NAME,
0N/A PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666);
0N/A if (fd == NULL) {
0N/A fprintf(stderr, "PR_Open failed\n");
0N/A exit(1);
0N/A }
0N/A position = PR_Seek64(fd, offset, PR_SEEK_SET);
0N/A if (!LL_GE_ZERO(position)) {
0N/A fprintf(stderr, "PR_Seek64 failed\n");
0N/A exit(1);
0N/A }
0N/A PR_ASSERT(LL_EQ(position, offset));
0N/A strcpy(buf, MESSAGE);
0N/A nbytes = PR_Write(fd, buf, sizeof(buf));
0N/A if (nbytes != sizeof(buf)) {
0N/A fprintf(stderr, "PR_Write failed\n");
0N/A exit(1);
0N/A }
0N/A if (PR_Close(fd) == PR_FAILURE) {
0N/A fprintf(stderr, "PR_Close failed\n");
0N/A exit(1);
0N/A }
0N/A
0N/A memset(buf, 0, sizeof(buf));
0N/A
0N/A#ifdef _WIN32
0N/A hFile = CreateFile(TEST_FILE_NAME, GENERIC_READ, 0, NULL,
0N/A OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
0N/A if (hFile == INVALID_HANDLE_VALUE) {
0N/A fprintf(stderr, "CreateFile failed\n");
0N/A exit(1);
0N/A }
0N/A li.QuadPart = offset;
0N/A li.LowPart = SetFilePointer(hFile, li.LowPart, &li.HighPart, FILE_BEGIN);
0N/A if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
0N/A fprintf(stderr, "SetFilePointer failed\n");
0N/A exit(1);
0N/A }
0N/A PR_ASSERT(li.QuadPart == offset);
0N/A if (ReadFile(hFile, buf, sizeof(buf), &nbytes, NULL) == 0) {
0N/A fprintf(stderr, "ReadFile failed\n");
0N/A exit(1);
0N/A }
0N/A PR_ASSERT(nbytes == sizeof(buf));
0N/A if (strcmp(buf, MESSAGE)) {
0N/A fprintf(stderr, "corrupt data:$%s$\n", buf);
0N/A exit(1);
0N/A }
0N/A if (CloseHandle(hFile) == 0) {
0N/A fprintf(stderr, "CloseHandle failed\n");
0N/A exit(1);
0N/A }
0N/A#endif /* _WIN32 */
0N/A
0N/A if (PR_Delete(TEST_FILE_NAME) == PR_FAILURE) {
0N/A fprintf(stderr, "PR_Delete failed\n");
0N/A exit(1);
0N/A }
0N/A
0N/A printf("PASS\n");
0N/A return 0;
0N/A}
0N/A