1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
15 #define TEST_FILE_NAME "bigfile3.txt"
17 #define TEST_FILE_NAME_FOR_CREATEFILE L"bigfile3.txt"
19 #define TEST_FILE_NAME_FOR_CREATEFILE TEST_FILE_NAME
22 #define MESSAGE "Hello world!"
23 #define MESSAGE_SIZE 13
25 int main(int argc
, char **argv
)
28 PRInt64 offset
, position
;
30 char buf
[MESSAGE_SIZE
];
37 LL_SHL(offset
, offset
, 32);
40 hFile
= CreateFile(TEST_FILE_NAME_FOR_CREATEFILE
, GENERIC_WRITE
, 0, NULL
,
41 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
42 if (hFile
== INVALID_HANDLE_VALUE
) {
43 fprintf(stderr
, "CreateFile failed\n");
47 li
.LowPart
= SetFilePointer(hFile
, li
.LowPart
, &li
.HighPart
, FILE_BEGIN
);
48 if (li
.LowPart
== 0xFFFFFFFF && GetLastError() != NO_ERROR
) {
49 fprintf(stderr
, "SetFilePointer failed\n");
52 PR_ASSERT(li
.QuadPart
== offset
);
54 if (WriteFile(hFile
, buf
, sizeof(buf
), &nbytes
, NULL
) == 0) {
55 fprintf(stderr
, "WriteFile failed\n");
58 PR_ASSERT(nbytes
== sizeof(buf
));
59 if (CloseHandle(hFile
) == 0) {
60 fprintf(stderr
, "CloseHandle failed\n");
65 memset(buf
, 0, sizeof(buf
));
67 fd
= PR_Open(TEST_FILE_NAME
, PR_RDONLY
, 0666);
69 fprintf(stderr
, "PR_Open failed\n");
72 position
= PR_Seek64(fd
, offset
, PR_SEEK_SET
);
73 if (!LL_GE_ZERO(position
)) {
74 fprintf(stderr
, "PR_Seek64 failed\n");
77 PR_ASSERT(LL_EQ(position
, offset
));
78 nbytes
= PR_Read(fd
, buf
, sizeof(buf
));
79 if (nbytes
!= sizeof(buf
)) {
80 fprintf(stderr
, "PR_Read failed\n");
83 if (strcmp(buf
, MESSAGE
)) {
84 fprintf(stderr
, "corrupt data:$%s$\n", buf
);
87 if (PR_Close(fd
) == PR_FAILURE
) {
88 fprintf(stderr
, "PR_Close failed\n");
92 if (PR_Delete(TEST_FILE_NAME
) == PR_FAILURE
) {
93 fprintf(stderr
, "PR_Delete failed\n");