Fixed varargs handling in the scanf functions (spotted by Eric
authorAlexandre Julliard <julliard@winehq.org>
Thu, 19 Feb 2004 01:13:12 +0000 (01:13 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 19 Feb 2004 01:13:12 +0000 (01:13 +0000)
Pouech).

dlls/msvcrt/file.c
dlls/msvcrt/scanf.c
dlls/msvcrt/scanf.h
include/msvcrt/stdio.h

index 668fed49efdc518a4ab6284191b3e4eb5b8f5284..18732215d6afbbcf0e060308615528e7f05aa91a 100644 (file)
@@ -73,9 +73,6 @@ MSVCRT_FILE* MSVCRT_files[MSVCRT_MAX_FILES];
 int  MSVCRT_flags[MSVCRT_MAX_FILES];
 char *MSVCRT_tempfiles[MSVCRT_MAX_FILES];
 MSVCRT_FILE MSVCRT__iob[3];
-#define MSVCRT_stdin       (MSVCRT__iob+STDIN_FILENO)
-#define MSVCRT_stdout      (MSVCRT__iob+STDOUT_FILENO)
-#define MSVCRT_stderr      (MSVCRT__iob+STDERR_FILENO)
 
 static int MSVCRT_fdstart = 3; /* first unallocated fd */
 static int MSVCRT_fdend = 3; /* highest allocated fd */
@@ -2374,34 +2371,6 @@ int _wremove(const MSVCRT_wchar_t *path)
   return -1;
 }
 
-/*********************************************************************
- *             scanf (MSVCRT.@)
- */
-int MSVCRT_scanf(const char *format, ...)
-{
-  va_list valist;
-  int res;
-
-  va_start(valist, format);
-  res = MSVCRT_fscanf(MSVCRT_stdin, format, valist);
-  va_end(valist);
-  return res;
-}
-
-/*********************************************************************
- *             wscanf (MSVCRT.@)
- */
-int MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
-{
-  va_list valist;
-  int res;
-
-  va_start(valist, format);
-  res = MSVCRT_fwscanf(MSVCRT_stdin, format, valist);
-  va_end(valist);
-  return res;
-}
-
 /*********************************************************************
  *             rename (MSVCRT.@)
  */
index 58cd6bca02ecae9ed9dcdefc51d5b5d10b3057b2..e7b240b1a32d9795b9b0e4801c79da6f3d55ad70 100644 (file)
@@ -38,6 +38,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 
+extern MSVCRT_FILE MSVCRT__iob[];
+
 /* helper function for *scanf.  Returns the value of character c in the
  * given base, or -1 if the given character is not a digit of the base.
  */
@@ -60,43 +62,135 @@ static int wchar2digit(MSVCRT_wchar_t c, int base) {
     return -1;
 }
 
-
-/*********************************************************************
- *             fscanf (MSVCRT.@)
- */
+/* vfscanf */
 #undef WIDE_SCANF
 #undef CONSOLE
 #undef STRING
 #include "scanf.h"
 
-/*********************************************************************
- *             fwscanf (MSVCRT.@)
- */
+/* vfwscanf */
 #define WIDE_SCANF 1
 #undef CONSOLE
 #undef STRING
 #include "scanf.h"
 
-/*********************************************************************
- *             sscanf (MSVCRT.@)
- */
+/* vsscanf */
 #undef WIDE_SCANF
 #undef CONSOLE
 #define STRING 1
 #include "scanf.h"
 
-/*********************************************************************
- *             swscanf (MSVCRT.@)
- */
+/* vswscanf */
 #define WIDE_SCANF 1
 #undef CONSOLE
 #define STRING 1
 #include "scanf.h"
 
-/*********************************************************************
- *             _cscanf (MSVCRT.@)
- */
+/* vcscanf */
 #undef WIDE_SCANF
 #define CONSOLE 1
 #undef STRING
 #include "scanf.h"
+
+
+/*********************************************************************
+ *             fscanf (MSVCRT.@)
+ */
+int MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vfscanf(file, format, valist);
+    va_end(valist);
+    return res;
+}
+
+/*********************************************************************
+ *             scanf (MSVCRT.@)
+ */
+int MSVCRT_scanf(const char *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vfscanf(MSVCRT_stdin, format, valist);
+    va_end(valist);
+    return res;
+}
+
+/*********************************************************************
+ *             fwscanf (MSVCRT.@)
+ */
+int MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vfwscanf(file, format, valist);
+    va_end(valist);
+    return res;
+}
+
+
+/*********************************************************************
+ *             wscanf (MSVCRT.@)
+ */
+int MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vfwscanf(MSVCRT_stdin, format, valist);
+    va_end(valist);
+    return res;
+}
+
+
+/*********************************************************************
+ *             sscanf (MSVCRT.@)
+ */
+int MSVCRT_sscanf(const char *str, const char *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vsscanf(str, format, valist);
+    va_end(valist);
+    return res;
+}
+
+
+/*********************************************************************
+ *             swscanf (MSVCRT.@)
+ */
+int MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vswscanf(str, format, valist);
+    va_end(valist);
+    return res;
+}
+
+
+/*********************************************************************
+ *             _cscanf (MSVCRT.@)
+ */
+int _cscanf(const char *format, ...)
+{
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = MSVCRT_vcscanf(format, valist);
+    va_end(valist);
+    return res;
+}
index 88c954b62f7fdad996b68265ca4e74581413bf3b..82552154c0069009a0b78e32d14efa9612e2deb6 100644 (file)
@@ -48,7 +48,7 @@
 #ifdef CONSOLE
 #define _GETC_(file) (consumed++, _getch())
 #define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)
