ReactOS 0.4.16-dev-2274-gc61d98f
pathansi.c File Reference
#include <k32.h>
Include dependency graph for pathansi.c:

Go to the source code of this file.

Functions

DWORD WINAPI GetShortPathNameA (IN LPCSTR lpszLongPath, OUT LPSTR lpszShortPath, IN DWORD cchBuffer)
 

Function Documentation

◆ GetShortPathNameA()

DWORD WINAPI GetShortPathNameA ( IN LPCSTR  lpszLongPath,
OUT LPSTR  lpszShortPath,
IN DWORD  cchBuffer 
)

Definition at line 20 of file pathansi.c.

23{
25 PWCHAR ShortPath;
27 UNICODE_STRING LongPathUni, ShortPathUni;
28 ANSI_STRING ShortPathAnsi;
29 WCHAR ShortPathBuffer[MAX_PATH];
30
31 ShortPath = NULL;
32 ShortPathAnsi.Buffer = NULL;
33 LongPathUni.Buffer = NULL;
34 Result = 0;
35
36 if (!lpszLongPath)
37 {
39 return 0;
40 }
41
42 Status = Basep8BitStringToDynamicUnicodeString(&LongPathUni, lpszLongPath);
43 if (!NT_SUCCESS(Status)) goto Quickie;
44
45 ShortPath = ShortPathBuffer;
46
47 PathLength = GetShortPathNameW(LongPathUni.Buffer, ShortPathBuffer, MAX_PATH);
48 if (PathLength >= MAX_PATH)
49 {
50 ShortPath = RtlAllocateHeap(RtlGetProcessHeap(), 0, PathLength * sizeof(WCHAR));
51 if (!ShortPath)
52 {
53 PathLength = 0;
55 }
56 else
57 {
58 PathLength = GetShortPathNameW(LongPathUni.Buffer, ShortPath, PathLength);
59 }
60 }
61
62 if (!PathLength) goto Quickie;
63
64 LongPathUni.MaximumLength = (USHORT)PathLength * sizeof(WCHAR) + sizeof(UNICODE_NULL);
65 ShortPathUni.Buffer = ShortPath;
66 ShortPathUni.Length = (USHORT)PathLength * sizeof(WCHAR);
67
68 Status = BasepUnicodeStringTo8BitString(&ShortPathAnsi, &ShortPathUni, TRUE);
69 if (!NT_SUCCESS(Status))
70 {
72 Result = 0;
73 }
74
75 Result = ShortPathAnsi.Length;
76 if ((lpszShortPath) && (cchBuffer > ShortPathAnsi.Length))
77 {
78 RtlMoveMemory(lpszShortPath, ShortPathAnsi.Buffer, ShortPathAnsi.Length);
79 lpszShortPath[Result] = ANSI_NULL;
80 }
81 else
82 {
83 Result = ShortPathAnsi.Length + sizeof(ANSI_NULL);
84 }
85
86Quickie:
87 if (LongPathUni.Buffer) RtlFreeUnicodeString(&LongPathUni);
88 if (ShortPathAnsi.Buffer) RtlFreeAnsiString(&ShortPathAnsi);
89 if ((ShortPath) && (ShortPath != ShortPathBuffer))
90 {
91 RtlFreeHeap(RtlGetProcessHeap(), 0, ShortPath);
92 }
93 return Result;
94}
static USHORT PathLength
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 TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define MAX_PATH
Definition: compat.h:34
static DWORD cchBuffer
Definition: fusion.c:85
DWORD WINAPI GetShortPathNameW(IN LPCWSTR lpszLongPath, OUT LPWSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1752
PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString
Definition: utils.c:28
BOOLEAN WINAPI Basep8BitStringToDynamicUnicodeString(OUT PUNICODE_STRING UnicodeString, IN LPCSTR String)
Definition: utils.c:226
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
#define ANSI_NULL
unsigned short USHORT
Definition: pedump.c:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DosChangeDirectory(), DosKRNLInitialize(), DosLoadExecutable(), full_file_path_name_in_a_CWD(), okChildPath_(), PathGetShortPathA(), START_TEST(), StoreNameInSft(), test_drive_letter_case(), test_filenames(), test_GetLongPathNameA(), test_PathNameA(), test_relative_path(), test_SdbGetPermLayerKeys(), test_ShortPathCase(), and test_ValidPathA().