ReactOS 0.4.15-dev-8102-g108db8f
fileutils.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for fileutils.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PWCHAR FilenameA2W (LPCSTR NameA, BOOL alloc)
 
DWORD FilenameU2A_FitOrFail (LPSTR DestA, INT destLen, PUNICODE_STRING SourceU)
 
DWORD FilenameW2A_FitOrFail (LPSTR DestA, INT destLen, LPCWSTR SourceW, INT sourceLen)
 
DWORD FilenameA2W_N (LPWSTR dest, INT destlen, LPCSTR src, INT srclen)
 
DWORD FilenameW2A_N (LPSTR dest, INT destlen, LPCWSTR src, INT srclen)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file fileutils.c.

Function Documentation

◆ FilenameA2W()

PWCHAR FilenameA2W ( LPCSTR  NameA,
BOOL  alloc 
)

Definition at line 18 of file fileutils.c.

19{
22 PUNICODE_STRING pstrW;
24
25 //ASSERT(NtCurrentTeb()->StaticUnicodeString.Buffer == NtCurrentTeb()->StaticUnicodeBuffer);
26 ASSERT(NtCurrentTeb()->StaticUnicodeString.MaximumLength == sizeof(NtCurrentTeb()->StaticUnicodeBuffer));
27
28 RtlInitAnsiString(&str, NameA);
29 pstrW = alloc ? &strW : &NtCurrentTeb()->StaticUnicodeString;
30
31 if (AreFileApisANSI())
33 else
35
36 if (NT_SUCCESS(Status))
37 return pstrW->Buffer;
38
41 else
43
44 return NULL;
45}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
Status
Definition: gdiplustypes.h:25
#define NtCurrentTeb
#define ASSERT(a)
Definition: mode.c:44
WCHAR strW[12]
Definition: clipboard.c:2029
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define alloc
Definition: rosglue.h:13
const WCHAR * str
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
BOOL WINAPI AreFileApisANSI(void)
Definition: utils.c:866
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263

Referenced by CreateFileA(), CreateSymbolicLinkA(), GetCompressedFileSizeA(), GetFileAttributesA(), GetFileAttributesExA(), SetFileAttributesA(), and SetFileShortNameA().

◆ FilenameA2W_N()

DWORD FilenameA2W_N ( LPWSTR  dest,
INT  destlen,
LPCSTR  src,
INT  srclen 
)

Definition at line 121 of file fileutils.c.

127{
128 DWORD ret;
129
130 if (srclen < 0) srclen = strlen( src ) + 1;
131
132 if (AreFileApisANSI())
133 RtlMultiByteToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src, srclen );
134 else
135 RtlOemToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src, srclen );
136
137 if (ret) dest[(ret/sizeof(WCHAR))-1]=0;
138
139 return ret/sizeof(WCHAR);
140}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:52
static char * dest
Definition: rtl.c:135
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:62
_Use_decl_annotations_ NTSTATUS NTAPI RtlOemToUnicodeN(_Out_ PWCHAR UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH OemString, _In_ ULONG OemSize)
Definition: nlsboot.c:282
int ret
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ FilenameU2A_FitOrFail()

DWORD FilenameU2A_FitOrFail ( LPSTR  DestA,
INT  destLen,
PUNICODE_STRING  SourceU 
)

Definition at line 56 of file fileutils.c.

61{
62 DWORD ret;
63
64 /* destLen should never exceed MAX_PATH */
65 if (destLen > MAX_PATH) destLen = MAX_PATH;
66
68 /* ret incl. nullchar */
69
70 if (DestA && (INT)ret <= destLen)
71 {
73
74 str.Buffer = DestA;
75 str.MaximumLength = (USHORT)destLen;
76
77
78 if (AreFileApisANSI())
80 else
82
83 ret = str.Length; /* SUCCESS: length without terminating 0 */
84 }
85
86 return ret;
87}
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
unsigned short USHORT
Definition: pedump.c:61
int32_t INT
Definition: typedefs.h:58
#define RtlUnicodeStringToOemSize(STRING)
#define RtlUnicodeStringToAnsiSize(String)
Definition: rtlfuncs.h:1005

Referenced by FilenameW2A_FitOrFail(), and GetFinalPathNameByHandleA().

◆ FilenameW2A_FitOrFail()

DWORD FilenameW2A_FitOrFail ( LPSTR  DestA,
INT  destLen,
LPCWSTR  SourceW,
INT  sourceLen 
)

Definition at line 98 of file fileutils.c.

104{
106
107 if (sourceLen < 0) sourceLen = wcslen(SourceW) + 1;
108
109 strW.Buffer = (PWCHAR)SourceW;
110 strW.MaximumLength = sourceLen * sizeof(WCHAR);
111 strW.Length = strW.MaximumLength - sizeof(WCHAR);
112
113 return FilenameU2A_FitOrFail(DestA, destLen, &strW);
114}
DWORD FilenameU2A_FitOrFail(LPSTR DestA, INT destLen, PUNICODE_STRING SourceU)
Definition: fileutils.c:56
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by GetTempPathA().

◆ FilenameW2A_N()

DWORD FilenameW2A_N ( LPSTR  dest,
INT  destlen,
LPCWSTR  src,
INT  srclen 
)

Definition at line 146 of file fileutils.c.

152{
153 DWORD ret;
154
155 if (srclen < 0) srclen = wcslen( src ) + 1;
156
157 if (AreFileApisANSI())
158 RtlUnicodeToMultiByteN( dest, destlen, &ret, (LPWSTR) src, srclen * sizeof(WCHAR));
159 else
160 RtlUnicodeToOemN( dest, destlen, &ret, (LPWSTR) src, srclen * sizeof(WCHAR) );
161
162 if (ret) dest[ret-1]=0;
163
164 return ret;
165}
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToOemN(_Out_ PCHAR OemString, _In_ ULONG OemSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:263
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:107
WCHAR * LPWSTR
Definition: xmlstorage.h:184