Changeset 8429 for trunk/src/NTDLL/wcstring.c
- Timestamp:
- May 16, 2002, 2:22:14 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/NTDLL/wcstring.c
r7343 r8429 4 4 * Copyright 2000 Alexandre Julliard 5 5 * Copyright 2000 Jon Griffiths 6 * 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. 11 * 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. 16 * 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 6 20 */ 7 21 … … 14 28 #include <stdio.h> 15 29 16 #ifdef __WIN32OS2__ 17 #include <stdarg.h> 18 #include <heapstring.h> 19 #endif 20 21 #include "windef.h" 22 #include "winbase.h" 23 #include "winnls.h" 30 #include "ntddk.h" 24 31 #include "wine/unicode.h" 25 #include "heap.h" 26 #include "debugtools.h" 27 28 DEFAULT_DEBUG_CHANNEL(ntdll); 32 #include "wine/debug.h" 33 34 WINE_DEFAULT_DEBUG_CHANNEL(ntdll); 29 35 30 36 … … 258 264 INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n ) 259 265 { 260 INT ret; 261 if (n <= 0) return 0; 262 ret = WideCharToMultiByte( CP_ACP, 0, src, -1, dst, dst ? n : 0, NULL, NULL ); 263 if (!ret) return n; /* overflow */ 264 return ret - 1; /* do not count terminating NULL */ 266 DWORD len; 267 268 if (!dst) 269 { 270 RtlUnicodeToMultiByteSize( &len, src, strlenW(src)*sizeof(WCHAR) ); 271 return len; 272 } 273 else 274 { 275 if (n <= 0) return 0; 276 RtlUnicodeToMultiByteN( dst, n, &len, src, strlenW(src)*sizeof(WCHAR) ); 277 if (len < n) dst[len] = 0; 278 } 279 return len; 265 280 } 266 281 … … 271 286 INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n ) 272 287 { 273 INT ret; 274 if (n <= 0) return 0; 275 ret = MultiByteToWideChar( CP_ACP, 0, src, -1, dst, dst ? n : 0 ); 276 if (!ret) return n; /* overflow */ 277 return ret - 1; /* do not count terminating NULL */ 288 DWORD len; 289 290 if (!dst) 291 { 292 RtlMultiByteToUnicodeSize( &len, src, strlen(src) ); 293 } 294 else 295 { 296 if (n <= 0) return 0; 297 RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) ); 298 if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0; 299 } 300 return len / sizeof(WCHAR); 278 301 } 279 302 … … 283 306 * Like strtol, but for wide character strings. 284 307 */ 285 INT __cdecl NTDLL_wcstol(LPWSTR s,LPWSTR *end,INT base) 286 { 287 LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA; 288 INT ret = strtol(sA,&endA,base); 289 290 HeapFree(GetProcessHeap(),0,sA); 291 if (end) *end = s+(endA-sA); /* pointer magic checked. */ 308 INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base) 309 { 310 UNICODE_STRING uni; 311 ANSI_STRING ansi; 312 INT ret; 313 LPSTR endA; 314 315 RtlInitUnicodeString( &uni, s ); 316 RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE ); 317 ret = strtol( ansi.Buffer, &endA, base ); 318 if (end) 319 { 320 DWORD len; 321 RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer ); 322 *end = (LPWSTR)s + len/sizeof(WCHAR); 323 } 324 RtlFreeAnsiString( &ansi ); 325 return ret; 326 } 327 328 329 /********************************************************************* 330 * wcstoul (NTDLL.@) 331 * Like strtoul, but for wide character strings. 332 */ 333 INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base) 334 { 335 UNICODE_STRING uni; 336 ANSI_STRING ansi; 337 INT ret; 338 LPSTR endA; 339 340 RtlInitUnicodeString( &uni, s ); 341 RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE ); 342 ret = strtoul( ansi.Buffer, &endA, base ); 343 if (end) 344 { 345 DWORD len; 346 RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer ); 347 *end = (LPWSTR)s + len/sizeof(WCHAR); 348 } 349 RtlFreeAnsiString( &ansi ); 292 350 return ret; 293 351 }
Note:
See TracChangeset
for help on using the changeset viewer.