ReactOS 0.4.15-dev-7934-g1dc8d80
stralign.h
Go to the documentation of this file.
1
6#ifndef __STRALIGN_H_
7#define __STRALIGN_H_
8
9#ifndef _STRALIGN_USE_SECURE_CRT
10#define _STRALIGN_USE_SECURE_CRT 0
11#endif
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#ifndef WSTR_ALIGNED
18#if defined (__amd64__) || defined (__arm__)
19#define WSTR_ALIGNED(s) TRUE
20#else
21#define WSTR_ALIGNED(s) (((DWORD_PTR)(s) & 1) == 0)
22#endif
23#endif
24
25#if defined(_X86_)
26#define ua_CharUpperW CharUpperW
27#define ua_lstrcmpiW lstrcmpiW
28#define ua_lstrcmpW lstrcmpW
29#define ua_lstrlenW lstrlenW
30#define ua_wcschr wcschr
31#define ua_wcsicmp wcsicmp
32#define ua_wcslen wcslen
33#define ua_wcsrchr wcsrchr
34
36#if !defined (__CRT__NO_INLINE) && !defined (__CYGWIN__)
37 __CRT_INLINE PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) { return wcscpy(Destination,Source); }
38#else
39#define ua_wcscpy wcscpy
40#endif
41
42#else /* not _X86_ : */
43
44#ifndef WSTR_ALIGNED
45#define WSTR_ALIGNED(s) (((DWORD_PTR)(s) & (sizeof(WCHAR)-1))==0)
46#endif
47
48 /* TODO: This method seems to be not present for amd64. */
58#ifdef CharUpper
59 LPUWSTR ua_CharUpperW(LPUWSTR String);
60#ifndef __CRT__NO_INLINE
61 __CRT_INLINE LPUWSTR ua_CharUpperW(LPUWSTR String) {
63 return uaw_CharUpperW(String);
64 }
65#endif /* !__CRT__NO_INLINE */
66#endif /* CharUpper */
67
68#ifdef lstrcmp
69 int ua_lstrcmpW(LPCUWSTR String1,LPCUWSTR String2);
70#endif
71#ifdef lstrcmpi
72 int ua_lstrcmpiW(LPCUWSTR String1,LPCUWSTR String2);
73#endif
74#ifdef lstrlen
75 int ua_lstrlenW(LPCUWSTR String);
76#endif
77
78#ifndef __CRT__NO_INLINE
79#ifdef lstrcmp
80 __CRT_INLINE int ua_lstrcmpW(LPCUWSTR String1,LPCUWSTR String2) {
81 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2))
82 return lstrcmpW((LPCWSTR)String1,(LPCWSTR)String2);
83 return uaw_lstrcmpW(String1,String2);
84 }
85#endif
86
87#ifdef lstrcmpi
88 __CRT_INLINE int ua_lstrcmpiW(LPCUWSTR String1,LPCUWSTR String2) {
89 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2))
90 return lstrcmpiW((LPCWSTR)String1,(LPCWSTR)String2);
91 return uaw_lstrcmpiW(String1,String2);
92 }
93#endif
94
95#ifdef lstrlen
96 __CRT_INLINE int ua_lstrlenW(LPCUWSTR String) {
98 return uaw_lstrlenW(String);
99 }
100#endif
101#endif /* !__CRT__NO_INLINE */
102
103#if defined(_WSTRING_DEFINED)
104#ifdef _WConst_return
105 typedef _WConst_return WCHAR UNALIGNED *PUWSTR_C;
106#else
107 typedef WCHAR UNALIGNED *PUWSTR_C;
108#endif
109
110 PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character);
111 PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character);
112#if defined(__cplusplus) && defined(_WConst_Return)
113 PUWSTR ua_wcschr(PUWSTR String,WCHAR Character);
114 PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character);
115#endif
117 size_t ua_wcslen(PCUWSTR String);
118
119#ifndef __CRT__NO_INLINE
120 __CRT_INLINE PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) {
121 if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character);
122 return (PUWSTR_C)uaw_wcschr(String,Character);
123 }
124 __CRT_INLINE PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character) {
125 if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character);
126 return (PUWSTR_C)uaw_wcsrchr(String,Character);
127 }
128#if defined(__cplusplus) && defined(_WConst_Return)
129 __CRT_INLINE PUWSTR ua_wcschr(PUWSTR String,WCHAR Character) {
132 }
133 __CRT_INLINE PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character) {
134 if(WSTR_ALIGNED(String)) return wcsrchr(String,Character);
135 return uaw_wcsrchr((PCUWSTR)String,Character);
136 }
137#endif
138
139 __CRT_INLINE PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) {
143 }
144 __CRT_INLINE size_t ua_wcslen(PCUWSTR String) {
145 if(WSTR_ALIGNED(String)) return wcslen((PCWSTR)String);
146 return uaw_wcslen(String);
147 }
148#endif /* !__CRT__NO_INLINE */
149#endif /* _X86_ */
150 int ua_wcsicmp(LPCUWSTR String1,LPCUWSTR String2);
151
152#ifndef __CRT__NO_INLINE
153 __CRT_INLINE int ua_wcsicmp(LPCUWSTR String1,LPCUWSTR String2) {
154 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2))
155 return _wcsicmp((LPCWSTR)String1,(LPCWSTR)String2);
156 return uaw_wcsicmp(String1,String2);
157 }
158#endif /* !__CRT__NO_INLINE */
159#endif /* _WSTRING_DEFINED */
160
161#ifndef __UA_WCSLEN
162#define __UA_WCSLEN ua_wcslen
163#endif
164
165#define __UA_WSTRSIZE(s) ((__UA_WCSLEN(s)+1)*sizeof(WCHAR))
166#define __UA_STACKCOPY(p,s) memcpy(_alloca(s),p,s)
167
168#if defined (__amd64__) || defined (__arm__) || defined (_X86_)
169#define WSTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCWSTR)(s))
170#else
171#define WSTR_ALIGNED_STACK_COPY(d,s) { PCUWSTR __ua_src; ULONG __ua_size; PWSTR __ua_dst; __ua_src = (s); if(WSTR_ALIGNED(__ua_src)) { __ua_dst = (PWSTR)__ua_src; } else { __ua_size = __UA_WSTRSIZE(__ua_src); __ua_dst = (PWSTR)_alloca(__ua_size); memcpy(__ua_dst,__ua_src,__ua_size); } *(d) = (PCWSTR)__ua_dst; }
172#endif
173
174#define ASTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCSTR)(s))
175
176#if !defined (_X86_) && !defined (__amd64__) && !defined (__arm__)
177#define __UA_STRUC_ALIGNED(t,s) (((DWORD_PTR)(s) & (TYPE_ALIGNMENT(t)-1))==0)
178#define STRUC_ALIGNED_STACK_COPY(t,s) __UA_STRUC_ALIGNED(t,s) ? ((t const *)(s)) : ((t const *)__UA_STACKCOPY((s),sizeof(t)))
179#else
180#define STRUC_ALIGNED_STACK_COPY(t,s) ((CONST t *)(s))
181#endif
182
183#if defined(UNICODE)
184#define TSTR_ALIGNED_STACK_COPY(d,s) WSTR_ALIGNED_STACK_COPY(d,s)
185#define TSTR_ALIGNED(x) WSTR_ALIGNED(x)
186#define ua_CharUpper ua_CharUpperW
187#define ua_lstrcmp ua_lstrcmpW
188#define ua_lstrcmpi ua_lstrcmpiW
189#define ua_lstrlen ua_lstrlenW
190#define ua_tcscpy ua_wcscpy
191#else
192#define TSTR_ALIGNED_STACK_COPY(d,s) ASTR_ALIGNED_STACK_COPY(d,s)
193#define TSTR_ALIGNED(x) TRUE
194#define ua_CharUpper CharUpperA
195#define ua_lstrcmp lstrcmpA
196#define ua_lstrcmpi lstrcmpiA
197#define ua_lstrlen lstrlenA
198#define ua_tcscpy strcpy
199#endif
200
201#ifdef __cplusplus
202}
203#endif
204
205#include <sec_api/stralign_s.h>
206#endif
#define __cdecl
Definition: accygwin.h:79
#define UNALIGNED
Definition: crtdefs.h:144
#define wcschr
Definition: compat.h:17
#define wcsrchr
Definition: compat.h:16
#define lstrlenW
Definition: compat.h:750
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ const STRING * String2
Definition: rtlfuncs.h:2357
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
_Null_terminated_ WCHAR UNALIGNED * LPUWSTR
Definition: ntbasedef.h:415
_Null_terminated_ CONST WCHAR UNALIGNED * LPCUWSTR
Definition: ntbasedef.h:418
_Null_terminated_ WCHAR UNALIGNED * PUWSTR
Definition: ntbasedef.h:415
_Null_terminated_ CONST WCHAR UNALIGNED * PCUWSTR
Definition: ntbasedef.h:418
#define _WConst_return
Definition: memory.h:19
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
PUWSTR __cdecl uaw_wcschr(PCUWSTR String, WCHAR Character)
int WINAPI uaw_lstrcmpW(PCUWSTR String1, PCUWSTR String2)
#define WSTR_ALIGNED(s)
Definition: stralign.h:21
int WINAPI uaw_lstrcmpiW(PCUWSTR String1, PCUWSTR String2)
PUWSTR __cdecl uaw_wcscpy(PUWSTR Destination, PCUWSTR Source)
size_t __cdecl uaw_wcslen(PCUWSTR String)
int WINAPI uaw_lstrlenW(LPCUWSTR String)
int __cdecl uaw_wcsicmp(PCUWSTR String1, PCUWSTR String2)
int ua_wcsicmp(LPCUWSTR String1, LPCUWSTR String2)
Definition: stralign.h:153
LPUWSTR WINAPI uaw_CharUpperW(LPUWSTR String)
PUWSTR __cdecl uaw_wcsrchr(PCUWSTR String, WCHAR Character)
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
#define WINAPI
Definition: msvc.h:6
LPWSTR WINAPI CharUpperW(_Inout_ LPWSTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185