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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// 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: getfiletype.c
**
** Purpose: Test the PAL implementation of GetFileType to ensure it
** recognizes opened pipes.
**
** Depends: CreatePipe
** CloseHandle
**
**
**===================================================================*/
#include <palsuite.h>
int __cdecl main(int argc, char **argv)
{
HANDLE hReadPipe = NULL;
HANDLE hWritePipe = NULL;
BOOL bRetVal = FALSE;
DWORD dwFileType;
SECURITY_ATTRIBUTES lpPipeAttributes;
/*Initialize the PAL*/
if ((PAL_Initialize(argc, argv)) != 0)
{
return (FAIL);
}
/*
** create a pipe and make sure GetFileType returns the correct value
*/
/*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/
lpPipeAttributes.nLength = sizeof(lpPipeAttributes);
lpPipeAttributes.lpSecurityDescriptor = NULL;
lpPipeAttributes.bInheritHandle = TRUE;
/*Create a Pipe*/
bRetVal = CreatePipe(&hReadPipe, /* read handle*/
&hWritePipe, /* write handle */
&lpPipeAttributes, /* security attributes*/
0); /* pipe size*/
if (bRetVal == FALSE)
{
Fail("ERROR: %u :Unable to create pipe.\n", GetLastError());
}
// Get the file type
dwFileType = GetFileType(hReadPipe);
if (dwFileType != FILE_TYPE_PIPE)
{
if (!CloseHandle(hWritePipe))
{
Trace("ERROR: %u : Unable to close write pipe handle "
"hWritePipe=0x%lx\n", GetLastError(), hWritePipe);
}
if (!CloseHandle(hReadPipe))
{
Trace("ERROR: %u : Unable to close read pipe handle "
"hReadPipe=0x%lx\n", GetLastError(), hReadPipe);
}
Fail("ERROR: GetFileType returned %u for a pipe instead of the "
"expected FILE_TYPE_PIPE (%u).\n",
dwFileType,
FILE_TYPE_PIPE);
}
/*Close write pipe handle*/
if (!CloseHandle(hWritePipe))
{
if (!CloseHandle(hReadPipe))
{
Trace("ERROR: %u : Unable to close read pipe handle "
"hReadPipe=0x%lx\n", GetLastError(), hReadPipe);
}
Fail("ERROR: %u : Unable to close write pipe handle "
"hWritePipe=0x%lx\n", GetLastError(), hWritePipe);
}
/*Close Read pipe handle*/
if (!CloseHandle(hReadPipe))
{
Fail("ERROR: %u : Unable to close read pipe handle "
"hReadPipe=0x%lx\n", GetLastError(), hReadPipe);
}
PAL_Terminate();
return (PASS);
}
|