aboutsummaryrefslogtreecommitdiff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/vfprintf.c29
-rw-r--r--stdio-common/vfscanf.c22
2 files changed, 34 insertions, 17 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index 9a9e583faa..7c6a498a75 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -101,6 +101,9 @@ ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
} \
} while (0)
# define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
+# define flockfile(S) _IO_flockfile (S)
+/* This macro must be without parameter! Don't change it. */
+# define funlockfile _IO_funlockfile
#else /* ! USE_IN_LIBIO */
/* This code is for use in the GNU C library. */
# include <stdio.h>
@@ -398,7 +401,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
#define process_arg(fspec) \
- /* Start real work. We know about all flag and modifiers and \
+ /* Start real work. We know about all flags and modifiers and \
now process the wanted format specifier. */ \
LABEL (form_percent): \
/* Write a literal "%". */ \
@@ -846,6 +849,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
f = lead_str_end = find_spec (format, &mbstate);
/* Lock stream. */
+ __libc_cleanup_region_start ((void (*) (void *)) &funlockfile, s);
flockfile (s);
/* Write the literal text before the first format. */
@@ -854,10 +858,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
/* If we only have to print a simple string, return now. */
if (*f == L_('\0'))
- {
- funlockfile (s);
- return done;
- }
+ goto all_done;
/* Process whole format string. */
do
@@ -1025,8 +1026,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
if (spec == L_('\0'))
{
/* The format string ended before the specifier is complete. */
- funlockfile (s);
- return -1;
+ done = -1;
+ goto all_done;
}
/* If we are in the fast loop force entering the complicated
@@ -1042,11 +1043,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
}
while (*f != L_('\0'));
- /* Unlock stream. */
- funlockfile (s);
-
- /* We processed the whole format without any positional parameters. */
- return done;
+ /* Unlock stream and return. */
+ goto all_done;
/* Here starts the more complex loop to handle positional parameters. */
do_positional:
@@ -1289,8 +1287,8 @@ do_positional:
of chars. */
if (function_done < 0)
{
- funlockfile (s);
- return -1;
+ done = -1;
+ goto all_done;
}
done += function_done;
@@ -1305,8 +1303,9 @@ do_positional:
}
}
+all_done:
/* Unlock the stream. */
- funlockfile (s);
+ __libc_cleanup_region_end (1);
return done;
}
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 41b9f51f08..903f5849cc 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -79,6 +79,10 @@ Cambridge, MA 02139, USA. */
return EOF; \
} \
} while (0)
+# define LOCK_STREAM(S) \
+ __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, (S)); \
+ _IO_flockfile (S)
+# define UNLOCK_STREAM __libc_cleanup_region_end (1)
#else
# define ungetc(c, s) (--read_in, ungetc (c, s))
# define inchar() ((c = getc (s)), (void) ++read_in, c)
@@ -105,8 +109,18 @@ Cambridge, MA 02139, USA. */
return EOF; \
} \
} while (0)
+#if 1
+ /* XXX For now !!! */
# define flockfile(S) /* nothing */
# define funlockfile(S) /* nothing */
+# define LOCK_STREAM(S)
+# define UNLOCK_STREAM
+#else
+# define LOCK_STREAM(S) \
+ __libc_cleanup_region_start (&__funlockfile, (S)); \
+ __flockfile (S)
+# define UNLOCK_STREAM __libc_cleanup_region_start (1)
+#endif
#endif
@@ -194,7 +208,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
thousands = (wchar_t) *_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
/* Lock the stream. */
- flockfile (s);
+ LOCK_STREAM (s);
/* Run through the format string. */
while (*f != '\0')
@@ -441,6 +455,10 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
else
while (--width > 0 && inchar () != EOF);
+ if (width > 0)
+ /* I.e., EOF was read. */
+ --read_in;
+
if (!(flags & SUPPRESS))
++done;
@@ -842,7 +860,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
}
/* Unlock stream. */
- funlockfile (s);
+ UNLOCK_STREAM;
return done;
}