update for HEAD-2003091401
[reactos.git] / lib / msvcrt / stdio / vfscanf.c
index 349aaba..2d2cc54 100644 (file)
@@ -64,7 +64,7 @@ unsigned long int __strtoul_internal  (const char *__nptr,  char **__endptr, int
 # define TYPEMOD       (LONG|LONGDBL|SHORT)
 
 
-# define ungetc(c, s)  ((void) (c != EOF && --read_in), ungetc (c, s))
+# define UNGETC(c, s)  ((void) (((wint_t)c) != ((wint_t)EOF) && --read_in), ungetc (c, s))
 # define inchar()      ((c = getc (s)), (void) (c != EOF && ++read_in), c)
 # define encode_error()        do {                                                  \
                          funlockfile (s);                                    \
@@ -103,25 +103,21 @@ unsigned long int __strtoul_internal  (const char *__nptr,  char **__endptr, int
 # define flockfile(S) /* nothing */
 # define funlockfile(S) /* nothing */
 
-  char *wp = NULL;             /* Workspace.  */
-  size_t wpmax = 0;            /* Maximal size of workspace.  */
-  size_t wpsize = 0;           /* Currently used bytes in workspace.  */
-
-
-void ADDW(int Ch)      \
-{
-  if (wpsize == wpmax)
-    {
-      char *old = wp;
-      wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax;
-      wp = (char *) malloc (wpmax);
-         if (old != NULL) {                                        
-         memcpy (wp, old, wpsize);
-         free(old);
-       }
-    }
-  wp[wpsize++] = (Ch);
-}
+# define ADDW(Ch)                                                            \
+do{                                                                          \
+  if (wpsize == wpmax)                                                       \
+    {                                                                        \
+      char *old = wp;                                                        \
+      wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax;                 \
+      wp = (char *) malloc (wpmax);                                          \
+      if (old != NULL)                                                       \
+       {                                                                     \
+         memcpy (wp, old, wpsize);                                           \
+         free(old);                                                          \
+       }                                                                     \
+    }                                                                        \
+  wp[wpsize++] = (Ch);                                                       \
+}while(0)
 
 
 int __vfscanf (FILE *s, const char *format, va_list argptr)
@@ -165,6 +161,9 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
      available anymore.  */
   int skip_space = 0;
   /* Workspace.  */
+  char *wp = NULL;             /* Workspace.  */
+  size_t wpmax = 0;            /* Maximal size of workspace.  */
+  size_t wpsize = 0;           /* Currently used bytes in workspace.  */
   char *tw;                    /* Temporary pointer.  */
 
 #ifdef __va_copy
@@ -198,7 +197,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
                    input_error ();
                  else if (c != *f++)
                    {
-                     ungetc (c, s);
+                     UNGETC (c, s);
                      conv_error ();
                    }
                }
@@ -229,14 +228,14 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
          if (skip_space)
            {
              while (isspace (c))
-               if (inchar () == EOF && errno == EINTR)
+               if (inchar () == EOF && *_errno() == EINTR)
                  conv_error ();
              skip_space = 0;
            }
 
          if (c != fc)
            {
-             ungetc (c, s);
+             UNGETC (c, s);
              conv_error ();
            }
 
@@ -344,7 +343,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
        conv_error ();
 
       /* We must take care for EINTR errors.  */
-      if (c == EOF && errno == EINTR)
+      if (c == EOF && *_errno() == EINTR)
        input_error ();
 
       /* Find the conversion specifier.  */
@@ -353,10 +352,10 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
        {
          /* Eat whitespace.  */
          do
-           if (inchar () == EOF && errno == EINTR)
+           if (inchar () == EOF && *_errno() == EINTR)
              input_error ();
          while (isspace (c));
-         ungetc (c, s);
+         UNGETC (c, s);
          skip_space = 0;
        }
 
@@ -366,7 +365,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
          c = inchar ();
          if (c != fc)
            {
-             ungetc (c, s);
+             UNGETC (c, s);
              conv_error ();
            }
          break;
@@ -583,7 +582,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
            {
              if (isspace (c))
                {
-                 ungetc (c, s);
+                 UNGETC (c, s);
                  break;
                }
 #define        STRING_ADD_CHAR(Str, c, Type)                                         \
@@ -653,7 +652,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
                       not make a difference for white space characters
                       we can simply push back a simple <SP> which is
                       guaranteed to be in the [:space:] class.  */
-                   ungetc (' ', s);
+                   UNGETC (' ', s);
                    break;
                  }
 
@@ -751,7 +750,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
            }
 
          /* The just read character is not part of the number anymore.  */
-         ungetc (c, s);
+         UNGETC (c, s);
 
          if (wpsize == 0 ||
              (wpsize == 1 && (wp[0] == '+' || wp[0] == '-')))
@@ -853,7 +852,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
                {
                  /* The last read character is not part of the number
                     anymore.  */
-                 ungetc (c, s);
+                 UNGETC (c, s);
                  break;
                }
              if (width > 0)
@@ -951,7 +950,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
          if (fc == '\0')
            {
              if (!(flags & LONG))
-               ungetc (c, s);
+               UNGETC (c, s);
              conv_error();
            }
 
@@ -973,7 +972,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
                         input we push it back only in case it is
                         representable within one byte.  */
                      if (val < 0x80)
-                       ungetc (val, s);
+                       UNGETC (val, s);
                      break;
                    }
                  STRING_ADD_CHAR (wstr, val, wchar_t);
@@ -999,7 +998,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
                {
                  if (wp[c] == not_in)
                    {
-                     ungetc (c, s);
+                     UNGETC (c, s);
                      break;
                    }
                  STRING_ADD_CHAR (str, c, char);
@@ -1036,7 +1035,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
       do
        c = inchar ();
       while (isspace (c));
-      ungetc (c, s);
+      UNGETC (c, s);
     }