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 * hmemcpy16 (KERNEL.348)
34 void WINAPI
hmemcpy16( LPVOID dst
, LPCVOID src
, LONG count
)
36 memcpy( dst
, src
, count
);
40 /***********************************************************************
41 * lstrcat16 (KERNEL.89)
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 * lstrcatA (KERNEL32.599)
54 LPSTR WINAPI
lstrcatA( LPSTR dst
, LPCSTR src
)
62 SetLastError( ERROR_INVALID_PARAMETER
);
70 /***********************************************************************
71 * lstrcatW (KERNEL32.600)
73 LPWSTR WINAPI
lstrcatW( LPWSTR dst
, LPCWSTR src
)
81 SetLastError( ERROR_INVALID_PARAMETER
);
89 /***********************************************************************
90 * lstrcatn16 (KERNEL.352)
92 SEGPTR WINAPI
lstrcatn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
98 if ((n
-= (p
- start
)) <= 0) return dst
;
99 lstrcpynA( p
, src
, n
);
104 /***********************************************************************
105 * lstrcmpA (KERNEL.602)
107 INT WINAPI
lstrcmpA( LPCSTR str1
, LPCSTR str2
)
109 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,0,str1
,-1,str2
,-1) - 2 ;
113 /***********************************************************************
114 * lstrcmpW (KERNEL.603)
115 * FIXME : should call CompareStringW, when it is implemented.
116 * This implementation is not "word sort", as it should.
118 INT WINAPI
lstrcmpW( LPCWSTR str1
, LPCWSTR str2
)
121 debugstr_w (str1
), debugstr_w (str2
));
122 if (!str1
|| !str2
) {
123 SetLastError(ERROR_INVALID_PARAMETER
);
126 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
127 return (INT
)(*str1
- *str2
);
131 /***********************************************************************
132 * lstrcmpiA (KERNEL32.605)
134 INT WINAPI
lstrcmpiA( LPCSTR str1
, LPCSTR str2
)
135 { TRACE("strcmpi %s and %s\n",
136 debugstr_a (str1
), debugstr_a (str2
));
137 return CompareStringA(LOCALE_SYSTEM_DEFAULT
,NORM_IGNORECASE
,str1
,-1,str2
,-1)-2;
141 /***********************************************************************
142 * lstrcmpiW (KERNEL32.606)
144 INT WINAPI
lstrcmpiW( LPCWSTR str1
, LPCWSTR str2
)
146 if (!str1
|| !str2
) {
147 SetLastError(ERROR_INVALID_PARAMETER
);
150 return strcmpiW( str1
, str2
);
154 /***********************************************************************
155 * lstrcpy16 (KERNEL.88)
157 SEGPTR WINAPI
lstrcpy16( SEGPTR dst
, LPCSTR src
)
159 if (!lstrcpyA( MapSL(dst
), src
)) dst
= 0;
164 /***********************************************************************
165 * lstrcpyA (KERNEL32.608)
167 LPSTR WINAPI
lstrcpyA( LPSTR dst
, LPCSTR src
)
171 /* this is how Windows does it */
172 memmove( dst
, src
, strlen(src
)+1 );
176 ERR("(%p, %p): page fault occurred ! Caused by bug ?\n", dst
, src
);
177 SetLastError( ERROR_INVALID_PARAMETER
);
185 /***********************************************************************
186 * lstrcpyW (KERNEL32.609)
188 LPWSTR WINAPI
lstrcpyW( LPWSTR dst
, LPCWSTR src
)
196 SetLastError( ERROR_INVALID_PARAMETER
);
204 /***********************************************************************
205 * lstrcpyn16 (KERNEL.353)
207 SEGPTR WINAPI
lstrcpyn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
209 lstrcpynA( MapSL(dst
), src
, n
);
214 /***********************************************************************
215 * lstrcpynA (KERNEL32.611)
216 * Note: this function differs from the UNIX strncpy, it _always_ writes
219 LPSTR WINAPI
lstrcpynA( LPSTR dst
, LPCSTR src
, INT n
)
222 TRACE("(%p, %s, %i)\n", dst
, debugstr_an(src
,n
), n
);
223 /* In real windows the whole function is protected by an exception handler
224 * that returns ERROR_INVALID_PARAMETER on faulty parameters
225 * We currently just check for NULL.
228 SetLastError(ERROR_INVALID_PARAMETER
);
231 while ((n
-- > 1) && *src
) *p
++ = *src
++;
237 /***********************************************************************
238 * lstrcpynW (KERNEL32.612)
239 * Note: this function differs from the UNIX strncpy, it _always_ writes
242 LPWSTR WINAPI
lstrcpynW( LPWSTR dst
, LPCWSTR src
, INT n
)
245 TRACE("(%p, %s, %i)\n", dst
, debugstr_wn(src
,n
), n
);
246 /* In real windows the whole function is protected by an exception handler
247 * that returns ERROR_INVALID_PARAMETER on faulty parameters
248 * We currently just check for NULL.
251 SetLastError(ERROR_INVALID_PARAMETER
);
254 while ((n
-- > 1) && *src
) *p
++ = *src
++;
260 /***********************************************************************
261 * lstrlen16 (KERNEL.90)
263 INT16 WINAPI
lstrlen16( LPCSTR str
)
265 return (INT16
)lstrlenA( str
);
269 /***********************************************************************
270 * lstrlenA (KERNEL32.614)
272 INT WINAPI
lstrlenA( LPCSTR str
)
281 SetLastError( ERROR_INVALID_PARAMETER
);
289 /***********************************************************************
290 * lstrlenW (KERNEL32.615)
292 INT WINAPI
lstrlenW( LPCWSTR str
)
301 SetLastError( ERROR_INVALID_PARAMETER
);
309 /***********************************************************************
310 * UnicodeToAnsi (KERNEL.434)
312 INT16 WINAPI
UnicodeToAnsi16( LPCWSTR src
, LPSTR dst
, INT16 codepage
)
314 if ( codepage
== -1 )
317 return WideCharToMultiByte( codepage
, 0, src
, -1, dst
, 0x7fffffff, NULL
, NULL
);