2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
9 #ifndef _STRALIGN_USE_SECURE_CRT
10 #define _STRALIGN_USE_SECURE_CRT 0
18 #if defined (__amd64__) || defined (__arm__)
19 #define WSTR_ALIGNED(s) TRUE
21 #define WSTR_ALIGNED(s) (((DWORD_PTR)(s) & 1) == 0)
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
35 PUWSTR
ua_wcscpy(PUWSTR Destination
,PCUWSTR Source
);
36 #if !defined (__CRT__NO_INLINE) && !defined (__CYGWIN__)
37 __CRT_INLINE PUWSTR
ua_wcscpy(PUWSTR Destination
,PCUWSTR Source
) { return wcscpy(Destination
,Source
); }
39 #define ua_wcscpy wcscpy
42 #else /* not _X86_ : */
45 #define WSTR_ALIGNED(s) (((DWORD_PTR)(s) & (sizeof(WCHAR)-1))==0)
48 /* TODO: This method seems to be not present for amd64. */
49 LPUWSTR WINAPI
uaw_CharUpperW(LPUWSTR String
);
50 int WINAPI
uaw_lstrcmpW(PCUWSTR String1
,PCUWSTR String2
);
51 int WINAPI
uaw_lstrcmpiW(PCUWSTR String1
,PCUWSTR String2
);
52 int WINAPI
uaw_lstrlenW(LPCUWSTR String
);
53 PUWSTR __cdecl
uaw_wcschr(PCUWSTR String
,WCHAR Character
);
54 PUWSTR __cdecl
uaw_wcscpy(PUWSTR Destination
,PCUWSTR Source
);
55 int __cdecl
uaw_wcsicmp(PCUWSTR String1
,PCUWSTR String2
);
56 size_t __cdecl
uaw_wcslen(PCUWSTR String
);
57 PUWSTR __cdecl
uaw_wcsrchr(PCUWSTR String
,WCHAR Character
);
59 LPUWSTR
ua_CharUpperW(LPUWSTR String
);
60 #ifndef __CRT__NO_INLINE
61 __CRT_INLINE LPUWSTR
ua_CharUpperW(LPUWSTR String
) {
62 if(WSTR_ALIGNED(String
)) return CharUpperW((PWSTR
)String
);
63 return uaw_CharUpperW(String
);
65 #endif /* !__CRT__NO_INLINE */
66 #endif /* CharUpper */
69 int ua_lstrcmpW(LPCUWSTR String1
,LPCUWSTR String2
);
72 int ua_lstrcmpiW(LPCUWSTR String1
,LPCUWSTR String2
);
75 int ua_lstrlenW(LPCUWSTR String
);
78 #ifndef __CRT__NO_INLINE
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
);
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
);
96 __CRT_INLINE
int ua_lstrlenW(LPCUWSTR String
) {
97 if(WSTR_ALIGNED(String
)) return lstrlenW((PCWSTR
)String
);
98 return uaw_lstrlenW(String
);
101 #endif /* !__CRT__NO_INLINE */
103 #if defined(_WSTRING_DEFINED)
104 #ifdef _WConst_return
105 typedef _WConst_return WCHAR UNALIGNED
*PUWSTR_C
;
107 typedef WCHAR UNALIGNED
*PUWSTR_C
;
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
);
116 PUWSTR
ua_wcscpy(PUWSTR Destination
,PCUWSTR Source
);
117 size_t ua_wcslen(PCUWSTR String
);
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
);
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
);
128 #if defined(__cplusplus) && defined(_WConst_Return)
129 __CRT_INLINE PUWSTR
ua_wcschr(PUWSTR String
,WCHAR Character
) {
130 if(WSTR_ALIGNED(String
)) return wcscpy((PWSTR
)Destination
,(PCWSTR
)Source
);
131 return uaw_wcscpy(Destination
,Source
);
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
);
139 __CRT_INLINE PUWSTR
ua_wcscpy(PUWSTR Destination
,PCUWSTR Source
) {
140 if(WSTR_ALIGNED(Source
) && WSTR_ALIGNED(Destination
))
141 return wcscpy((PWSTR
)Destination
,(PCWSTR
)Source
);
142 return uaw_wcscpy(Destination
,Source
);
144 __CRT_INLINE
size_t ua_wcslen(PCUWSTR String
) {
145 if(WSTR_ALIGNED(String
)) return wcslen((PCWSTR
)String
);
146 return uaw_wcslen(String
);
148 #endif /* !__CRT__NO_INLINE */
150 int ua_wcsicmp(LPCUWSTR String1
,LPCUWSTR String2
);
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
);
158 #endif /* !__CRT__NO_INLINE */
159 #endif /* _WSTRING_DEFINED */
162 #define __UA_WCSLEN ua_wcslen
165 #define __UA_WSTRSIZE(s) ((__UA_WCSLEN(s)+1)*sizeof(WCHAR))
166 #define __UA_STACKCOPY(p,s) memcpy(_alloca(s),p,s)
168 #if defined (__amd64__) || defined (__arm__) || defined (_X86_)
169 #define WSTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCWSTR)(s))
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; }
174 #define ASTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCSTR)(s))
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)))
180 #define STRUC_ALIGNED_STACK_COPY(t,s) ((CONST t *)(s))
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
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
205 #include <sec_api/stralign_s.h>