4 * Copyright 1993 Yngvi Sigurjonsson
5 * Copyright 1996 Alexandre Julliard
13 #include "wine/winbase16.h"
14 #include "wine/exception.h"
15 #include "wine/unicode.h"
18 #include "msvcrt/excpt.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(string
);
23 /* filter for page-fault exceptions */
24 static WINE_EXCEPTION_FILTER(page_fault
)
26 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
27 return EXCEPTION_EXECUTE_HANDLER
;
28 return EXCEPTION_CONTINUE_SEARCH
;
32 /***********************************************************************
33 * hmemcpy (KERNEL.348)
35 void WINAPI
hmemcpy16( LPVOID dst
, LPCVOID src
, LONG count
)
37 memcpy( dst
, src
, count
);
41 /***********************************************************************
44 SEGPTR WINAPI
lstrcat16( SEGPTR dst
, LPCSTR src
)
46 /* Windows does not check for NULL pointers here, so we don't either */
47 strcat( MapSL(dst
), src
);
52 /***********************************************************************
53 * lstrcat (KERNEL32.@)
54 * lstrcatA (KERNEL32.@)
56 LPSTR WINAPI
lstrcatA( LPSTR dst
, LPCSTR src
)
64 SetLastError( ERROR_INVALID_PARAMETER
);
72 /***********************************************************************
73 * lstrcatW (KERNEL32.@)
75 LPWSTR WINAPI
lstrcatW( LPWSTR dst
, LPCWSTR src
)
83 SetLastError( ERROR_INVALID_PARAMETER
);
91 /***********************************************************************
92 * lstrcatn (KERNEL.352)
94 SEGPTR WINAPI
lstrcatn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
100 if ((n
-= (p
- start
)) <= 0) return dst
;
101 lstrcpynA( p
, src
, n
);
106 /***********************************************************************
107 * lstrcmp (KERNEL32.@)
108 * lstrcmpA (KERNEL32.@)
110 INT WINAPI
lstrcmpA( LPCSTR str1
, LPCSTR str2
)
112 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,0,str1
,-1,str2
,-1) - 2 ;
116 /***********************************************************************
117 * lstrcmpW (KERNEL32.@)
118 * FIXME : should call CompareStringW, when it is implemented.
119 * This implementation is not "word sort", as it should.
121 INT WINAPI
lstrcmpW( LPCWSTR str1
, LPCWSTR str2
)
124 debugstr_w (str1
), debugstr_w (str2
));
125 if (!str1
|| !str2
) {
126 SetLastError(ERROR_INVALID_PARAMETER
);
129 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
130 return (INT
)(*str1
- *str2
);
134 /***********************************************************************
135 * lstrcmpi (KERNEL32.@)
136 * lstrcmpiA (KERNEL32.@)
138 INT WINAPI
lstrcmpiA( LPCSTR str1
, LPCSTR str2
)
139 { TRACE("strcmpi %s and %s\n",
140 debugstr_a (str1
), debugstr_a (str2
));
141 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,NORM_IGNORECASE
,str1
,-1,str2
,-1)-2;
145 /***********************************************************************
146 * lstrcmpiW (KERNEL32.@)
148 INT WINAPI
lstrcmpiW( LPCWSTR str1
, LPCWSTR str2
)
150 if (!str1
|| !str2
) {
151 SetLastError(ERROR_INVALID_PARAMETER
);
154 return strcmpiW( str1
, str2
);
158 /***********************************************************************
159 * lstrcpy (KERNEL.88)
161 SEGPTR WINAPI
lstrcpy16( SEGPTR dst
, LPCSTR src
)
163 if (!lstrcpyA( MapSL(dst
), src
)) dst
= 0;
168 /***********************************************************************
169 * lstrcpy (KERNEL32.@)
170 * lstrcpyA (KERNEL32.@)
172 LPSTR WINAPI
lstrcpyA( LPSTR dst
, LPCSTR src
)
176 /* this is how Windows does it */
177 memmove( dst
, src
, strlen(src
)+1 );
181 ERR("(%p, %p): page fault occurred ! Caused by bug ?\n", dst
, src
);
182 SetLastError( ERROR_INVALID_PARAMETER
);
190 /***********************************************************************
191 * lstrcpyW (KERNEL32.@)
193 LPWSTR WINAPI
lstrcpyW( LPWSTR dst
, LPCWSTR src
)
201 SetLastError( ERROR_INVALID_PARAMETER
);
209 /***********************************************************************
210 * lstrcpyn (KERNEL.353)
212 SEGPTR WINAPI
lstrcpyn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
214 lstrcpynA( MapSL(dst
), src
, n
);
219 /***********************************************************************
220 * lstrcpyn (KERNEL32.@)
221 * lstrcpynA (KERNEL32.@)
223 * Note: this function differs from the UNIX strncpy, it _always_ writes
226 LPSTR WINAPI
lstrcpynA( LPSTR dst
, LPCSTR src
, INT n
)
229 TRACE("(%p, %s, %i)\n", dst
, debugstr_an(src
,n
), n
);
230 /* In real windows the whole function is protected by an exception handler
231 * that returns ERROR_INVALID_PARAMETER on faulty parameters
232 * We currently just check for NULL.
235 SetLastError(ERROR_INVALID_PARAMETER
);
238 while ((n
-- > 1) && *src
) *p
++ = *src
++;
244 /***********************************************************************
245 * lstrcpynW (KERNEL32.@)
246 * Note: this function differs from the UNIX strncpy, it _always_ writes
249 LPWSTR WINAPI
lstrcpynW( LPWSTR dst
, LPCWSTR src
, INT n
)
252 TRACE("(%p, %s, %i)\n", dst
, debugstr_wn(src
,n
), n
);
253 /* In real windows the whole function is protected by an exception handler
254 * that returns ERROR_INVALID_PARAMETER on faulty parameters
255 * We currently just check for NULL.
258 SetLastError(ERROR_INVALID_PARAMETER
);
261 while ((n
-- > 1) && *src
) *p
++ = *src
++;
267 /***********************************************************************
268 * lstrlen (KERNEL.90)
270 INT16 WINAPI
lstrlen16( LPCSTR str
)
272 return (INT16
)lstrlenA( str
);
276 /***********************************************************************
277 * lstrlen (KERNEL32.@)
278 * lstrlenA (KERNEL32.@)
280 INT WINAPI
lstrlenA( LPCSTR str
)
289 SetLastError( ERROR_INVALID_PARAMETER
);
297 /***********************************************************************
298 * lstrlenW (KERNEL32.@)
300 INT WINAPI
lstrlenW( LPCWSTR str
)
309 SetLastError( ERROR_INVALID_PARAMETER
);
317 /***********************************************************************
318 * UnicodeToAnsi (KERNEL.434)
320 INT16 WINAPI
UnicodeToAnsi16( LPCWSTR src
, LPSTR dst
, INT16 codepage
)
322 if ( codepage
== -1 )
325 return WideCharToMultiByte( codepage
, 0, src
, -1, dst
, 0x7fffffff, NULL
, NULL
);