ReactOS 0.4.16-dev-2274-gc61d98f
volumeansi.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/file/volumeansi.c
5 * PURPOSE: Volume functions (ANSI)
6 */
7
8/* INCLUDES *****************************************************************/
9
10#include <k32.h>
11
12/* FUNCTIONS ****************************************************************/
13
14/*
15 * @implemented
16 */
17BOOL
20 IN LPSTR lpszVolumePathName,
21 IN DWORD cchBufferLength)
22{
23 BOOL Ret;
24 PUNICODE_STRING FileNameU;
25 ANSI_STRING VolumePathName;
26 UNICODE_STRING VolumePathNameU;
27
28 /* Convert file name to unicode */
29 FileNameU = Basep8BitStringToStaticUnicodeString(lpszFileName);
30 if (FileNameU == NULL)
31 {
32 return FALSE;
33 }
34
35 /* Initialize all the strings we'll need */
36 VolumePathName.Buffer = lpszVolumePathName;
37 VolumePathName.Length = 0;
38 VolumePathName.MaximumLength = cchBufferLength - 1;
39
40 VolumePathNameU.Length = 0;
41 VolumePathNameU.MaximumLength = (cchBufferLength - 1) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
42 /* Allocate a buffer for calling the -W */
43 VolumePathNameU.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, VolumePathNameU.MaximumLength);
44 if (VolumePathNameU.Buffer == NULL)
45 {
47 return FALSE;
48 }
49
50 /* Call the -W implementation */
51 Ret = GetVolumePathNameW(FileNameU->Buffer, VolumePathNameU.Buffer, cchBufferLength);
52 /* If it succeed */
53 if (Ret)
54 {
56
57 /* Convert back to ANSI */
58 RtlInitUnicodeString(&VolumePathNameU, VolumePathNameU.Buffer);
59 Status = RtlUnicodeStringToAnsiString(&VolumePathName, &VolumePathNameU, FALSE);
60 /* If conversion failed, just set error code and fail the rest */
61 if (!NT_SUCCESS(Status))
62 {
64 Ret = FALSE;
65 }
66 /* Otherwise, null terminate the string (it's OK, we computed -1) */
67 else
68 {
69 VolumePathName.Buffer[VolumePathName.Length] = ANSI_NULL;
70 }
71 }
72
73 /* Free the buffer allocated for -W call */
74 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumePathNameU.Buffer);
75 return Ret;
76}
77
78/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:751
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:189
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNICODE_NULL
#define ANSI_NULL
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
USHORT MaximumLength
Definition: env_spec_w32.h:377
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IN
Definition: typedefs.h:39
BOOL WINAPI GetVolumePathNameA(IN LPCSTR lpszFileName, IN LPSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volumeansi.c:19
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
char * LPSTR
Definition: xmlstorage.h:182