Debian Codegraph @

winpr/libwinpr/file/test/TestFileGetStdHandle.c

raw
1
2 /**
3 * WinPR: Windows Portable Runtime
4 * File Functions
5 *
6 * Copyright 2015 Thincast Technologies GmbH
7 * Copyright 2015 Bernhard Miklautz <[email protected]>
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 #include <winpr/file.h>
23 #include <winpr/handle.h>
24 #include <string.h>
25 #include <stdio.h>
26
27 int TestFileGetStdHandle(int argc, char* argv[])
28 {
29 HANDLE so = nullptr;
30 const char buf[] = "happy happy";
31 DWORD bytesWritten = 0;
32 WINPR_UNUSED(argc);
33 WINPR_UNUSED(argv);
34 so = GetStdHandle(STD_OUTPUT_HANDLE);
35 if (so == INVALID_HANDLE_VALUE)
36 {
37 (void)fprintf(stderr, "GetStdHandle failed ;(\n");
38 return -1;
39 }
40 WriteFile(so, buf, strnlen(buf, sizeof(buf)), &bytesWritten, nullptr);
41 if (bytesWritten != strnlen(buf, sizeof(buf)))
42 {
43 (void)fprintf(stderr, "write failed\n");
44 return -1;
45 }
46 (void)CloseHandle(so);
47
48 return 0;
49 }