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)
11 /* INCLUDES *****************************************************************/
16 #include <kernel32/kernel32.h>
18 /* FUNCTIONS ****************************************************************/
21 CreateMailslotA(LPCSTR lpName,
22 DWORD nMaxMessageSize,
24 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
26 HANDLE MailslotHandle;
30 RtlInitAnsiString(&NameA, (LPSTR)lpName);
31 RtlAnsiStringToUnicodeString(&NameU, &NameA, TRUE);
33 MailslotHandle = CreateMailslotW(NameU.Buffer,
36 lpSecurityAttributes);
38 RtlFreeUnicodeString(&NameU);
40 return(MailslotHandle);
45 CreateMailslotW(LPCWSTR lpName,
46 DWORD nMaxMessageSize,
48 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
50 OBJECT_ATTRIBUTES ObjectAttributes;
51 UNICODE_STRING MailslotName;
52 HANDLE MailslotHandle;
55 LARGE_INTEGER DefaultTimeOut;
58 Result = RtlDosPathNameToNtPathName_U((LPWSTR)lpName,
64 SetLastError(ERROR_PATH_NOT_FOUND);
65 return(INVALID_HANDLE_VALUE);
68 DPRINT("Mailslot name: %wZ\n", &MailslotName);
70 InitializeObjectAttributes(&ObjectAttributes,
76 DefaultTimeOut.QuadPart = lReadTimeout * 10000;
78 Status = NtCreateMailslotFile(&MailslotHandle,
79 GENERIC_READ | SYNCHRONIZE | WRITE_DAC,
87 RtlFreeUnicodeString(&MailslotName);
89 if (!NT_SUCCESS(Status))
91 DPRINT("NtCreateMailslot failed (Status %x)!\n", Status);
92 SetLastErrorByStatus (Status);
93 return(INVALID_HANDLE_VALUE);
96 return(MailslotHandle);
101 GetMailslotInfo(HANDLE hMailslot,
102 LPDWORD lpMaxMessageSize,
104 LPDWORD lpMessageCount,
105 LPDWORD lpReadTimeout)
107 FILE_MAILSLOT_QUERY_INFORMATION Buffer;
108 IO_STATUS_BLOCK Iosb;
111 Status = NtQueryInformationFile(hMailslot,
114 sizeof(FILE_MAILSLOT_QUERY_INFORMATION),
115 FileMailslotQueryInformation);
116 if (!NT_SUCCESS(Status))
118 DPRINT("NtQueryInformationFile failed (Status %x)!\n", Status);
119 SetLastErrorByStatus (Status);
123 if (lpMaxMessageSize != NULL)
125 *lpMaxMessageSize = Buffer.MaxMessageSize;
127 if (lpNextSize != NULL)
129 *lpNextSize = Buffer.NextSize;
131 if (lpMessageCount != NULL)
133 *lpMessageCount = Buffer.MessageCount;
135 if (lpReadTimeout != NULL)
137 *lpReadTimeout = (DWORD)(Buffer.Timeout.QuadPart / -10000);
145 SetMailslotInfo(HANDLE hMailslot,
148 FILE_MAILSLOT_SET_INFORMATION Buffer;
149 IO_STATUS_BLOCK Iosb;
152 Buffer.Timeout.QuadPart = lReadTimeout * -10000;
154 Status = NtSetInformationFile(hMailslot,
157 sizeof(FILE_MAILSLOT_SET_INFORMATION),
158 FileMailslotSetInformation);
159 if (!NT_SUCCESS(Status))
161 DPRINT("NtSetInformationFile failed (Status %x)!\n", Status);
162 SetLastErrorByStatus (Status);