4 * Copyright 1993 Yngvi Sigurjonsson
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/winbase16.h"
30 #include "wine/exception.h"
31 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(string
);
39 /* filter for page-fault exceptions */
40 static WINE_EXCEPTION_FILTER(page_fault
)
42 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
43 return EXCEPTION_EXECUTE_HANDLER
;
44 return EXCEPTION_CONTINUE_SEARCH
;
48 /***********************************************************************
49 * hmemcpy (KERNEL.348)
51 void WINAPI
hmemcpy16( LPVOID dst
, LPCVOID src
, LONG count
)
53 memcpy( dst
, src
, count
);
57 /***********************************************************************
60 SEGPTR WINAPI
lstrcat16( SEGPTR dst
, LPCSTR src
)
62 /* Windows does not check for NULL pointers here, so we don't either */
63 strcat( MapSL(dst
), src
);
68 /***********************************************************************
69 * lstrcat (KERNEL32.@)
70 * lstrcatA (KERNEL32.@)
72 LPSTR WINAPI
lstrcatA( LPSTR dst
, LPCSTR src
)
80 SetLastError( ERROR_INVALID_PARAMETER
);
88 /***********************************************************************
89 * lstrcatW (KERNEL32.@)
91 LPWSTR WINAPI
lstrcatW( LPWSTR dst
, LPCWSTR src
)
99 SetLastError( ERROR_INVALID_PARAMETER
);
107 /***********************************************************************
108 * lstrcatn (KERNEL.352)
110 SEGPTR WINAPI
lstrcatn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
112 LPSTR p
= MapSL(dst
);
116 if ((n
-= (p
- start
)) <= 0) return dst
;
117 lstrcpynA( p
, src
, n
);
122 /***********************************************************************
123 * lstrcpy (KERNEL.88)
125 SEGPTR WINAPI
lstrcpy16( SEGPTR dst
, LPCSTR src
)
127 if (!lstrcpyA( MapSL(dst
), src
)) dst
= 0;
132 /***********************************************************************
133 * lstrcpy (KERNEL32.@)
134 * lstrcpyA (KERNEL32.@)
136 LPSTR WINAPI
lstrcpyA( LPSTR dst
, LPCSTR src
)
140 /* this is how Windows does it */
141 memmove( dst
, src
, strlen(src
)+1 );
145 ERR("(%p, %p): page fault occurred ! Caused by bug ?\n", dst
, src
);
146 SetLastError( ERROR_INVALID_PARAMETER
);
154 /***********************************************************************
155 * lstrcpyW (KERNEL32.@)
157 LPWSTR WINAPI
lstrcpyW( LPWSTR dst
, LPCWSTR src
)
165 SetLastError( ERROR_INVALID_PARAMETER
);
173 /***********************************************************************
174 * lstrcpyn (KERNEL.353)
176 SEGPTR WINAPI
lstrcpyn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
178 lstrcpynA( MapSL(dst
), src
, n
);
183 /***********************************************************************
184 * lstrcpyn (KERNEL32.@)
185 * lstrcpynA (KERNEL32.@)
187 * Note: this function differs from the UNIX strncpy, it _always_ writes
190 * Note: n is an INT but Windows treats it as unsigned, and will happily
191 * copy a gazillion chars if n is negative.
193 LPSTR WINAPI
lstrcpynA( LPSTR dst
, LPCSTR src
, INT n
)
198 TRACE("(%p, %s, %i)\n", dst
, debugstr_a(src
), n
);
200 /* In real windows the whole function is protected by an exception handler
201 * that returns ERROR_INVALID_PARAMETER on faulty parameters
202 * We currently just check for NULL.
205 SetLastError(ERROR_INVALID_PARAMETER
);
208 while ((count
> 1) && *src
)
218 /***********************************************************************
219 * lstrcpynW (KERNEL32.@)
221 * Note: this function differs from the UNIX strncpy, it _always_ writes
224 * Note: n is an INT but Windows treats it as unsigned, and will happily
225 * copy a gazillion chars if n is negative.
227 LPWSTR WINAPI
lstrcpynW( LPWSTR dst
, LPCWSTR src
, INT n
)
232 TRACE("(%p, %s, %i)\n", dst
, debugstr_w(src
), n
);
234 /* In real windows the whole function is protected by an exception handler
235 * that returns ERROR_INVALID_PARAMETER on faulty parameters
236 * We currently just check for NULL.
239 SetLastError(ERROR_INVALID_PARAMETER
);
242 while ((count
> 1) && *src
)
252 /***********************************************************************
253 * lstrlen (KERNEL.90)
255 INT16 WINAPI
lstrlen16( LPCSTR str
)
257 return (INT16
)lstrlenA( str
);
261 /***********************************************************************
262 * lstrlen (KERNEL32.@)
263 * lstrlenA (KERNEL32.@)
265 INT WINAPI
lstrlenA( LPCSTR str
)
274 SetLastError( ERROR_INVALID_PARAMETER
);
282 /***********************************************************************
283 * lstrlenW (KERNEL32.@)
285 INT WINAPI
lstrlenW( LPCWSTR str
)
294 SetLastError( ERROR_INVALID_PARAMETER
);
302 /***********************************************************************
303 * UnicodeToAnsi (KERNEL.434)
305 INT16 WINAPI
UnicodeToAnsi16( LPCWSTR src
, LPSTR dst
, INT16 codepage
)
307 if ( codepage
== -1 )
310 return WideCharToMultiByte( codepage
, 0, src
, -1, dst
, 0x7fffffff, NULL
, NULL
);