FreeRDP
Loading...
Searching...
No Matches
TestEnvironmentGetEnvironmentStrings.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/tchar.h>
5#include <winpr/environment.h>
6
7int TestEnvironmentGetEnvironmentStrings(int argc, char* argv[])
8{
9 int r = -1;
10
11 WINPR_UNUSED(argc);
12 WINPR_UNUSED(argv);
13
14 LPTCH lpszEnvironmentBlock = GetEnvironmentStrings();
15 if (!lpszEnvironmentBlock)
16 goto fail;
17
18 TCHAR* p = lpszEnvironmentBlock;
19 while (p[0] && p[1])
20 {
21 const size_t max = _tcslen(p);
22 const int rc = _sntprintf(NULL, 0, _T("%s\n"), p);
23 if (rc < 1)
24 {
25 _tprintf(_T("test failed: return %d\n"), rc);
26 goto fail;
27 }
28 if (max != (size_t)(rc - 1))
29 {
30 _tprintf(_T("test failed: length %") _T(PRIuz) _T(" != %d [%s]\n"), max, rc - 1, p);
31 goto fail;
32 }
33 p += (max + 1);
34 }
35
36 r = 0;
37fail:
38 FreeEnvironmentStrings(lpszEnvironmentBlock);
39
40 return r;
41}