blob: 516f2531eda4436dbc4032a997f8b88a62f005ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*=====================================================================
**
** Source: test1.c
**
** Purpose: Tests the PAL implementation of the ferror function.
**
** Depends:
** fopen
** fread
** fclose
**
**
**
**===================================================================*/
#include <palsuite.h>
int __cdecl main(int argc, char **argv)
{
const char filename[] = "testfile";
char buffer[128];
FILE * fp = NULL;
int result;
if (PAL_Initialize(argc, argv))
{
return FAIL;
}
/* Open a file in READ mode */
if((fp = fopen(filename, "r")) == NULL)
{
Fail("Unable to open a file for reading. Is the file "
"in the directory? It should be.");
}
/* Read 10 characters from the file. The file has 15
characters in it.
*/
if((result = fread(buffer,1,10,fp)) == 0)
{
Fail("ERROR: Zero characters read from the file. It should have "
"read 10 character in from a 15 character file.");
}
if(ferror(fp) != 0)
{
Fail("ERROR: ferror returned a value not equal to 0. The read "
"operation shouldn't have caused an error, and ferror should "
"return 0 still.");
}
/*
Close the open file and end the test.
*/
if(fclose(fp) != 0)
{
Fail("ERROR: fclose failed when trying to close a file pointer. "
"This test depends on fclose working properly.");
}
PAL_Terminate();
return PASS;
}
|