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 "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(string
);
22 /* filter for page-fault exceptions */
23 static WINE_EXCEPTION_FILTER(page_fault
)
25 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
26 return EXCEPTION_EXECUTE_HANDLER
;
27 return EXCEPTION_CONTINUE_SEARCH
;
31 /***********************************************************************
32 * hmemcpy (KERNEL.348)
34 void WINAPI
hmemcpy16( LPVOID dst
, LPCVOID src
, LONG count
)
36 memcpy( dst
, src
, count
);
40 /***********************************************************************
43 SEGPTR WINAPI
lstrcat16( SEGPTR dst
, LPCSTR src
)
45 /* Windows does not check for NULL pointers here, so we don't either */
46 strcat( MapSL(dst
), src
);
51 /***********************************************************************
52 * lstrcat (KERNEL32.@)
53 * lstrcatA (KERNEL32.@)
55 LPSTR WINAPI
lstrcatA( LPSTR dst
, LPCSTR src
)
63 SetLastError( ERROR_INVALID_PARAMETER
);
71 /***********************************************************************
72 * lstrcatW (KERNEL32.@)
74 LPWSTR WINAPI
lstrcatW( LPWSTR dst
, LPCWSTR src
)
82 SetLastError( ERROR_INVALID_PARAMETER
);
90 /***********************************************************************
91 * lstrcatn (KERNEL.352)
93 SEGPTR WINAPI
lstrcatn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
99 if ((n
-= (p
- start
)) <= 0) return dst
;
100 lstrcpynA( p
, src
, n
);
105 /***********************************************************************
106 * lstrcmp (KERNEL32.@)
107 * lstrcmpA (KERNEL32.@)
109 INT WINAPI
lstrcmpA( LPCSTR str1
, LPCSTR str2
)
111 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,0,str1
,-1,str2
,-1) - 2 ;
115 /***********************************************************************
116 * lstrcmpW (KERNEL32.@)
117 * FIXME : should call CompareStringW, when it is implemented.
118 * This implementation is not "word sort", as it should.
120 INT WINAPI
lstrcmpW( LPCWSTR str1
, LPCWSTR str2
)
123 debugstr_w (str1
), debugstr_w (str2
));
124 if (!str1
|| !str2
) {
125 SetLastError(ERROR_INVALID_PARAMETER
);
128 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
129 return (INT
)(*str1
- *str2
);
133 /***********************************************************************
134 * lstrcmpi (KERNEL32.@)
135 * lstrcmpiA (KERNEL32.@)
137 INT WINAPI
lstrcmpiA( LPCSTR str1
, LPCSTR str2
)
138 { TRACE("strcmpi %s and %s\n",
139 debugstr_a (str1
), debugstr_a (str2
));
140 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,NORM_IGNORECASE
,str1
,-1,str2
,-1)-2;
144 /***********************************************************************
145 * lstrcmpiW (KERNEL32.@)
147 INT WINAPI
lstrcmpiW( LPCWSTR str1
, LPCWSTR str2
)
149 if (!str1
|| !str2
) {
150 SetLastError(ERROR_INVALID_PARAMETER
);
153 return strcmpiW( str1
, str2
);
157 /***********************************************************************
158 * lstrcpy (KERNEL.88)
160 SEGPTR WINAPI
lstrcpy16( SEGPTR dst
, LPCSTR src
)
162 if (!lstrcpyA( MapSL(dst
), src
)) dst
= 0;
167 /***********************************************************************
168 * lstrcpy (KERNEL32.@)
169 * lstrcpyA (KERNEL32.@)
171 LPSTR WINAPI
lstrcpyA( LPSTR dst
, LPCSTR src
)
175 /* this is how Windows does it */
176 memmove( dst
, src
, strlen(src
)+1 );
180 ERR("(%p, %p): page fault occurred ! Caused by bug ?\n", dst
, src
);
181 SetLastError( ERROR_INVALID_PARAMETER
);
189 /***********************************************************************
190 * lstrcpyW (KERNEL32.@)
192 LPWSTR WINAPI
lstrcpyW( LPWSTR dst
, LPCWSTR src
)
200 SetLastError( ERROR_INVALID_PARAMETER
);
208 /***********************************************************************
209 * lstrcpyn (KERNEL.353)
211 SEGPTR WINAPI
lstrcpyn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
213 lstrcpynA( MapSL(dst
), src
, n
);
218 /***********************************************************************
219 * lstrcpyn (KERNEL32.@)
220 * lstrcpynA (KERNEL32.@)
222 * Note: this function differs from the UNIX strncpy, it _always_ writes
225 LPSTR WINAPI
lstrcpynA( LPSTR dst
, LPCSTR src
, INT n
)
228 TRACE("(%p, %s, %i)\n", dst
, debugstr_an(src
,n
), n
);
229 /* In real windows the whole function is protected by an exception handler
230 * that returns ERROR_INVALID_PARAMETER on faulty parameters
231 * We currently just check for NULL.
234 SetLastError(ERROR_INVALID_PARAMETER
);
237 while ((n
-- > 1) && *src
) *p
++ = *src
++;
243 /***********************************************************************
244 * lstrcpynW (KERNEL32.@)
245 * Note: this function differs from the UNIX strncpy, it _always_ writes
248 LPWSTR WINAPI
lstrcpynW( LPWSTR dst
, LPCWSTR src
, INT n
)
251 TRACE("(%p, %s, %i)\n", dst
, debugstr_wn(src
,n
), n
);
252 /* In real windows the whole function is protected by an exception handler
253 * that returns ERROR_INVALID_PARAMETER on faulty parameters
254 * We currently just check for NULL.
257 SetLastError(ERROR_INVALID_PARAMETER
);
260 while ((n
-- > 1) && *src
) *p
++ = *src
++;
266 /***********************************************************************
267 * lstrlen (KERNEL.90)
269 INT16 WINAPI
lstrlen16( LPCSTR str
)
271 return (INT16
)lstrlenA( str
);
275 /***********************************************************************
276 * lstrlen (KERNEL32.@)
277 * lstrlenA (KERNEL32.@)
279 INT WINAPI
lstrlenA( LPCSTR str
)
288 SetLastError( ERROR_INVALID_PARAMETER
);
296 /***********************************************************************
297 * lstrlenW (KERNEL32.@)
299 INT WINAPI
lstrlenW( LPCWSTR str
)
308 SetLastError( ERROR_INVALID_PARAMETER
);
316 /***********************************************************************
317 * UnicodeToAnsi (KERNEL.434)
319 INT16 WINAPI
UnicodeToAnsi16( LPCWSTR src
, LPSTR dst
, INT16 codepage
)
321 if ( codepage
== -1 )
324 return WideCharToMultiByte( codepage
, 0, src
, -1, dst
, 0x7fffffff, NULL
, NULL
);