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: GetTempFileNameA.c (test 2) |
8 | ** |
9 | ** Purpose: Tests the number of files GetTempFileNameA can create. |
10 | ** |
11 | ** Depends on: |
12 | ** GetFileAttributesA |
13 | ** oodles of free disk space (>4.07GB) |
14 | ** |
15 | ** |
16 | **===================================================================*/ |
17 | |
18 | #include <palsuite.h> |
19 | |
20 | |
21 | |
22 | int __cdecl main(int argc, char *argv[]) |
23 | { |
24 | UINT uiError = 0; |
25 | DWORD dwError = 0; |
26 | const UINT uUnique = 0; |
27 | const char* szDot = {"." }; |
28 | const char* szValidPrefix = {"cfr" }; |
29 | char szReturnedName[256]; |
30 | DWORD i; |
31 | |
32 | if (0 != PAL_Initialize(argc, argv)) |
33 | { |
34 | return FAIL; |
35 | } |
36 | |
37 | |
38 | /* test the number of temp files that can be created */ |
39 | for (i = 0; i < 0x10005; i++) |
40 | { |
41 | uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); |
42 | if (uiError == 0) |
43 | { |
44 | dwError = GetLastError(); |
45 | if (dwError == ERROR_FILE_EXISTS) |
46 | { |
47 | /* file already existes so break out of the loop */ |
48 | i--; /* decrement the count because it wasn't successful */ |
49 | break; |
50 | } |
51 | else |
52 | { |
53 | /* it was something other than the file already existing? */ |
54 | Fail("GetTempFileNameA: ERROR -> Call failed with a valid " |
55 | "path and prefix with the error code: %ld\n" , GetLastError()); |
56 | } |
57 | } |
58 | else |
59 | { |
60 | /* verify temp file was created */ |
61 | if (GetFileAttributesA(szReturnedName) == -1) |
62 | { |
63 | Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed " |
64 | "on the returned temp file \"%s\" with error code: %ld.\n" , |
65 | szReturnedName, |
66 | GetLastError()); |
67 | } |
68 | } |
69 | } |
70 | |
71 | /* did it create more than 0xffff files */ |
72 | if (i > 0xffff) |
73 | { |
74 | Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff" |
75 | " temp files.\n" ); |
76 | } |
77 | |
78 | PAL_Terminate(); |
79 | return PASS; |
80 | } |
81 | |