1 /*
2 * general implementation of scanf used by scanf, sscanf, fscanf,
3 * _cscanf, wscanf, swscanf and fwscanf
4 *
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
10 *
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.
15 *
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.
20 *
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
24 */
25
26 #include <stdarg.h>
27 #include <limits.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winternl.h"
32 #include "msvcrt.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36
37 extern MSVCRT_FILE MSVCRT__iob[];
38
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.
41 */
42 static int char2digit(char c, int base) {
43 if ((c>='') && (c<='9') && (c<=''+base-1)) return (c-'');
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);
47 return -1;
48 }
49
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.
52 */
53 static int wchar2digit(MSVCRT_wchar_t c, int base) {
54 if ((c>='') && (c<='9') && (c<=''+base-1)) return (c-'');
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);
58 return -1;
59 }
60
61 /* vfscanf_l */
62 #undef WIDE_SCANF
63 #undef CONSOLE
64 #undef STRING
65 #undef SECURE
66 #include "scanf.h"
67
68 /* vfscanf_l */
69 #define SECURE 1
70 #include "scanf.h"
71
72 /* vfwscanf_l */
73 #define WIDE_SCANF 1
74 #undef CONSOLE
75 #undef STRING
76 #undef SECURE
77 #include "scanf.h"
78
79 /* vfwscanf_s_l */
80 #define SECURE 1
81 #include "scanf.h"
82
83 /* vsscanf_l */
84 #undef WIDE_SCANF
85 #undef CONSOLE
86 #define STRING 1
87 #undef SECURE
88 #include "scanf.h"
89
90 /* vsscanf_s_l */
91 #define SECURE 1
92 #include "scanf.h"
93
94 /* vsnscanf_l */
95 #undef SECURE
96 #define STRING_LEN 1
97 #include "scanf.h"
98
99 /* vsnscanf_s_l */
100 #define SECURE
101 #include "scanf.h"
102
103 /* vsnwscanf_l */
104 #define WIDE_SCANF 1
105 #undef SECURE
106 #include "scanf.h"
107
108 /* vsnwscanf_s_l */
109 #define SECURE 1
110 #include "scanf.h"
111 #undef STRING_LEN
112
113 /* vswscanf_l */
114 #define WIDE_SCANF 1
115 #undef CONSOLE
116 #define STRING 1
117 #undef SECURE
118 #include "scanf.h"
119
120 /* vswscanf_s_l */
121 #define SECURE 1
122 #include "scanf.h"
123
124 /* vcscanf_l */
125 #undef WIDE_SCANF
126 #define CONSOLE 1
127 #undef STRING
128 #undef SECURE
129 #include "scanf.h"
130
131 /* vcscanf_s_l */
132 #define SECURE 1
133 #include "scanf.h"
134
135 /* vcwscanf_l */
136 #define WIDE_SCANF 1
137 #define CONSOLE 1
138 #undef STRING
139 #undef SECURE
140 #include "scanf.h"
141
142 /* vcwscanf_s_l */
143 #define SECURE 1
144 #include "scanf.h"
145
146
147 /*********************************************************************
148 * fscanf (MSVCRT.@)
149 */
150 int CDECL MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
151 {
152 __ms_va_list valist;
153 int res;
154
155 __ms_va_start(valist, format);
156 res = MSVCRT_vfscanf_l(file, format, NULL, valist);
157 __ms_va_end(valist);
158 return res;
159 }
160
161 /*********************************************************************
162 * _fscanf_l (MSVCRT.@)
163 */
164 int CDECL MSVCRT__fscanf_l(MSVCRT_FILE *file, const char *format,
165 MSVCRT__locale_t locale, ...)
166 {
167 __ms_va_list valist;
168 int res;
169
170 __ms_va_start(valist, locale);
171 res = MSVCRT_vfscanf_l(file, format, locale, valist);
172 __ms_va_end(valist);
173 return res;
174 }
175
176 /*********************************************************************
177 * fscanf_s (MSVCRT.@)
178 */
179 int CDECL MSVCRT_fscanf_s(MSVCRT_FILE *file, const char *format, ...)
180 {
181 __ms_va_list valist;
182 int res;
183
184 __ms_va_start(valist, format);
185 res = MSVCRT_vfscanf_s_l(file, format, NULL, valist);
186 __ms_va_end(valist);
187 return res;
188 }
189
190 /*********************************************************************
191 * _fscanf_s_l (MSVCRT.@)
192 */
193 int CDECL MSVCRT__fscanf_s_l(MSVCRT_FILE *file, const char *format,
194 MSVCRT__locale_t locale, ...)
195 {
196 __ms_va_list valist;
197 int res;
198
199 __ms_va_start(valist, locale);
200 res = MSVCRT_vfscanf_s_l(file, format, locale, valist);
201 __ms_va_end(valist);
202 return res;
203 }
204
205 /*********************************************************************
206 * scanf (MSVCRT.@)
207 */
208 int CDECL MSVCRT_scanf(const char *format, ...)
209 {
210 __ms_va_list valist;
211 int res;
212
213 __ms_va_start(valist, format);
214 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, NULL, valist);
215 __ms_va_end(valist);
216 return res;
217 }
218
219 /*********************************************************************
220 * _scanf_l (MSVCRT.@)
221 */
222 int CDECL MSVCRT__scanf_l(const char *format, MSVCRT__locale_t locale, ...)
223 {
224 __ms_va_list valist;
225 int res;
226
227 __ms_va_start(valist, locale);
228 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, locale, valist);
229 __ms_va_end(valist);
230 return res;
231 }
232
233 /*********************************************************************
234 * scanf_s (MSVCRT.@)
235 */
236 int CDECL MSVCRT_scanf_s(const char *format, ...)
237 {
238 __ms_va_list valist;
239 int res;
240
241 __ms_va_start(valist, format);
242 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, NULL, valist);
243 __ms_va_end(valist);
244 return res;
245 }
246
247 /*********************************************************************
248 * _scanf_s_l (MSVCRT.@)
249 */
250 int CDECL MSVCRT__scanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
251 {
252 __ms_va_list valist;
253 int res;
254
255 __ms_va_start(valist, locale);
256 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, locale, valist);
257 __ms_va_end(valist);
258 return res;
259 }
260
261 /*********************************************************************
262 * fwscanf (MSVCRT.@)
263 */
264 int CDECL MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
265 {
266 __ms_va_list valist;
267 int res;
268
269 __ms_va_start(valist, format);
270 res = MSVCRT_vfwscanf_l(file, format, NULL, valist);
271 __ms_va_end(valist);
272 return res;
273 }
274
275 /*********************************************************************
276 * _fwscanf_l (MSVCRT.@)
277 */
278 int CDECL MSVCRT__fwscanf_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
279 MSVCRT__locale_t locale, ...)
280 {
281 __ms_va_list valist;
282 int res;
283
284 __ms_va_start(valist, locale);
285 res = MSVCRT_vfwscanf_l(file, format, locale, valist);
286 __ms_va_end(valist);
287 return res;
288 }
289
290 /*********************************************************************
291 * fwscanf_s (MSVCRT.@)
292 */
293 int CDECL MSVCRT_fwscanf_s(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
294 {
295 __ms_va_list valist;
296 int res;
297
298 __ms_va_start(valist, format);
299 res = MSVCRT_vfwscanf_s_l(file, format, NULL, valist);
300 __ms_va_end(valist);
301 return res;
302 }
303
304 /*********************************************************************
305 * _fwscanf_s_l (MSVCRT.@)
306 */
307 int CDECL MSVCRT__fwscanf_s_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
308 MSVCRT__locale_t locale, ...)
309 {
310 __ms_va_list valist;
311 int res;
312
313 __ms_va_start(valist, locale);
314 res = MSVCRT_vfwscanf_s_l(file, format, locale, valist);
315 __ms_va_end(valist);
316 return res;
317 }
318
319 /*********************************************************************
320 * wscanf (MSVCRT.@)
321 */
322 int CDECL MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
323 {
324 __ms_va_list valist;
325 int res;
326
327 __ms_va_start(valist, format);
328 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, NULL, valist);
329 __ms_va_end(valist);
330 return res;
331 }
332
333 /*********************************************************************
334 * _wscanf_l (MSVCRT.@)
335 */
336 int CDECL MSVCRT__wscanf_l(const MSVCRT_wchar_t *format,
337 MSVCRT__locale_t locale, ...)
338 {
339 __ms_va_list valist;
340 int res;
341
342 __ms_va_start(valist, locale);
343 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, locale, valist);
344 __ms_va_end(valist);
345 return res;
346 }
347
348 /*********************************************************************
349 * wscanf_s (MSVCRT.@)
350 */
351 int CDECL MSVCRT_wscanf_s(const MSVCRT_wchar_t *format, ...)
352 {
353 __ms_va_list valist;
354 int res;
355
356 __ms_va_start(valist, format);
357 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, NULL, valist);
358 __ms_va_end(valist);
359 return res;
360 }
361
362 /*********************************************************************
363 * _wscanf_s_l (MSVCRT.@)
364 */
365 int CDECL MSVCRT__wscanf_s_l(const MSVCRT_wchar_t *format,
366 MSVCRT__locale_t locale, ...)
367 {
368 __ms_va_list valist;
369 int res;
370
371 __ms_va_start(valist, locale);
372 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, locale, valist);
373 __ms_va_end(valist);
374 return res;
375 }
376
377 /*********************************************************************
378 * sscanf (MSVCRT.@)
379 */
380 int CDECL MSVCRT_sscanf(const char *str, const char *format, ...)
381 {
382 __ms_va_list valist;
383 int res;
384
385 __ms_va_start(valist, format);
386 res = MSVCRT_vsscanf_l(str, format, NULL, valist);
387 __ms_va_end(valist);
388 return res;
389 }
390
391 /*********************************************************************
392 * _sscanf_l (MSVCRT.@)
393 */
394 int CDECL MSVCRT__sscanf_l(const char *str, const char *format,
395 MSVCRT__locale_t locale, ...)
396 {
397 __ms_va_list valist;
398 int res;
399
400 __ms_va_start(valist, locale);
401 res = MSVCRT_vsscanf_l(str, format, locale, valist);
402 __ms_va_end(valist);
403 return res;
404 }
405
406 /*********************************************************************
407 * sscanf_s (MSVCRT.@)
408 */
409 int CDECL MSVCRT_sscanf_s(const char *str, const char *format, ...)
410 {
411 __ms_va_list valist;
412 int res;
413
414 __ms_va_start(valist, format);
415 res = MSVCRT_vsscanf_s_l(str, format, NULL, valist);
416 __ms_va_end(valist);
417 return res;
418 }
419
420 /*********************************************************************
421 * _sscanf_s_l (MSVCRT.@)
422 */
423 int CDECL MSVCRT__sscanf_s_l(const char *str, const char *format,
424 MSVCRT__locale_t locale, ...)
425 {
426 __ms_va_list valist;
427 int res;
428
429 __ms_va_start(valist, locale);
430 res = MSVCRT_vsscanf_s_l(str, format, locale, valist);
431 __ms_va_end(valist);
432 return res;
433 }
434
435 /*********************************************************************
436 * swscanf (MSVCRT.@)
437 */
438 int CDECL MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
439 {
440 __ms_va_list valist;
441 int res;
442
443 __ms_va_start(valist, format);
444 res = MSVCRT_vswscanf_l(str, format, NULL, valist);
445 __ms_va_end(valist);
446 return res;
447 }
448
449 /*********************************************************************
450 * _swscanf_l (MSVCRT.@)
451 */
452 int CDECL MSVCRT__swscanf_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
453 MSVCRT__locale_t locale, ...)
454 {
455 __ms_va_list valist;
456 int res;
457
458 __ms_va_start(valist, locale);
459 res = MSVCRT_vswscanf_l(str, format, locale, valist);
460 __ms_va_end(valist);
461 return res;
462 }
463
464 /*********************************************************************
465 * swscanf_s (MSVCRT.@)
466 */
467 int CDECL MSVCRT_swscanf_s(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
468 {
469 __ms_va_list valist;
470 int res;
471
472 __ms_va_start(valist, format);
473 res = MSVCRT_vswscanf_s_l(str, format, NULL, valist);
474 __ms_va_end(valist);
475 return res;
476 }
477
478 /*********************************************************************
479 * _swscanf_s_l (MSVCRT.@)
480 */
481 int CDECL MSVCRT__swscanf_s_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
482 MSVCRT__locale_t locale, ...)
483 {
484 __ms_va_list valist;
485 int res;
486
487 __ms_va_start(valist, locale);
488 res = MSVCRT_vswscanf_s_l(str, format, locale, valist);
489 __ms_va_end(valist);
490 return res;
491 }
492
493 /*********************************************************************
494 * _cscanf (MSVCRT.@)
495 */
496 int CDECL _cscanf(const char *format, ...)
497 {
498 __ms_va_list valist;
499 int res;
500
501 __ms_va_start(valist, format);
502 res = MSVCRT_vcscanf_l(format, NULL, valist);
503 __ms_va_end(valist);
504 return res;
505 }
506
507 /*********************************************************************
508 * _cscanf_l (MSVCRT.@)
509 */
510 int CDECL _cscanf_l(const char *format, MSVCRT__locale_t locale, ...)
511 {
512 __ms_va_list valist;
513 int res;
514
515 __ms_va_start(valist, locale);
516 res = MSVCRT_vcscanf_l(format, locale, valist);
517 __ms_va_end(valist);
518 return res;
519 }
520
521 /*********************************************************************
522 * _cscanf_s (MSVCRT.@)
523 */
524 int CDECL _cscanf_s(const char *format, ...)
525 {
526 __ms_va_list valist;
527 int res;
528
529 __ms_va_start(valist, format);
530 res = MSVCRT_vcscanf_s_l(format, NULL, valist);
531 __ms_va_end(valist);
532 return res;
533 }
534
535 /*********************************************************************
536 * _cscanf_s_l (MSVCRT.@)
537 */
538 int CDECL _cscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
539 {
540 __ms_va_list valist;
541 int res;
542
543 __ms_va_start(valist, locale);
544 res = MSVCRT_vcscanf_s_l(format, locale, valist);
545 __ms_va_end(valist);
546 return res;
547 }
548
549 /*********************************************************************
550 * _cwscanf (MSVCRT.@)
551 */
552 int CDECL _cwscanf(const char *format, ...)
553 {
554 __ms_va_list valist;
555 int res;
556
557 __ms_va_start(valist, format);
558 res = MSVCRT_vcwscanf_l(format, NULL, valist);
559 __ms_va_end(valist);
560 return res;
561 }
562
563 /*********************************************************************
564 * _cwscanf_l (MSVCRT.@)
565 */
566 int CDECL _cwscanf_l(const char *format, MSVCRT__locale_t locale, ...)
567 {
568 __ms_va_list valist;
569 int res;
570
571 __ms_va_start(valist, locale);
572 res = MSVCRT_vcwscanf_l(format, locale, valist);
573 __ms_va_end(valist);
574 return res;
575 }
576
577 /*********************************************************************
578 * _cwscanf_s (MSVCRT.@)
579 */
580 int CDECL _cwscanf_s(const char *format, ...)
581 {
582 __ms_va_list valist;
583 int res;
584
585 __ms_va_start(valist, format);
586 res = MSVCRT_vcwscanf_s_l(format, NULL, valist);
587 __ms_va_end(valist);
588 return res;
589 }
590
591 /*********************************************************************
592 * _cwscanf_s_l (MSVCRT.@)
593 */
594 int CDECL _cwscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
595 {
596 __ms_va_list valist;
597 int res;
598
599 __ms_va_start(valist, locale);
600 res = MSVCRT_vcwscanf_s_l(format, locale, valist);
601 __ms_va_end(valist);
602 return res;
603 }
604
605 /*********************************************************************
606 * _snscanf (MSVCRT.@)
607 */
608 int CDECL MSVCRT__snscanf(char *input, MSVCRT_size_t length, const char *format, ...)
609 {
610 __ms_va_list valist;
611 int res;
612
613 __ms_va_start(valist, format);
614 res = MSVCRT_vsnscanf_l(input, length, format, NULL, valist);
615 __ms_va_end(valist);
616 return res;
617 }
618
619 /*********************************************************************
620 * _snscanf_l (MSVCRT.@)
621 */
622 int CDECL MSVCRT__snscanf_l(char *input, MSVCRT_size_t length,
623 const char *format, MSVCRT__locale_t locale, ...)
624 {
625 __ms_va_list valist;
626 int res;
627
628 __ms_va_start(valist, locale);
629 res = MSVCRT_vsnscanf_l(input, length, format, locale, valist);
630 __ms_va_end(valist);
631 return res;
632 }
633
634 /*********************************************************************
635 * _snscanf_s (MSVCRT.@)
636 */
637 int CDECL MSVCRT__snscanf_s(char *input, MSVCRT_size_t length, const char *format, ...)
638 {
639 __ms_va_list valist;
640 int res;
641
642 __ms_va_start(valist, format);
643 res = MSVCRT_vsnscanf_s_l(input, length, format, NULL, valist);
644 __ms_va_end(valist);
645 return res;
646 }
647
648 /*********************************************************************
649 * _snscanf_s_l (MSVCRT.@)
650 */
651 int CDECL MSVCRT__snscanf_s_l(char *input, MSVCRT_size_t length,
652 const char *format, MSVCRT__locale_t locale, ...)
653 {
654 __ms_va_list valist;
655 int res;
656
657 __ms_va_start(valist, locale);
658 res = MSVCRT_vsnscanf_s_l(input, length, format, locale, valist);
659 __ms_va_end(valist);
660 return res;
661 }
662
663 /*********************************************************************
664 * _snwscanf (MSVCRT.@)
665 */
666 int CDECL MSVCRT__snwscanf(MSVCRT_wchar_t *input, MSVCRT_size_t length,
667 const MSVCRT_wchar_t *format, ...)
668 {
669 __ms_va_list valist;
670 int res;
671
672 __ms_va_start(valist, format);
673 res = MSVCRT_vsnwscanf_l(input, length, format, NULL, valist);
674 __ms_va_end(valist);
675 return res;
676 }
677
678 /*********************************************************************
679 * _snwscanf_l (MSVCRT.@)
680 */
681 int CDECL MSVCRT__snwscanf_l(MSVCRT_wchar_t *input, MSVCRT_size_t length,
682 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
683 {
684 __ms_va_list valist;
685 int res;
686
687 __ms_va_start(valist, locale);
688 res = MSVCRT_vsnwscanf_l(input, length, format, locale, valist);
689 __ms_va_end(valist);
690 return res;
691 }
692
693 /*********************************************************************
694 * _snwscanf_s (MSVCRT.@)
695 */
696 int CDECL MSVCRT__snwscanf_s(MSVCRT_wchar_t *input, MSVCRT_size_t length,
697 const MSVCRT_wchar_t *format, ...)
698 {
699 __ms_va_list valist;
700 int res;
701
702 __ms_va_start(valist, format);
703 res = MSVCRT_vsnwscanf_s_l(input, length, format, NULL, valist);
704 __ms_va_end(valist);
705 return res;
706 }
707
708 /*********************************************************************
709 * _snscanf_s_l (MSVCRT.@)
710 */
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, ...)
713 {
714 __ms_va_list valist;
715 int res;
716
717 __ms_va_start(valist, locale);
718 res = MSVCRT_vsnwscanf_s_l(input, length, format, locale, valist);
719 __ms_va_end(valist);
720 return res;
721 }
722
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.