Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / sdk / lib / tdilib / handle.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TDI interface
4 * FILE: handle.c
5 * PURPOSE: TDI transport handle management
6 */
7
8 #include "precomp.h"
9
10 const PWCHAR TcpFileName = L"\\Device\\Tcp";
11
12 NTSTATUS openTcpFile(PHANDLE tcpFile, ACCESS_MASK DesiredAccess)
13 {
14 UNICODE_STRING fileName;
15 OBJECT_ATTRIBUTES objectAttributes;
16 IO_STATUS_BLOCK ioStatusBlock;
17 NTSTATUS status;
18
19 RtlInitUnicodeString( &fileName, TcpFileName );
20
21 InitializeObjectAttributes( &objectAttributes,
22 &fileName,
23 OBJ_CASE_INSENSITIVE,
24 NULL,
25 NULL );
26
27 status = NtOpenFile( tcpFile,
28 DesiredAccess | SYNCHRONIZE,
29 &objectAttributes,
30 &ioStatusBlock,
31 FILE_SHARE_READ | FILE_SHARE_WRITE,
32 FILE_SYNCHRONOUS_IO_NONALERT);
33
34 /* String does not need to be freed: it points to the constant
35 * string we provided */
36
37 if (!NT_SUCCESS(status))
38 *tcpFile = INVALID_HANDLE_VALUE;
39
40 return status;
41 }
42
43 VOID closeTcpFile( HANDLE h )
44 {
45 ASSERT(h != INVALID_HANDLE_VALUE);
46
47 NtClose( h );
48 }