advapi32/tests: Add trailing slashes tests for RegOpen/CreateKey.
[wine.git] / dlls / msvcrt / scanf.c
blob5dc69155c5db453f3d1a656d542bd86eff4d555e
1 /*
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
26 #include <stdarg.h>
27 #include <limits.h>
28 #include <math.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winternl.h"
33 #include "msvcrt.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
38 extern MSVCRT_FILE MSVCRT__iob[];
40 /* helper function for *scanf. Returns the value of character c in the
41 * given base, or -1 if the given character is not a digit of the base.
43 static int char2digit(char c, int base) {
44 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
45 if (base<=10) return -1;
46 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
47 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
48 return -1;
51 /* helper function for *wscanf. Returns the value of character c in the
52 * given base, or -1 if the given character is not a digit of the base.
54 static int wchar2digit(MSVCRT_wchar_t c, int base) {
55 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
56 if (base<=10) return -1;
57 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
58 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
59 return -1;
62 /* vfscanf_l */
63 #undef WIDE_SCANF
64 #undef CONSOLE
65 #undef STRING
66 #undef SECURE
67 #include "scanf.h"
69 /* vfscanf_l */
70 #define SECURE 1
71 #include "scanf.h"
73 /* vfwscanf_l */
74 #define WIDE_SCANF 1
75 #undef CONSOLE
76 #undef STRING
77 #undef SECURE
78 #include "scanf.h"
80 /* vfwscanf_s_l */
81 #define SECURE 1
82 #include "scanf.h"
84 /* vsscanf_l */
85 #undef WIDE_SCANF
86 #undef CONSOLE
87 #define STRING 1
88 #undef SECURE
89 #include "scanf.h"
91 /* vsscanf_s_l */
92 #define SECURE 1
93 #include "scanf.h"
95 /* vsnscanf_l */
96 #undef SECURE
97 #define STRING_LEN 1
98 #include "scanf.h"
100 /* vsnscanf_s_l */
101 #define SECURE
102 #include "scanf.h"
104 /* vsnwscanf_l */
105 #define WIDE_SCANF 1
106 #undef SECURE
107 #include "scanf.h"
109 /* vsnwscanf_s_l */
110 #define SECURE 1
111 #include "scanf.h"
112 #undef STRING_LEN
114 /* vswscanf_l */
115 #define WIDE_SCANF 1
116 #undef CONSOLE
117 #define STRING 1
118 #undef SECURE
119 #include "scanf.h"
121 /* vswscanf_s_l */
122 #define SECURE 1
123 #include "scanf.h"
125 /* vcscanf_l */
126 #undef WIDE_SCANF
127 #define CONSOLE 1
128 #undef STRING
129 #undef SECURE
130 #include "scanf.h"
132 /* vcscanf_s_l */
133 #define SECURE 1
134 #include "scanf.h"
136 /* vcwscanf_l */
137 #define WIDE_SCANF 1
138 #define CONSOLE 1
139 #undef STRING
140 #undef SECURE
141 #include "scanf.h"
143 /* vcwscanf_s_l */
144 #define SECURE 1
145 #include "scanf.h"
148 /*********************************************************************
149 * fscanf (MSVCRT.@)
151 int CDECL MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
153 __ms_va_list valist;
154 int res;
156 __ms_va_start(valist, format);
157 res = MSVCRT_vfscanf_l(file, format, NULL, valist);
158 __ms_va_end(valist);
159 return res;
162 /*********************************************************************
163 * _fscanf_l (MSVCRT.@)
165 int CDECL MSVCRT__fscanf_l(MSVCRT_FILE *file, const char *format,
166 MSVCRT__locale_t locale, ...)
168 __ms_va_list valist;
169 int res;
171 __ms_va_start(valist, locale);
172 res = MSVCRT_vfscanf_l(file, format, locale, valist);
173 __ms_va_end(valist);
174 return res;
177 /*********************************************************************
178 * fscanf_s (MSVCRT.@)
180 int CDECL MSVCRT_fscanf_s(MSVCRT_FILE *file, const char *format, ...)
182 __ms_va_list valist;
183 int res;
185 __ms_va_start(valist, format);
186 res = MSVCRT_vfscanf_s_l(file, format, NULL, valist);
187 __ms_va_end(valist);
188 return res;
191 /*********************************************************************
192 * _fscanf_s_l (MSVCRT.@)
194 int CDECL MSVCRT__fscanf_s_l(MSVCRT_FILE *file, const char *format,
195 MSVCRT__locale_t locale, ...)
197 __ms_va_list valist;
198 int res;
200 __ms_va_start(valist, locale);
201 res = MSVCRT_vfscanf_s_l(file, format, locale, valist);
202 __ms_va_end(valist);
203 return res;
206 /*********************************************************************
207 * scanf (MSVCRT.@)
209 int CDECL MSVCRT_scanf(const char *format, ...)
211 __ms_va_list valist;
212 int res;
214 __ms_va_start(valist, format);
215 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, NULL, valist);
216 __ms_va_end(valist);
217 return res;
220 /*********************************************************************
221 * _scanf_l (MSVCRT.@)
223 int CDECL MSVCRT__scanf_l(const char *format, MSVCRT__locale_t locale, ...)
225 __ms_va_list valist;
226 int res;
228 __ms_va_start(valist, locale);
229 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, locale, valist);
230 __ms_va_end(valist);
231 return res;
234 /*********************************************************************
235 * scanf_s (MSVCRT.@)
237 int CDECL MSVCRT_scanf_s(const char *format, ...)
239 __ms_va_list valist;
240 int res;
242 __ms_va_start(valist, format);
243 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, NULL, valist);
244 __ms_va_end(valist);
245 return res;
248 /*********************************************************************
249 * _scanf_s_l (MSVCRT.@)
251 int CDECL MSVCRT__scanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
253 __ms_va_list valist;
254 int res;
256 __ms_va_start(valist, locale);
257 res = MSVCRT_vfscanf_s_l(MSVCRT_stdin, format, locale, valist);
258 __ms_va_end(valist);
259 return res;
262 /*********************************************************************
263 * fwscanf (MSVCRT.@)
265 int CDECL MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
267 __ms_va_list valist;
268 int res;
270 __ms_va_start(valist, format);
271 res = MSVCRT_vfwscanf_l(file, format, NULL, valist);
272 __ms_va_end(valist);
273 return res;
276 /*********************************************************************
277 * _fwscanf_l (MSVCRT.@)
279 int CDECL MSVCRT__fwscanf_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
280 MSVCRT__locale_t locale, ...)
282 __ms_va_list valist;
283 int res;
285 __ms_va_start(valist, locale);
286 res = MSVCRT_vfwscanf_l(file, format, locale, valist);
287 __ms_va_end(valist);
288 return res;
291 /*********************************************************************
292 * fwscanf_s (MSVCRT.@)
294 int CDECL MSVCRT_fwscanf_s(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
296 __ms_va_list valist;
297 int res;
299 __ms_va_start(valist, format);
300 res = MSVCRT_vfwscanf_s_l(file, format, NULL, valist);
301 __ms_va_end(valist);
302 return res;
305 /*********************************************************************
306 * _fwscanf_s_l (MSVCRT.@)
308 int CDECL MSVCRT__fwscanf_s_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
309 MSVCRT__locale_t locale, ...)
311 __ms_va_list valist;
312 int res;
314 __ms_va_start(valist, locale);
315 res = MSVCRT_vfwscanf_s_l(file, format, locale, valist);
316 __ms_va_end(valist);
317 return res;
320 /*********************************************************************
321 * wscanf (MSVCRT.@)
323 int CDECL MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
325 __ms_va_list valist;
326 int res;
328 __ms_va_start(valist, format);
329 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, NULL, valist);
330 __ms_va_end(valist);
331 return res;
334 /*********************************************************************
335 * _wscanf_l (MSVCRT.@)
337 int CDECL MSVCRT__wscanf_l(const MSVCRT_wchar_t *format,
338 MSVCRT__locale_t locale, ...)
340 __ms_va_list valist;
341 int res;
343 __ms_va_start(valist, locale);
344 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, locale, valist);
345 __ms_va_end(valist);
346 return res;
349 /*********************************************************************
350 * wscanf_s (MSVCRT.@)
352 int CDECL MSVCRT_wscanf_s(const MSVCRT_wchar_t *format, ...)
354 __ms_va_list valist;
355 int res;
357 __ms_va_start(valist, format);
358 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, NULL, valist);
359 __ms_va_end(valist);
360 return res;
363 /*********************************************************************
364 * _wscanf_s_l (MSVCRT.@)
366 int CDECL MSVCRT__wscanf_s_l(const MSVCRT_wchar_t *format,
367 MSVCRT__locale_t locale, ...)
369 __ms_va_list valist;
370 int res;
372 __ms_va_start(valist, locale);
373 res = MSVCRT_vfwscanf_s_l(MSVCRT_stdin, format, locale, valist);
374 __ms_va_end(valist);
375 return res;
378 /*********************************************************************
379 * sscanf (MSVCRT.@)
381 int CDECL MSVCRT_sscanf(const char *str, const char *format, ...)
383 __ms_va_list valist;
384 int res;
386 __ms_va_start(valist, format);
387 res = MSVCRT_vsscanf_l(str, format, NULL, valist);
388 __ms_va_end(valist);
389 return res;
392 /*********************************************************************
393 * _sscanf_l (MSVCRT.@)
395 int CDECL MSVCRT__sscanf_l(const char *str, const char *format,
396 MSVCRT__locale_t locale, ...)
398 __ms_va_list valist;
399 int res;
401 __ms_va_start(valist, locale);
402 res = MSVCRT_vsscanf_l(str, format, locale, valist);
403 __ms_va_end(valist);
404 return res;
407 /*********************************************************************
408 * sscanf_s (MSVCRT.@)
410 int CDECL MSVCRT_sscanf_s(const char *str, const char *format, ...)
412 __ms_va_list valist;
413 int res;
415 __ms_va_start(valist, format);
416 res = MSVCRT_vsscanf_s_l(str, format, NULL, valist);
417 __ms_va_end(valist);
418 return res;
421 /*********************************************************************
422 * _sscanf_s_l (MSVCRT.@)
424 int CDECL MSVCRT__sscanf_s_l(const char *str, const char *format,
425 MSVCRT__locale_t locale, ...)
427 __ms_va_list valist;
428 int res;
430 __ms_va_start(valist, locale);
431 res = MSVCRT_vsscanf_s_l(str, format, locale, valist);
432 __ms_va_end(valist);
433 return res;
436 /*********************************************************************
437 * swscanf (MSVCRT.@)
439 int CDECL MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
441 __ms_va_list valist;
442 int res;
444 __ms_va_start(valist, format);
445 res = MSVCRT_vswscanf_l(str, format, NULL, valist);
446 __ms_va_end(valist);
447 return res;
450 /*********************************************************************
451 * _swscanf_l (MSVCRT.@)
453 int CDECL MSVCRT__swscanf_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
454 MSVCRT__locale_t locale, ...)
456 __ms_va_list valist;
457 int res;
459 __ms_va_start(valist, locale);
460 res = MSVCRT_vswscanf_l(str, format, locale, valist);
461 __ms_va_end(valist);
462 return res;
465 /*********************************************************************
466 * swscanf_s (MSVCRT.@)
468 int CDECL MSVCRT_swscanf_s(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
470 __ms_va_list valist;
471 int res;
473 __ms_va_start(valist, format);
474 res = MSVCRT_vswscanf_s_l(str, format, NULL, valist);
475 __ms_va_end(valist);
476 return res;
479 /*********************************************************************
480 * _swscanf_s_l (MSVCRT.@)
482 int CDECL MSVCRT__swscanf_s_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
483 MSVCRT__locale_t locale, ...)
485 __ms_va_list valist;
486 int res;
488 __ms_va_start(valist, locale);
489 res = MSVCRT_vswscanf_s_l(str, format, locale, valist);
490 __ms_va_end(valist);
491 return res;
494 /*********************************************************************
495 * _cscanf (MSVCRT.@)
497 int CDECL _cscanf(const char *format, ...)
499 __ms_va_list valist;
500 int res;
502 __ms_va_start(valist, format);
503 res = MSVCRT_vcscanf_l(format, NULL, valist);
504 __ms_va_end(valist);
505 return res;
508 /*********************************************************************
509 * _cscanf_l (MSVCRT.@)
511 int CDECL _cscanf_l(const char *format, MSVCRT__locale_t locale, ...)
513 __ms_va_list valist;
514 int res;
516 __ms_va_start(valist, locale);
517 res = MSVCRT_vcscanf_l(format, locale, valist);
518 __ms_va_end(valist);
519 return res;
522 /*********************************************************************
523 * _cscanf_s (MSVCRT.@)
525 int CDECL _cscanf_s(const char *format, ...)
527 __ms_va_list valist;
528 int res;
530 __ms_va_start(valist, format);
531 res = MSVCRT_vcscanf_s_l(format, NULL, valist);
532 __ms_va_end(valist);
533 return res;
536 /*********************************************************************
537 * _cscanf_s_l (MSVCRT.@)
539 int CDECL _cscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
541 __ms_va_list valist;
542 int res;
544 __ms_va_start(valist, locale);
545 res = MSVCRT_vcscanf_s_l(format, locale, valist);
546 __ms_va_end(valist);
547 return res;
550 /*********************************************************************
551 * _cwscanf (MSVCRT.@)
553 int CDECL _cwscanf(const char *format, ...)
555 __ms_va_list valist;
556 int res;
558 __ms_va_start(valist, format);
559 res = MSVCRT_vcwscanf_l(format, NULL, valist);
560 __ms_va_end(valist);
561 return res;
564 /*********************************************************************
565 * _cwscanf_l (MSVCRT.@)
567 int CDECL _cwscanf_l(const char *format, MSVCRT__locale_t locale, ...)
569 __ms_va_list valist;
570 int res;
572 __ms_va_start(valist, locale);
573 res = MSVCRT_vcwscanf_l(format, locale, valist);
574 __ms_va_end(valist);
575 return res;
578 /*********************************************************************
579 * _cwscanf_s (MSVCRT.@)
581 int CDECL _cwscanf_s(const char *format, ...)
583 __ms_va_list valist;
584 int res;
586 __ms_va_start(valist, format);
587 res = MSVCRT_vcwscanf_s_l(format, NULL, valist);
588 __ms_va_end(valist);
589 return res;
592 /*********************************************************************
593 * _cwscanf_s_l (MSVCRT.@)
595 int CDECL _cwscanf_s_l(const char *format, MSVCRT__locale_t locale, ...)
597 __ms_va_list valist;
598 int res;
600 __ms_va_start(valist, locale);
601 res = MSVCRT_vcwscanf_s_l(format, locale, valist);
602 __ms_va_end(valist);
603 return res;
606 /*********************************************************************
607 * _snscanf (MSVCRT.@)
609 int CDECL MSVCRT__snscanf(char *input, MSVCRT_size_t length, const char *format, ...)
611 __ms_va_list valist;
612 int res;
614 __ms_va_start(valist, format);
615 res = MSVCRT_vsnscanf_l(input, length, format, NULL, valist);
616 __ms_va_end(valist);
617 return res;
620 /*********************************************************************
621 * _snscanf_l (MSVCRT.@)
623 int CDECL MSVCRT__snscanf_l(char *input, MSVCRT_size_t length,
624 const char *format, MSVCRT__locale_t locale, ...)
626 __ms_va_list valist;
627 int res;
629 __ms_va_start(valist, locale);
630 res = MSVCRT_vsnscanf_l(input, length, format, locale, valist);
631 __ms_va_end(valist);
632 return res;
635 /*********************************************************************
636 * _snscanf_s (MSVCRT.@)
638 int CDECL MSVCRT__snscanf_s(char *input, MSVCRT_size_t length, const char *format, ...)
640 __ms_va_list valist;
641 int res;
643 __ms_va_start(valist, format);
644 res = MSVCRT_vsnscanf_s_l(input, length, format, NULL, valist);
645 __ms_va_end(valist);
646 return res;
649 /*********************************************************************
650 * _snscanf_s_l (MSVCRT.@)
652 int CDECL MSVCRT__snscanf_s_l(char *input, MSVCRT_size_t length,
653 const char *format, MSVCRT__locale_t locale, ...)
655 __ms_va_list valist;
656 int res;
658 __ms_va_start(valist, locale);
659 res = MSVCRT_vsnscanf_s_l(input, length, format, locale, valist);
660 __ms_va_end(valist);
661 return res;
664 /*********************************************************************
665 * _snwscanf (MSVCRT.@)
667 int CDECL MSVCRT__snwscanf(MSVCRT_wchar_t *input, MSVCRT_size_t length,
668 const MSVCRT_wchar_t *format, ...)
670 __ms_va_list valist;
671 int res;
673 __ms_va_start(valist, format);
674 res = MSVCRT_vsnwscanf_l(input, length, format, NULL, valist);
675 __ms_va_end(valist);
676 return res;
679 /*********************************************************************
680 * _snwscanf_l (MSVCRT.@)
682 int CDECL MSVCRT__snwscanf_l(MSVCRT_wchar_t *input, MSVCRT_size_t length,
683 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
685 __ms_va_list valist;
686 int res;
688 __ms_va_start(valist, locale);
689 res = MSVCRT_vsnwscanf_l(input, length, format, locale, valist);
690 __ms_va_end(valist);
691 return res;
694 /*********************************************************************
695 * _snwscanf_s (MSVCRT.@)
697 int CDECL MSVCRT__snwscanf_s(MSVCRT_wchar_t *input, MSVCRT_size_t length,
698 const MSVCRT_wchar_t *format, ...)
700 __ms_va_list valist;
701 int res;
703 __ms_va_start(valist, format);
704 res = MSVCRT_vsnwscanf_s_l(input, length, format, NULL, valist);
705 __ms_va_end(valist);
706 return res;
709 /*********************************************************************
710 * _snscanf_s_l (MSVCRT.@)
712 int CDECL MSVCRT__snwscanf_s_l(MSVCRT_wchar_t *input, MSVCRT_size_t length,
713 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
715 __ms_va_list valist;
716 int res;
718 __ms_va_start(valist, locale);
719 res = MSVCRT_vsnwscanf_s_l(input, length, format, locale, valist);
720 __ms_va_end(valist);
721 return res;