2 * general implementation of scanf used by scanf, sscanf, fscanf,
3 * _cscanf, wscanf, swscanf and fwscanf
5 * Copyright 1996,1998 Marcus Meissner
6 * Copyright 1996 Jukka Iivonen
7 * Copyright 1997,2000 Uwe Bonnes
8 * Copyright 2000 Jon Griffiths
9 * Copyright 2002 Daniel Gudbjartsson
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
37 extern MSVCRT_FILE MSVCRT__iob[];
39 /* helper function for *scanf. Returns the value of character c in the
40 * given base, or -1 if the given character is not a digit of the base.
42 static int char2digit(char c, int base) {
43 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
44 if (base<=10) return -1;
45 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
46 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
50 /* helper function for *wscanf. Returns the value of character c in the
51 * given base, or -1 if the given character is not a digit of the base.
53 static int wchar2digit(MSVCRT_wchar_t c, int base) {
54 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
55 if (base<=10) return -1;
56 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
57 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
147 /*********************************************************************
150 int CDECL MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
155 __ms_va_start(valist, format);
156 res = MSVCRT_vfscanf_l(file, format, NULL, valist);
161 /*********************************************************************
162 * _fscanf_l (MSVCRT.@)
164 int CDECL MSVCRT__fscanf_l(MSVCRT_FILE *file, const char *format,
165 MSVCRT__locale_t locale, ...)
170 __ms_va_start(valist, locale);
171 res = MSVCRT_vfscanf_l(file, format, locale, valist);
176 /*********************************************************************
177 * fscanf_s (MSVCRT.@)
179 int CDECL MSVCRT_fscanf_s(MSVCRT_FILE *file, const char *format, ...)
184 __ms_va_start(valist, format);
185 res = MSVCRT_vfscanf_s_l(file, format, NULL, valist);
190 /*********************************************************************
191 * _fscanf_s_l (MSVCRT.@)
193 int CDECL MSVCRT__fscanf_s_l(MSVCRT_FILE *file, const char *format,
194 MSVCRT__locale_t locale, ...)
199 __ms_va_start(valist, locale);
200 res = MSVCRT_vfscanf_s_l(file, format, locale, valist);
205 /*********************************************************************
208 int CDECL MSVCRT_scanf(const char *format, ...)
213 __ms_va_start(valist, format);
214 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, NULL, valist);
219 /*********************************************************************
220 * _scanf_l (MSVCRT.@)
222 int CDECL MSVCRT__scanf_l(const char *format, MSVCRT__locale_t locale, ...)
227 __ms_va_start(valist, locale);
228 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, locale, valist);
233 /*********************************************************************
236 int CDECL MSVCRT_scanf_s(const char *format, ...)
241 __ms_va_start(valist, format);
242 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, NULL, valist);
247 /*********************************************************************
248 * _scanf_s_l (MSVCRT.@)
250 int CDECL MSVCRT__scanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
255 __ms_va_start(valist, locale);
256 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, locale, valist);
261 /*********************************************************************
264 int CDECL MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
269 __ms_va_start(valist, format);
270 res = MSVCRT_vfwscanf_l(file, format, NULL, valist);
275 /*********************************************************************
276 * _fwscanf_l (MSVCRT.@)
278 int CDECL MSVCRT__fwscanf_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
279 MSVCRT__locale_t locale, ...)
284 __ms_va_start(valist, locale);
285 res = MSVCRT_vfwscanf_l(file, format, locale, valist);
290 /*********************************************************************
291 * fwscanf_s (MSVCRT.@)
293 int CDECL MSVCRT_fwscanf_s(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
298 __ms_va_start(valist, format);
299 res = MSVCRT_vfwscanf_s_l(file, format, NULL, valist);
304 /*********************************************************************
305 * _fwscanf_s_l (MSVCRT.@)
307 int CDECL MSVCRT__fwscanf_s_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
308 MSVCRT__locale_t locale, ...)
313 __ms_va_start(valist, locale);
314 res = MSVCRT_vfwscanf_s_l(file, format, locale, valist);
319 /*********************************************************************
322 int CDECL MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
327 __ms_va_start(valist, format);
328 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, NULL, valist);
333 /*********************************************************************
334 * _wscanf_l (MSVCRT.@)
336 int CDECL MSVCRT__wscanf_l(const MSVCRT_wchar_t *format,
337 MSVCRT__locale_t locale, ...)
342 __ms_va_start(valist, locale);
343 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, locale, valist);
348 /*********************************************************************
349 * wscanf_s (MSVCRT.@)
351 int CDECL MSVCRT_wscanf_s(const MSVCRT_wchar_t *format, ...)
356 __ms_va_start(valist, format);
357 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, NULL, valist);
362 /*********************************************************************
363 * _wscanf_s_l (MSVCRT.@)
365 int CDECL MSVCRT__wscanf_s_l(const MSVCRT_wchar_t *format,
366 MSVCRT__locale_t locale, ...)
371 __ms_va_start(valist, locale);
372 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, locale, valist);
377 /*********************************************************************
380 int CDECL MSVCRT_sscanf(const char *str, const char *format, ...)
385 __ms_va_start(valist, format);
386 res = MSVCRT_vsscanf_l(str, format, NULL, valist);
391 /*********************************************************************
392 * _sscanf_l (MSVCRT.@)
394 int CDECL MSVCRT__sscanf_l(const char *str, const char *format,
395 MSVCRT__locale_t locale, ...)
400 __ms_va_start(valist, locale);
401 res = MSVCRT_vsscanf_l(str, format, locale, valist);
406 /*********************************************************************
407 * sscanf_s (MSVCRT.@)
409 int CDECL MSVCRT_sscanf_s(const char *str, const char *format, ...)
414 __ms_va_start(valist, format);
415 res = MSVCRT_vsscanf_s_l(str, format, NULL, valist);
420 /*********************************************************************
421 * _sscanf_s_l (MSVCRT.@)
423 int CDECL MSVCRT__sscanf_s_l(const char *str, const char *format,
424 MSVCRT__locale_t locale, ...)
429 __ms_va_start(valist, locale);
430 res = MSVCRT_vsscanf_s_l(str, format, locale, valist);
435 /*********************************************************************
438 int CDECL MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
443 __ms_va_start(valist, format);
444 res = MSVCRT_vswscanf_l(str, format, NULL, valist);
449 /*********************************************************************
450 * _swscanf_l (MSVCRT.@)
452 int CDECL MSVCRT__swscanf_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
453 MSVCRT__locale_t locale, ...)
458 __ms_va_start(valist, locale);
459 res = MSVCRT_vswscanf_l(str, format, locale, valist);
464 /*********************************************************************
465 * swscanf_s (MSVCRT.@)
467 int CDECL MSVCRT_swscanf_s(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
472 __ms_va_start(valist, format);
473 res = MSVCRT_vswscanf_s_l(str, format, NULL, valist);
478 /*********************************************************************
479 * _swscanf_s_l (MSVCRT.@)
481 int CDECL MSVCRT__swscanf_s_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
482 MSVCRT__locale_t locale, ...)
487 __ms_va_start(valist, locale);
488 res = MSVCRT_vswscanf_s_l(str, format, locale, valist);
493 /*********************************************************************
496 int CDECL _cscanf(const char *format, ...)
501 __ms_va_start(valist, format);
502 res = MSVCRT_vcscanf_l(format, NULL, valist);
507 /*********************************************************************
508 * _cscanf_l (MSVCRT.@)
510 int CDECL _cscanf_l(const char *format, MSVCRT__locale_t locale, ...)
515 __ms_va_start(valist, locale);
516 res = MSVCRT_vcscanf_l(format, locale, valist);
521 /*********************************************************************
522 * _cscanf_s (MSVCRT.@)
524 int CDECL _cscanf_s(const char *format, ...)
529 __ms_va_start(valist, format);
530 res = MSVCRT_vcscanf_s_l(format, NULL, valist);
535 /*********************************************************************
536 * _cscanf_s_l (MSVCRT.@)
538 int CDECL _cscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
543 __ms_va_start(valist, locale);
544 res = MSVCRT_vcscanf_s_l(format, locale, valist);
549 /*********************************************************************
550 * _cwscanf (MSVCRT.@)
552 int CDECL _cwscanf(const char *format, ...)
557 __ms_va_start(valist, format);
558 res = MSVCRT_vcwscanf_l(format, NULL, valist);
563 /*********************************************************************
564 * _cwscanf_l (MSVCRT.@)
566 int CDECL _cwscanf_l(const char *format, MSVCRT__locale_t locale, ...)
571 __ms_va_start(valist, locale);
572 res = MSVCRT_vcwscanf_l(format, locale, valist);
577 /*********************************************************************
578 * _cwscanf_s (MSVCRT.@)
580 int CDECL _cwscanf_s(const char *format, ...)
585 __ms_va_start(valist, format);
586 res = MSVCRT_vcwscanf_s_l(format, NULL, valist);
591 /*********************************************************************
592 * _cwscanf_s_l (MSVCRT.@)
594 int CDECL _cwscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
599 __ms_va_start(valist, locale);
600 res = MSVCRT_vcwscanf_s_l(format, locale, valist);
605 /*********************************************************************
606 * _snscanf (MSVCRT.@)
608 int CDECL MSVCRT__snscanf(char *input, MSVCRT_size_t length, const char *format, ...)
613 __ms_va_start(valist, format);
614 res = MSVCRT_vsnscanf_l(input, length, format, NULL, valist);
619 /*********************************************************************
620 * _snscanf_l (MSVCRT.@)
622 int CDECL MSVCRT__snscanf_l(char *input, MSVCRT_size_t length,
623 const char *format, MSVCRT__locale_t locale, ...)
628 __ms_va_start(valist, locale);
629 res = MSVCRT_vsnscanf_l(input, length, format, locale, valist);
634 /*********************************************************************
635 * _snscanf_s (MSVCRT.@)
637 int CDECL MSVCRT__snscanf_s(char *input, MSVCRT_size_t length, const char *format, ...)
642 __ms_va_start(valist, format);
643 res = MSVCRT_vsnscanf_s_l(input, length, format, NULL, valist);
648 /*********************************************************************
649 * _snscanf_s_l (MSVCRT.@)
651 int CDECL MSVCRT__snscanf_s_l(char *input, MSVCRT_size_t length,
652 const char *format, MSVCRT__locale_t locale, ...)
657 __ms_va_start(valist, locale);
658 res = MSVCRT_vsnscanf_s_l(input, length, format, locale, valist);
663 /*********************************************************************
664 * _snwscanf (MSVCRT.@)
666 int CDECL MSVCRT__snwscanf(MSVCRT_wchar_t *input, MSVCRT_size_t length,
667 const MSVCRT_wchar_t *format, ...)
672 __ms_va_start(valist, format);
673 res = MSVCRT_vsnwscanf_l(input, length, format, NULL, valist);
678 /*********************************************************************
679 * _snwscanf_l (MSVCRT.@)
681 int CDECL MSVCRT__snwscanf_l(MSVCRT_wchar_t *input, MSVCRT_size_t length,
682 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
687 __ms_va_start(valist, locale);
688 res = MSVCRT_vsnwscanf_l(input, length, format, locale, valist);
693 /*********************************************************************
694 * _snwscanf_s (MSVCRT.@)
696 int CDECL MSVCRT__snwscanf_s(MSVCRT_wchar_t *input, MSVCRT_size_t length,
697 const MSVCRT_wchar_t *format, ...)
702 __ms_va_start(valist, format);
703 res = MSVCRT_vsnwscanf_s_l(input, length, format, NULL, valist);
708 /*********************************************************************
709 * _snscanf_s_l (MSVCRT.@)
711 int CDECL MSVCRT__snwscanf_s_l(MSVCRT_wchar_t *input, MSVCRT_size_t length,
712 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
717 __ms_va_start(valist, locale);
718 res = MSVCRT_vsnwscanf_s_l(input, length, format, locale, valist);