reshuffling of dlls
[reactos.git] / reactos / dll / win32 / kernel32 / file / mailslot.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/mailslot.c
6 * PURPOSE: Mailslot functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <k32.h>
14
15 #define NDEBUG
16 #include "../include/debug.h"
17
18 /* FUNCTIONS ****************************************************************/
19
20 /*
21 * @implemented
22 */
23 HANDLE STDCALL
24 CreateMailslotA(LPCSTR lpName,
25 DWORD nMaxMessageSize,
26 DWORD lReadTimeout,
27 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
28 {
29 HANDLE MailslotHandle;
30 UNICODE_STRING NameU;
31 ANSI_STRING NameA;
32
33 RtlInitAnsiString(&NameA, (LPSTR)lpName);
34 RtlAnsiStringToUnicodeString(&NameU, &NameA, TRUE);
35
36 MailslotHandle = CreateMailslotW(NameU.Buffer,
37 nMaxMessageSize,
38 lReadTimeout,
39 lpSecurityAttributes);
40
41 RtlFreeUnicodeString(&NameU);
42
43 return(MailslotHandle);
44 }
45
46
47 /*
48 * @implemented
49 */
50 HANDLE STDCALL
51 CreateMailslotW(LPCWSTR lpName,
52 DWORD nMaxMessageSize,
53 DWORD lReadTimeout,
54 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
55 {
56 OBJECT_ATTRIBUTES ObjectAttributes;
57 UNICODE_STRING MailslotName;
58 HANDLE MailslotHandle;
59 NTSTATUS Status;
60 BOOLEAN Result;
61 LARGE_INTEGER DefaultTimeOut;
62 IO_STATUS_BLOCK Iosb;
63 ULONG Attributes = OBJ_CASE_INSENSITIVE;
64 PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
65
66 Result = RtlDosPathNameToNtPathName_U(lpName,
67 &MailslotName,
68 NULL,
69 NULL);
70 if (!Result)
71 {
72 SetLastError(ERROR_PATH_NOT_FOUND);
73 return(INVALID_HANDLE_VALUE);
74 }
75
76 DPRINT("Mailslot name: %wZ\n", &MailslotName);
77
78 if(lpSecurityAttributes)
79 {
80 SecurityDescriptor = lpSecurityAttributes->lpSecurityDescriptor;
81 if(lpSecurityAttributes->bInheritHandle)
82 Attributes |= OBJ_INHERIT;
83 }
84
85 InitializeObjectAttributes(&ObjectAttributes,
86 &MailslotName,
87 Attributes,
88 NULL,
89 SecurityDescriptor);
90
91 DefaultTimeOut.QuadPart = lReadTimeout * 10000;
92
93 Status = NtCreateMailslotFile(&MailslotHandle,
94 GENERIC_READ | SYNCHRONIZE | WRITE_DAC,
95 &ObjectAttributes,
96 &Iosb,
97 FILE_WRITE_THROUGH,
98 0,
99 nMaxMessageSize,
100 &DefaultTimeOut);
101
102 RtlFreeHeap(RtlGetProcessHeap(),
103 0,
104 MailslotName.Buffer);
105
106 if (!NT_SUCCESS(Status))
107 {
108 DPRINT("NtCreateMailslot failed (Status %x)!\n", Status);
109 SetLastErrorByStatus (Status);
110 return(INVALID_HANDLE_VALUE);
111 }
112
113 return(MailslotHandle);
114 }
115
116
117 /*
118 * @implemented
119 */
120 BOOL STDCALL
121 GetMailslotInfo(HANDLE hMailslot,
122 LPDWORD lpMaxMessageSize,
123 LPDWORD lpNextSize,
124 LPDWORD lpMessageCount,
125 LPDWORD lpReadTimeout)
126 {
127 FILE_MAILSLOT_QUERY_INFORMATION Buffer;
128 IO_STATUS_BLOCK Iosb;
129 NTSTATUS Status;
130
131 Status = NtQueryInformationFile(hMailslot,
132 &Iosb,
133 &Buffer,
134 sizeof(FILE_MAILSLOT_QUERY_INFORMATION),
135 FileMailslotQueryInformation);
136 if (!NT_SUCCESS(Status))
137 {
138 DPRINT("NtQueryInformationFile failed (Status %x)!\n", Status);
139 SetLastErrorByStatus (Status);
140 return(FALSE);
141 }
142
143 if (lpMaxMessageSize != NULL)
144 {
145 *lpMaxMessageSize = Buffer.MaximumMessageSize;
146 }
147 if (lpNextSize != NULL)
148 {
149 *lpNextSize = Buffer.NextMessageSize;
150 }
151 if (lpMessageCount != NULL)
152 {
153 *lpMessageCount = Buffer.MessagesAvailable;
154 }
155 if (lpReadTimeout != NULL)
156 {
157 *lpReadTimeout = (DWORD)(Buffer.ReadTimeout.QuadPart / -10000);
158 }
159
160 return(TRUE);
161 }
162
163
164 /*
165 * @implemented
166 */
167 BOOL STDCALL
168 SetMailslotInfo(HANDLE hMailslot,
169 DWORD lReadTimeout)
170 {
171 FILE_MAILSLOT_SET_INFORMATION Buffer;
172 LARGE_INTEGER Timeout;
173 IO_STATUS_BLOCK Iosb;
174 NTSTATUS Status;
175
176 Timeout.QuadPart = lReadTimeout * -10000;
177 Buffer.ReadTimeout = &Timeout;
178
179 Status = NtSetInformationFile(hMailslot,
180 &Iosb,
181 &Buffer,
182 sizeof(FILE_MAILSLOT_SET_INFORMATION),
183 FileMailslotSetInformation);
184 if (!NT_SUCCESS(Status))
185 {
186 DPRINT("NtSetInformationFile failed (Status %x)!\n", Status);
187 SetLastErrorByStatus (Status);
188 return(FALSE);
189 }
190
191 return(TRUE);
192 }
193
194 /* EOF */