-#define _FUNCTION_ _cscanf(const _CHAR_ *format, ...)
+#define _FUNCTION_ static int MSVCRT_vcscanf(const char *format, va_list ap)
 #else
 #ifdef STRING
 #undef _EOF_
 #define _GETC_(file) (consumed++, *file++)
 #define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
 #ifdef WIDE_SCANF
-#define _FUNCTION_ MSVCRT_swscanf(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, ...)
+#define _FUNCTION_ static int MSVCRT_vswscanf(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, va_list ap)
 #else /* WIDE_SCANF */
-#define _FUNCTION_ MSVCRT_sscanf(const char *file, const char *format, ...)
+#define _FUNCTION_ static int MSVCRT_vsscanf(const char *file, const char *format, va_list ap)
 #endif /* WIDE_SCANF */
 #else /* STRING */
 #ifdef WIDE_SCANF
 #define _GETC_(file) (consumed++, MSVCRT_fgetwc(file))
 #define _UNGETC_(nch, file) do { MSVCRT_ungetwc(nch, file); consumed--; } while(0)
-#define _FUNCTION_ MSVCRT_fwscanf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, ...)
+#define _FUNCTION_ static int MSVCRT_vfwscanf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, va_list ap)
 #else /* WIDE_SCANF */
 #define _GETC_(file) (consumed++, MSVCRT_fgetc(file))
 #define _UNGETC_(nch, file) do { MSVCRT_ungetc(nch, file); consumed--; } while(0)
-#define _FUNCTION_ MSVCRT_fscanf(MSVCRT_FILE* file, const char *format, ...)
+#define _FUNCTION_ static int MSVCRT_vfscanf(MSVCRT_FILE* file, const char *format, va_list ap)
 #endif /* WIDE_SCANF */
 #endif /* STRING */
 #endif /* CONSOLE */
  * Extended by C. Scott Ananian <cananian@alumni.princeton.edu> to handle
  * more types of format spec.
  */
-int _FUNCTION_ {
+_FUNCTION_ {
     int rd = 0, consumed = 0;
     int nch;
-    va_list ap;
     if (!*format) return 0;
 #ifndef WIDE_SCANF
 #ifdef CONSOLE
@@ -98,7 +97,6 @@ int _FUNCTION_ {
     nch = _GETC_(file);
     if (nch == _EOF_) return _EOF_RET;
 
-    va_start(ap, format);
     while (*format) {
        /* a whitespace character in the format string causes scanf to read,
         * but not store, all consecutive white-space characters in the input
@@ -512,7 +510,6 @@ int _FUNCTION_ {
     if (nch!=_EOF_) {
        _UNGETC_(nch, file);
     }
-    va_end(ap);
     TRACE("returning %d\n", rd);
     return rd;
 }
index c93816cdf9cd584136c35fc4dccf8fd7582bb8e3..d665263e649f9b90795e09933e86685e70637921 100644 (file)
 
 #else
 
+#define MSVCRT_STDIN_FILENO  0
+#define MSVCRT_STDOUT_FILENO 1
+#define MSVCRT_STDERR_FILENO 2
+
 /* more file._flag flags, but these conflict with Unix */
 #define MSVCRT__IOFBF    0x0000
 #define MSVCRT__IONBF    0x0004
@@ -144,6 +148,10 @@ MSVCRT(FILE)*        MSVCRT(__p__iob)(void);
 #define stdin              (_iob+STDIN_FILENO)
 #define stdout             (_iob+STDOUT_FILENO)
 #define stderr             (_iob+STDERR_FILENO)
+#else
+#define MSVCRT_stdin       (MSVCRT__iob+MSVCRT_STDIN_FILENO)
+#define MSVCRT_stdout      (MSVCRT__iob+MSVCRT_STDOUT_FILENO)
+#define MSVCRT_stderr      (MSVCRT__iob+MSVCRT_STDERR_FILENO)
 #endif /* USE_MSVCRT_PREFIX */
 
 #ifndef MSVCRT_STDIO_DEFINED