4 #include <winpr/file.h>
5 #include <winpr/path.h>
6 #include <winpr/handle.h>
7 #include <winpr/windows.h>
8 #include <winpr/sysinfo.h>
10 static const DWORD allflags[] = {
12 FILE_ATTRIBUTE_READONLY,
13 FILE_ATTRIBUTE_HIDDEN,
14 FILE_ATTRIBUTE_SYSTEM,
15 FILE_ATTRIBUTE_DIRECTORY,
16 FILE_ATTRIBUTE_ARCHIVE,
17 FILE_ATTRIBUTE_DEVICE,
18 FILE_ATTRIBUTE_NORMAL,
19 FILE_ATTRIBUTE_TEMPORARY,
20 FILE_ATTRIBUTE_SPARSE_FILE,
21 FILE_ATTRIBUTE_REPARSE_POINT,
22 FILE_ATTRIBUTE_COMPRESSED,
23 FILE_ATTRIBUTE_OFFLINE,
24 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
25 FILE_ATTRIBUTE_ENCRYPTED,
26 FILE_ATTRIBUTE_VIRTUAL,
27 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM,
28 FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DEVICE |
29 FILE_ATTRIBUTE_NORMAL,
30 FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_SPARSE_FILE | FILE_ATTRIBUTE_REPARSE_POINT |
31 FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_OFFLINE,
32 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_VIRTUAL
35 static BOOL test_SetFileAttributesA(
void)
39 const DWORD flags[] = { 0, FILE_ATTRIBUTE_READONLY };
40 char* name = GetKnownSubPath(KNOWN_PATH_TEMP,
"afsklhjwe4oq5iu432oijrlkejadlkhjaklhfdkahfd");
44 for (
size_t x = 0; x < ARRAYSIZE(allflags); x++)
46 const DWORD flag = allflags[x];
47 const BOOL brc = SetFileAttributesA(NULL, flag);
51 const BOOL crc = SetFileAttributesA(name, flag);
56 handle = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW,
57 FILE_ATTRIBUTE_NORMAL, NULL);
58 if (handle == INVALID_HANDLE_VALUE)
60 (void)CloseHandle(handle);
62 for (
size_t x = 0; x < ARRAYSIZE(flags); x++)
65 const DWORD flag = flags[x];
66 const BOOL brc = SetFileAttributesA(name, flag);
70 attr = GetFileAttributesA(name);
73 if ((attr & flag) == 0)
86 static BOOL test_SetFileAttributesW(
void)
91 const DWORD flags[] = { 0, FILE_ATTRIBUTE_READONLY };
92 char* base = GetKnownSubPath(KNOWN_PATH_TEMP,
"afsklhjwe4oq5iu432oijrlkejadlkhjaklhfdkahfd");
96 name = ConvertUtf8ToWCharAlloc(base, NULL);
100 for (
size_t x = 0; x < ARRAYSIZE(allflags); x++)
102 const DWORD flag = allflags[x];
103 const BOOL brc = SetFileAttributesW(NULL, flag);
107 const BOOL crc = SetFileAttributesW(name, flag);
112 handle = CreateFileW(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW,
113 FILE_ATTRIBUTE_NORMAL, NULL);
114 if (handle == INVALID_HANDLE_VALUE)
116 (void)CloseHandle(handle);
118 for (
size_t x = 0; x < ARRAYSIZE(flags); x++)
121 const DWORD flag = flags[x];
122 const BOOL brc = SetFileAttributesW(name, flag);
126 attr = GetFileAttributesW(name);
129 if ((attr & flag) == 0)
142 int TestSetFileAttributes(
int argc,
char* argv[])
147 if (!test_SetFileAttributesA())
149 if (!test_SetFileAttributesW())