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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// 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: SetFileAttributesA.c
**
**
** Purpose: Tests the PAL implementation of the SetFileAttributesA function
** Test that we can set the defined attributes aside from READONLY on a
** file, and that it doesn't return failure. Note, these attributes won't
** do anything to the file, however.
**
**
**===================================================================*/
#include <palsuite.h>
/* this cleanup method tries to revert the file back to its initial attributes */
void do_cleanup(char* filename, DWORD attributes)
{
DWORD result;
result = SetFileAttributesA(filename, attributes);
if (result == 0)
{
Fail("ERROR:SetFileAttributesA returned 0,failure in the do_cleanup "
"method when trying to revert the file back to its initial attributes (%u)", GetLastError());
}
}
int __cdecl main(int argc, char **argv)
{
DWORD TheResult;
DWORD initialAttr;
char* FileName = {"test_file"};
if (0 != PAL_Initialize(argc,argv))
{
return FAIL;
}
// Create the test file
FILE *testFile = fopen(FileName, "w");
if (testFile == NULL)
{
Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName);
}
if (fputs("testing", testFile) == EOF)
{
Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName);
}
if (fclose(testFile) != 0)
{
Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName);
}
testFile = NULL;
/* Get the initial attributes of the file */
initialAttr = GetFileAttributesA(FileName);
/* Try to set the file to HIDDEN */
TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_HIDDEN);
if(TheResult == 0)
{
do_cleanup(FileName,initialAttr);
Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
"to set the FILE_ATTRIBUTE_HIDDEN attribute. This should "
"not do anything in FreeBSD, but it shouldn't fail.");
}
/* Try to set the file to ARCHIVE */
TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_ARCHIVE);
if(TheResult == 0)
{
do_cleanup(FileName,initialAttr);
Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
"to set the FILE_ATTRIBUTE_ARCHIVE attribute.");
}
/* Try to set the file to SYSTEM */
TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_SYSTEM);
if(TheResult == 0)
{
do_cleanup(FileName,initialAttr);
Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
"to set the FILE_ATTRIBUTE_SYSTEM attribute.");
}
/* Try to set the file to DIRECTORY */
TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_DIRECTORY);
if(TheResult == 0)
{
do_cleanup(FileName,initialAttr);
Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
"to set the FILE_ATTRIBUTE_DIRECTORY attribute.");
}
do_cleanup(FileName,initialAttr);
PAL_Terminate();
return PASS;
}
|