win64: use new headers from mingw
[tinycc.git] / win32 / include / winapi / stralign.h
blob38120359d2691789bb8391c727b66476d9b57718
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER within this package.
5 */
6 #ifndef __STRALIGN_H_
7 #define __STRALIGN_H_
9 #ifndef _STRALIGN_USE_SECURE_CRT
10 #define _STRALIGN_USE_SECURE_CRT 0
11 #endif
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
17 #if defined(I_X86_)
18 #define WSTR_ALIGNED(s) TRUE
19 #define ua_CharUpperW CharUpperW
20 #define ua_lstrcmpiW lstrcmpiW
21 #define ua_lstrcmpW lstrcmpW
22 #define ua_lstrlenW lstrlenW
23 #define ua_wcschr wcschr
24 #define ua_wcsicmp wcsicmp
25 #define ua_wcslen wcslen
26 #define ua_wcsrchr wcsrchr
27 static __inline PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) { return wcscpy(Destination,Source); }
28 #else
29 #define WSTR_ALIGNED(s) (((DWORD_PTR)(s) & (sizeof(WCHAR)-1))==0)
31 LPUWSTR WINAPI uaw_CharUpperW(LPUWSTR String);
32 int WINAPI uaw_lstrcmpW(PCUWSTR String1,PCUWSTR String2);
33 int WINAPI uaw_lstrcmpiW(PCUWSTR String1,PCUWSTR String2);
34 int WINAPI uaw_lstrlenW(LPCUWSTR String);
35 PUWSTR __cdecl uaw_wcschr(PCUWSTR String,WCHAR Character);
36 PUWSTR __cdecl uaw_wcscpy(PUWSTR Destination,PCUWSTR Source);
37 int __cdecl uaw_wcsicmp(PCUWSTR String1,PCUWSTR String2);
38 size_t __cdecl uaw_wcslen(PCUWSTR String);
39 PUWSTR __cdecl uaw_wcsrchr(PCUWSTR String,WCHAR Character);
40 #ifdef CharUpper
41 static __inline LPUWSTR ua_CharUpperW(LPUWSTR String) {
42 if(WSTR_ALIGNED(String)) return CharUpperW((PWSTR)String);
43 return uaw_CharUpperW(String);
45 #endif
47 #ifdef lstrcmp
48 static __inline int ua_lstrcmpW(LPCUWSTR String1,LPCUWSTR String2) {
49 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2)) return lstrcmpW((LPCWSTR)String1,(LPCWSTR)String2);
50 return uaw_lstrcmpW(String1,String2);
52 #endif
54 #ifdef lstrcmpi
55 static __inline int ua_lstrcmpiW(LPCUWSTR String1,LPCUWSTR String2) {
56 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2)) return lstrcmpiW((LPCWSTR)String1,(LPCWSTR)String2);
57 return uaw_lstrcmpiW(String1,String2);
59 #endif
61 #ifdef lstrlen
62 static __inline int ua_lstrlenW(LPCUWSTR String) {
63 if(WSTR_ALIGNED(String)) return lstrlenW((PCWSTR)String);
64 return uaw_lstrlenW(String);
66 #endif
68 #if defined(_WSTRING_DEFINED)
69 #ifdef _WConst_return
70 typedef _WConst_return WCHAR UNALIGNED *PUWSTR_C;
71 #else
72 typedef WCHAR UNALIGNED *PUWSTR_C;
73 #endif
74 static __inline PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) {
75 if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character);
76 return (PUWSTR_C)uaw_wcschr(String,Character);
78 static __inline PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character) {
79 if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character);
80 return (PUWSTR_C)uaw_wcsrchr(String,Character);
82 #if defined(__cplusplus) && defined(_WConst_Return)
83 static __inline PUWSTR ua_wcschr(PUWSTR String,WCHAR Character) {
84 if(WSTR_ALIGNED(String)) return wcscpy((PWSTR)Destination,(PCWSTR)Source);
85 return uaw_wcscpy(Destination,Source);
87 static __inline PUWSTR ua_wcsrchr(PUWSTR String,WCHAR Character) {
88 if(WSTR_ALIGNED(String)) return wcsrchr(String,Character);
89 return uaw_wcsrchr((PCUWSTR)String,Character);
91 #endif
93 static __inline PUWSTR ua_wcscpy(PUWSTR Destination,PCUWSTR Source) {
94 if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return wcscpy((PWSTR)Destination,(PCWSTR)Source);
95 return uaw_wcscpy(Destination,Source);
97 static __inline size_t ua_wcslen(PCUWSTR String) {
98 if(WSTR_ALIGNED(String)) return wcslen((PCWSTR)String);
99 return uaw_wcslen(String);
101 #endif
103 static __inline int ua_wcsicmp(LPCUWSTR String1,LPCUWSTR String2) {
104 if(WSTR_ALIGNED(String1) && WSTR_ALIGNED(String2)) return _wcsicmp((LPCWSTR)String1,(LPCWSTR)String2);
105 return uaw_wcsicmp(String1,String2);
107 #endif
109 #ifndef __UA_WCSLEN
110 #define __UA_WCSLEN ua_wcslen
111 #endif
113 #define __UA_WSTRSIZE(s) ((__UA_WCSLEN(s)+1)*sizeof(WCHAR))
114 #define __UA_STACKCOPY(p,s) memcpy(_alloca(s),p,s)
116 #ifdef I_X86_
117 #define WSTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCWSTR)(s))
118 #else
119 #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; }
120 #endif
122 #define ASTR_ALIGNED_STACK_COPY(d,s) (*(d) = (PCSTR)(s))
124 #ifndef I_X86_
125 #define __UA_STRUC_ALIGNED(t,s) (((DWORD_PTR)(s) & (TYPE_ALIGNMENT(t)-1))==0)
126 #define STRUC_ALIGNED_STACK_COPY(t,s) __UA_STRUC_ALIGNED(t,s) ? ((t const *)(s)) : ((t const *)__UA_STACKCOPY((s),sizeof(t)))
127 #else
128 #define STRUC_ALIGNED_STACK_COPY(t,s) ((CONST t *)(s))
129 #endif
131 #ifdef UNICODE
132 #define TSTR_ALIGNED_STACK_COPY(d,s) WSTR_ALIGNED_STACK_COPY(d,s)
133 #define TSTR_ALIGNED(x) WSTR_ALIGNED(x)
134 #define ua_CharUpper ua_CharUpperW
135 #define ua_lstrcmp ua_lstrcmpW
136 #define ua_lstrcmpi ua_lstrcmpiW
137 #define ua_lstrlen ua_lstrlenW
138 #define ua_tcscpy ua_wcscpy
139 #else
140 #define TSTR_ALIGNED_STACK_COPY(d,s) ASTR_ALIGNED_STACK_COPY(d,s)
141 #define TSTR_ALIGNED(x) TRUE
142 #define ua_CharUpper CharUpperA
143 #define ua_lstrcmp lstrcmpA
144 #define ua_lstrcmpi lstrcmpiA
145 #define ua_lstrlen lstrlenA
146 #define ua_tcscpy strcpy
147 #endif
149 #ifdef __cplusplus
151 #endif
153 #include <sec_api/stralign_s.h>
154 #endif