ReactOS  0.4.15-dev-2344-g8ddbfde
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 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
WCHAR strW[12]
Definition: clipboard.c:2029
BOOL WINAPI AreFileApisANSI(VOID)
Definition: utils.c:863
const WCHAR * str
unsigned char BOOLEAN
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:611
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define alloc
Definition: rosglue.h:13
#define NULL
Definition: types.h:112
#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 }
NTSYSAPI NTSTATUS WINAPI RtlOemToUnicodeN(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * LPSTR
Definition: xmlstorage.h:182
BOOL WINAPI AreFileApisANSI(VOID)
Definition: utils.c:863
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
GLenum src
Definition: glext.h:6340
static char * dest
Definition: rtl.c:135

◆ 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 }
int32_t INT
Definition: typedefs.h:58
#define FALSE
Definition: types.h:117
BOOL WINAPI AreFileApisANSI(VOID)
Definition: utils.c:863
const WCHAR * str
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI DWORD WINAPI RtlUnicodeStringToAnsiSize(const UNICODE_STRING *)
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI DWORD WINAPI RtlUnicodeStringToOemSize(const UNICODE_STRING *)

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 }
uint16_t * PWCHAR
Definition: typedefs.h:56
DWORD FilenameU2A_FitOrFail(LPSTR DestA, INT destLen, PUNICODE_STRING SourceU)
Definition: fileutils.c:56
WCHAR strW[12]
Definition: clipboard.c:2029
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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 }
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToOemN(PCHAR OemString, ULONG OemSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
BOOL WINAPI AreFileApisANSI(VOID)
Definition: utils.c:863
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToMultiByteN(PCHAR MbString, ULONG MbSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
GLenum src
Definition: glext.h:6340
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static char * dest
Definition: rtl.c:135
WCHAR * LPWSTR
Definition: xmlstorage.h:184