1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*===================================================================== |
6 | ** |
7 | ** Source: test2.c |
8 | ** |
9 | ** Purpose: Tests the PAL implementation of the fopen function. |
10 | ** Test to ensure that you can write to a 'w' mode file. |
11 | ** And that you can't read from a 'w' mode file. |
12 | ** |
13 | ** Depends: |
14 | ** fprintf |
15 | ** fseek |
16 | ** fgets |
17 | ** |
18 | |
19 | ** |
20 | **===================================================================*/ |
21 | |
22 | #include <palsuite.h> |
23 | |
24 | int __cdecl main(int argc, char **argv) |
25 | { |
26 | |
27 | FILE *fp; |
28 | char buffer[128]; |
29 | |
30 | if (PAL_Initialize(argc, argv)) |
31 | { |
32 | return FAIL; |
33 | } |
34 | |
35 | |
36 | if( (fp = fopen( "testfile" , "w" )) == NULL ) |
37 | { |
38 | Fail( "ERROR: The file failed to open with 'w' mode.\n" ); |
39 | } |
40 | |
41 | /* Test that you can write */ |
42 | if(fprintf(fp,"%s" ,"some text" ) <= 0) |
43 | { |
44 | Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " |
45 | "but fprintf failed. Either fopen or fprintf have problems." ); |
46 | } |
47 | |
48 | if(fseek(fp, 0, SEEK_SET)) |
49 | { |
50 | Fail("ERROR: fseek failed, and this test depends on it." ); |
51 | } |
52 | |
53 | /* Test that you can't read */ |
54 | if(fgets(buffer,10,fp) != NULL) |
55 | { |
56 | Fail("ERROR: Tried to READ from a file with only 'w' mode set. " |
57 | "This should fail, but fgets didn't return NULL. Either " |
58 | "fgets or fopen is broken." ); |
59 | } |
60 | |
61 | PAL_Terminate(); |
62 | return PASS; |
63 | } |
64 | |
65 | |
66 | |