summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c
blob: 861a8b87e87df12fbde6c6ce28d6b72e35493644 (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
75
76
77
78
79
80
// 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:  GetTempFileNameA.c (test 2)
**
** Purpose: Tests the number of files GetTempFileNameA can create.
**
** Depends on:
**          GetFileAttributesA
**          oodles of free disk space (>4.07GB)
**
**
**===================================================================*/

#include <palsuite.h>



int __cdecl main(int argc, char *argv[])
{
    UINT uiError = 0;
    DWORD dwError = 0;
    const UINT uUnique = 0;
    const char* szDot = {"."};
    const char* szValidPrefix = {"cfr"};
    char szReturnedName[256];
    DWORD i;

    if (0 != PAL_Initialize(argc, argv))
    {
        return FAIL;
    }


    /* test the number of temp files that can be created */
    for (i = 0; i < 0x10005; i++)
    {
        uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName);
        if (uiError == 0)
        {
            dwError = GetLastError();
            if (dwError == ERROR_FILE_EXISTS)
            {
                /* file already existes so break out of the loop */
                i--; /* decrement the count because it wasn't successful */
                break;
            }
            else
            {
                /* it was something other than the file already existing? */
                Fail("GetTempFileNameA: ERROR -> Call failed with a valid "
                    "path and prefix with the error code: %ld\n", GetLastError());
            }
        }
        else
        {
            /* verify temp file was created */
            if (GetFileAttributesA(szReturnedName) == -1)
            {
                Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed "
                    "on the returned temp file \"%s\" with error code: %ld.\n",
                    szReturnedName,
                    GetLastError());
            }
        }
    }

    /* did it create more than 0xffff files */
    if (i > 0xffff)
    {
        Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff"
            " temp files.\n");
    }

    PAL_Terminate();
    return PASS;
}