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);
128 /*********************************************************************
131 int CDECL
MSVCRT_fscanf(MSVCRT_FILE
*file
, const char *format
, ...)
136 __ms_va_start(valist
, format
);
137 res
= MSVCRT_vfscanf_l(file
, format
, NULL
, valist
);
142 /*********************************************************************
143 * _fscanf_l (MSVCRT.@)
145 int CDECL
MSVCRT__fscanf_l(MSVCRT_FILE
*file
, const char *format
,
146 MSVCRT__locale_t locale
, ...)
151 __ms_va_start(valist
, locale
);
152 res
= MSVCRT_vfscanf_l(file
, format
, locale
, valist
);
157 /*********************************************************************
158 * fscanf_s (MSVCRT.@)
160 int CDECL
MSVCRT_fscanf_s(MSVCRT_FILE
*file
, const char *format
, ...)
165 __ms_va_start(valist
, format
);
166 res
= MSVCRT_vfscanf_s_l(file
, format
, NULL
, valist
);
171 /*********************************************************************
172 * _fscanf_s_l (MSVCRT.@)
174 int CDECL
MSVCRT__fscanf_s_l(MSVCRT_FILE
*file
, const char *format
,
175 MSVCRT__locale_t locale
, ...)
180 __ms_va_start(valist
, locale
);
181 res
= MSVCRT_vfscanf_s_l(file
, format
, locale
, valist
);
186 /*********************************************************************
189 int CDECL
MSVCRT_scanf(const char *format
, ...)
194 __ms_va_start(valist
, format
);
195 res
= MSVCRT_vfscanf_l(MSVCRT_stdin
, format
, NULL
, valist
);
200 /*********************************************************************
201 * _scanf_l (MSVCRT.@)
203 int CDECL
MSVCRT__scanf_l(const char *format
, MSVCRT__locale_t locale
, ...)
208 __ms_va_start(valist
, locale
);
209 res
= MSVCRT_vfscanf_l(MSVCRT_stdin
, format
, locale
, valist
);
214 /*********************************************************************
217 int CDECL
MSVCRT_scanf_s(const char *format
, ...)
222 __ms_va_start(valist
, format
);
223 res
= MSVCRT_vfscanf_s_l(MSVCRT_stdin
, format
, NULL
, valist
);
228 /*********************************************************************
229 * _scanf_s_l (MSVCRT.@)
231 int CDECL
MSVCRT__scanf_s_l(const char *format
, MSVCRT__locale_t locale
, ...)
236 __ms_va_start(valist
, locale
);
237 res
= MSVCRT_vfscanf_s_l(MSVCRT_stdin
, format
, locale
, valist
);
242 /*********************************************************************
245 int CDECL
MSVCRT_fwscanf(MSVCRT_FILE
*file
, const MSVCRT_wchar_t
*format
, ...)
250 __ms_va_start(valist
, format
);
251 res
= MSVCRT_vfwscanf_l(file
, format
, NULL
, valist
);
256 /*********************************************************************
257 * _fwscanf_l (MSVCRT.@)
259 int CDECL
MSVCRT__fwscanf_l(MSVCRT_FILE
*file
, const MSVCRT_wchar_t
*format
,
260 MSVCRT__locale_t locale
, ...)
265 __ms_va_start(valist
, locale
);
266 res
= MSVCRT_vfwscanf_l(file
, format
, locale
, valist
);
271 /*********************************************************************
272 * fwscanf_s (MSVCRT.@)
274 int CDECL
MSVCRT_fwscanf_s(MSVCRT_FILE
*file
, const MSVCRT_wchar_t
*format
, ...)
279 __ms_va_start(valist
, format
);
280 res
= MSVCRT_vfwscanf_s_l(file
, format
, NULL
, valist
);
285 /*********************************************************************
286 * _fwscanf_s_l (MSVCRT.@)
288 int CDECL
MSVCRT__fwscanf_s_l(MSVCRT_FILE
*file
, const MSVCRT_wchar_t
*format
,
289 MSVCRT__locale_t locale
, ...)
294 __ms_va_start(valist
, locale
);
295 res
= MSVCRT_vfwscanf_s_l(file
, format
, locale
, valist
);
300 /*********************************************************************
303 int CDECL
MSVCRT_wscanf(const MSVCRT_wchar_t
*format
, ...)
308 __ms_va_start(valist
, format
);
309 res
= MSVCRT_vfwscanf_l(MSVCRT_stdin
, format
, NULL
, valist
);
314 /*********************************************************************
315 * _wscanf_l (MSVCRT.@)
317 int CDECL
MSVCRT__wscanf_l(const MSVCRT_wchar_t
*format
,
318 MSVCRT__locale_t locale
, ...)
323 __ms_va_start(valist
, locale
);
324 res
= MSVCRT_vfwscanf_l(MSVCRT_stdin
, format
, locale
, valist
);
329 /*********************************************************************
330 * wscanf_s (MSVCRT.@)
332 int CDECL
MSVCRT_wscanf_s(const MSVCRT_wchar_t
*format
, ...)
337 __ms_va_start(valist
, format
);
338 res
= MSVCRT_vfwscanf_s_l(MSVCRT_stdin
, format
, NULL
, valist
);
343 /*********************************************************************
344 * _wscanf_s_l (MSVCRT.@)
346 int CDECL
MSVCRT__wscanf_s_l(const MSVCRT_wchar_t
*format
,
347 MSVCRT__locale_t locale
, ...)
352 __ms_va_start(valist
, locale
);
353 res
= MSVCRT_vfwscanf_s_l(MSVCRT_stdin
, format
, locale
, valist
);
358 /*********************************************************************
361 int CDECL
MSVCRT_sscanf(const char *str
, const char *format
, ...)
366 __ms_va_start(valist
, format
);
367 res
= MSVCRT_vsscanf_l(str
, format
, NULL
, valist
);
372 /*********************************************************************
373 * _sscanf_l (MSVCRT.@)
375 int CDECL
MSVCRT__sscanf_l(const char *str
, const char *format
,
376 MSVCRT__locale_t locale
, ...)
381 __ms_va_start(valist
, locale
);
382 res
= MSVCRT_vsscanf_l(str
, format
, locale
, valist
);
387 /*********************************************************************
388 * sscanf_s (MSVCRT.@)
390 int CDECL
MSVCRT_sscanf_s(const char *str
, const char *format
, ...)
395 __ms_va_start(valist
, format
);
396 res
= MSVCRT_vsscanf_s_l(str
, format
, NULL
, valist
);
401 /*********************************************************************
402 * _sscanf_s_l (MSVCRT.@)
404 int CDECL
MSVCRT__sscanf_s_l(const char *str
, const char *format
,
405 MSVCRT__locale_t locale
, ...)
410 __ms_va_start(valist
, locale
);
411 res
= MSVCRT_vsscanf_s_l(str
, format
, locale
, valist
);
416 /*********************************************************************
419 int CDECL
MSVCRT_swscanf(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ...)
424 __ms_va_start(valist
, format
);
425 res
= MSVCRT_vswscanf_l(str
, format
, NULL
, valist
);
430 /*********************************************************************
431 * _swscanf_l (MSVCRT.@)
433 int CDECL
MSVCRT__swscanf_l(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
434 MSVCRT__locale_t locale
, ...)
439 __ms_va_start(valist
, locale
);
440 res
= MSVCRT_vswscanf_l(str
, format
, locale
, valist
);
445 /*********************************************************************
446 * swscanf_s (MSVCRT.@)
448 int CDECL
MSVCRT_swscanf_s(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ...)
453 __ms_va_start(valist
, format
);
454 res
= MSVCRT_vswscanf_s_l(str
, format
, NULL
, valist
);
459 /*********************************************************************
460 * _swscanf_s_l (MSVCRT.@)
462 int CDECL
MSVCRT__swscanf_s_l(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
463 MSVCRT__locale_t locale
, ...)
468 __ms_va_start(valist
, locale
);
469 res
= MSVCRT_vswscanf_s_l(str
, format
, locale
, valist
);
474 /*********************************************************************
477 int CDECL
_cscanf(const char *format
, ...)
482 __ms_va_start(valist
, format
);
483 res
= MSVCRT_vcscanf_l(format
, NULL
, valist
);
488 /*********************************************************************
489 * _cscanf_l (MSVCRT.@)
491 int CDECL
_cscanf_l(const char *format
, MSVCRT__locale_t locale
, ...)
496 __ms_va_start(valist
, locale
);
497 res
= MSVCRT_vcscanf_l(format
, locale
, valist
);
502 /*********************************************************************
503 * _cscanf_s (MSVCRT.@)
505 int CDECL
_cscanf_s(const char *format
, ...)
510 __ms_va_start(valist
, format
);
511 res
= MSVCRT_vcscanf_s_l(format
, NULL
, valist
);
516 /*********************************************************************
517 * _cscanf_s_l (MSVCRT.@)
519 int CDECL
_cscanf_s_l(const char *format
, MSVCRT__locale_t locale
, ...)
524 __ms_va_start(valist
, locale
);
525 res
= MSVCRT_vcscanf_s_l(format
, locale
, valist
);
530 /*********************************************************************
531 * _cwscanf (MSVCRT.@)
533 int CDECL
_cwscanf(const char *format
, ...)
538 __ms_va_start(valist
, format
);
539 res
= MSVCRT_vcwscanf_l(format
, NULL
, valist
);
544 /*********************************************************************
545 * _cwscanf_l (MSVCRT.@)
547 int CDECL
_cwscanf_l(const char *format
, MSVCRT__locale_t locale
, ...)
552 __ms_va_start(valist
, locale
);
553 res
= MSVCRT_vcwscanf_l(format
, locale
, valist
);
558 /*********************************************************************
559 * _cwscanf_s (MSVCRT.@)
561 int CDECL
_cwscanf_s(const char *format
, ...)
566 __ms_va_start(valist
, format
);
567 res
= MSVCRT_vcwscanf_s_l(format
, NULL
, valist
);
572 /*********************************************************************
573 * _cwscanf_s_l (MSVCRT.@)
575 int CDECL
_cwscanf_s_l(const char *format
, MSVCRT__locale_t locale
, ...)
580 __ms_va_start(valist
, locale
);
581 res
= MSVCRT_vcwscanf_s_l(format
, locale
, valist
);