1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00
* stdio-common/vfscanf.c: Simplify error handling macros.  Use
	direct locale access functions.
This commit is contained in:
Ulrich Drepper
2004-03-15 20:33:43 +00:00
parent 4f514b6bf2
commit e3b22ad379
4 changed files with 116 additions and 174 deletions

View File

@ -1,5 +1,8 @@
2004-03-15 Ulrich Drepper <drepper@redhat.com> 2004-03-15 Ulrich Drepper <drepper@redhat.com>
* stdio-common/vfscanf.c: Simplify error handling macros. Use
direct locale access functions.
* sysdeps/generic/strcasestr.c (__strcasestr): Optimize use of * sysdeps/generic/strcasestr.c (__strcasestr): Optimize use of
tolower function. tolower function.

View File

@ -1,3 +1,7 @@
2004-03-15 Ulrich Weigand <uweigand@de.ibm.com>
* init.c (nptl_version): Add __attribute_used__ to nptl_version.
2004-03-12 Richard Henderson <rth@redhat.com> 2004-03-12 Richard Henderson <rth@redhat.com>
* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: Propagate * sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: Propagate

View File

@ -62,7 +62,7 @@ size_t __static_tls_size;
size_t __static_tls_align_m1; size_t __static_tls_align_m1;
/* Version of the library, used in libthread_db to detect mismatches. */ /* Version of the library, used in libthread_db to detect mismatches. */
static const char nptl_version[] = VERSION; static const char nptl_version[] __attribute_used__ = VERSION;
#if defined USE_TLS && !defined SHARED #if defined USE_TLS && !defined SHARED

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc. /* Copyright (C) 1991-2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -65,7 +65,7 @@
#define I18N 0x400 /* I: use locale's digits */ #define I18N 0x400 /* I: use locale's digits */
#ifdef USE_IN_LIBIO #include <locale/localeinfo.h>
#include <libioP.h> #include <libioP.h>
#include <libio.h> #include <libio.h>
@ -116,10 +116,10 @@
? ++read_in \ ? ++read_in \
: (size_t) (inchar_errno = errno)), c)) : (size_t) (inchar_errno = errno)), c))
# define MEMCPY(d, s, n) memcpy (d, s, n) # define MEMCPY(d, s, n) memcpy (d, s, n)
# define ISSPACE(Ch) isspace (Ch) # define ISSPACE(Ch) __isspace_l (Ch, loc)
# define ISDIGIT(Ch) isdigit (Ch) # define ISDIGIT(Ch) __isdigit_l (Ch, loc)
# define ISXDIGIT(Ch) isxdigit (Ch) # define ISXDIGIT(Ch) __isxdigit_l (Ch, loc)
# define TOLOWER(Ch) tolower (Ch) # define TOLOWER(Ch) __tolower_l (Ch, loc)
# define ORIENT if (_IO_vtable_offset (s) == 0 \ # define ORIENT if (_IO_vtable_offset (s) == 0 \
&& _IO_fwide (s, -1) != -1) \ && _IO_fwide (s, -1) != -1) \
return EOF return EOF
@ -131,29 +131,23 @@
#endif #endif
#define encode_error() do { \ #define encode_error() do { \
if (errp != NULL) *errp |= 4; \ errval = 4; \
_IO_funlockfile (s); \
__libc_cleanup_end (0); \
__set_errno (EILSEQ); \ __set_errno (EILSEQ); \
return done; \ goto errout; \
} while (0) } while (0)
#define conv_error() do { \ #define conv_error() do { \
if (errp != NULL) *errp |= 2; \ errval = 2; \
_IO_funlockfile (s); \ goto errout; \
__libc_cleanup_end (0); \
return done; \
} while (0) } while (0)
#define input_error() do { \ #define input_error() do { \
_IO_funlockfile (s); \ errval = 1; \
if (errp != NULL) *errp |= 1; \ if (done == 0) done = EOF; \
__libc_cleanup_end (0); \ goto errout; \
return done ?: EOF; \
} while (0) } while (0)
#define memory_error() do { \ #define memory_error() do { \
_IO_funlockfile (s); \
__set_errno (ENOMEM); \ __set_errno (ENOMEM); \
__libc_cleanup_end (0); \ done = EOF; \
return EOF; \ goto errout; \
} while (0) } while (0)
#define ARGCHECK(s, format) \ #define ARGCHECK(s, format) \
do \ do \
@ -177,76 +171,11 @@
#define UNLOCK_STREAM(S) \ #define UNLOCK_STREAM(S) \
_IO_funlockfile (S); \ _IO_funlockfile (S); \
__libc_cleanup_region_end (0) __libc_cleanup_region_end (0)
#else
# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s))
# define ungetc_not_eof(c, s) (--read_in, (ungetc) (c, s))
# define inchar() (c == EOF ? EOF \
: ((c = getc (s)), (void) (c != EOF && ++read_in), c))
# define MEMCPY(d, s, n) memcpy (d, s, n)
# define ISSPACE(Ch) isspace (Ch)
# define ISDIGIT(Ch) isdigit (Ch)
# define ISXDIGIT(Ch) isxdigit (Ch)
# define TOLOWER(Ch) tolower (Ch)
# define L_(Str) Str
# define CHAR_T char
# define UCHAR_T unsigned char
# define WINT_T int
# define encode_error() do { \
funlockfile (s); \
__set_errno (EILSEQ); \
return done; \
} while (0)
# define conv_error() do { \
funlockfile (s); \
return done; \
} while (0)
# define input_error() do { \
funlockfile (s); \
return done ?: EOF; \
} while (0)
# define memory_error() do { \
funlockfile (s); \
__set_errno (ENOMEM); \
return EOF; \
} while (0)
# define ARGCHECK(s, format) \
do \
{ \
/* Check file argument for consistence. */ \
if (!__validfp (s) || !s->__mode.__read) \
{ \
__set_errno (EBADF); \
return EOF; \
} \
else if (format == NULL) \
{ \
__set_errno (EINVAL); \
return EOF; \
} \
} while (0)
#if 1
/* XXX For now !!! */
# define flockfile(S) /* nothing */
# define funlockfile(S) /* nothing */
# define LOCK_STREAM(S)
# define UNLOCK_STREAM(S)
#else
# define LOCK_STREAM(S) \
__libc_cleanup_region_start (&__funlockfile, (S)); \
__flockfile (S)
# define UNLOCK_STREAM(S) \
__funlockfile (S); \
__libc_cleanup_region_end (0)
#endif
#endif
/* Read formatted input from S according to the format string /* Read formatted input from S according to the format string
FORMAT, using the argument list in ARG. FORMAT, using the argument list in ARG.
Return the number of assignments made, or -1 for an input error. */ Return the number of assignments made, or -1 for an input error. */
#ifdef USE_IN_LIBIO
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
int int
_IO_vfwscanf (s, format, argptr, errp) _IO_vfwscanf (s, format, argptr, errp)
@ -262,10 +191,6 @@ _IO_vfscanf (s, format, argptr, errp)
_IO_va_list argptr; _IO_va_list argptr;
int *errp; int *errp;
#endif #endif
#else
int
__vfscanf (FILE *s, const char *format, va_list argptr)
#endif
{ {
va_list arg; va_list arg;
register const CHAR_T *f = format; register const CHAR_T *f = format;
@ -275,6 +200,11 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
register WINT_T c = 0; /* Last char read. */ register WINT_T c = 0; /* Last char read. */
register int width; /* Maximum field width. */ register int width; /* Maximum field width. */
register int flags; /* Modifiers for current format element. */ register int flags; /* Modifiers for current format element. */
int errval = 0;
#ifndef COMPILE_WSCANF
__locale_t loc = _NL_CURRENT_LOCALE;
struct locale_data *const curctype = loc->__locales[LC_CTYPE];
#endif
/* Errno of last failed inchar call. */ /* Errno of last failed inchar call. */
int inchar_errno = 0; int inchar_errno = 0;
@ -353,20 +283,26 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
ARGCHECK (s, format); ARGCHECK (s, format);
{
#ifndef COMPILE_WSCANF
struct locale_data *const curnumeric = loc->__locales[LC_NUMERIC];
#endif
/* Figure out the decimal point character. */ /* Figure out the decimal point character. */
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
decimal = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC); decimal = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
#else #else
decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT); decimal = curnumeric->values[_NL_ITEM_INDEX (DECIMAL_POINT)].string;
#endif #endif
/* Figure out the thousands separator character. */ /* Figure out the thousands separator character. */
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
thousands = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_THOUSANDS_SEP_WC); thousands = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_THOUSANDS_SEP_WC);
#else #else
thousands = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP); thousands = curnumeric->values[_NL_ITEM_INDEX (THOUSANDS_SEP)].string;
if (*thousands == '\0') if (*thousands == '\0')
thousands = NULL; thousands = NULL;
#endif #endif
}
/* Lock the stream. */ /* Lock the stream. */
LOCK_STREAM (s); LOCK_STREAM (s);
@ -1237,8 +1173,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
to_level = _NL_CURRENT_WORD (LC_CTYPE, to_level = _NL_CURRENT_WORD (LC_CTYPE,
_NL_CTYPE_INDIGITS_WC_LEN) - 1; _NL_CTYPE_INDIGITS_WC_LEN) - 1;
#else #else
to_level = _NL_CURRENT_WORD (LC_CTYPE, to_level = (uint32_t) curctype->values[_NL_ITEM_INDEX (_NL_CTYPE_INDIGITS_MB_LEN)].word - 1;
_NL_CTYPE_INDIGITS_MB_LEN) - 1;
#endif #endif
/* Read the number into workspace. */ /* Read the number into workspace. */
@ -1266,8 +1201,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
const char *cmpp; const char *cmpp;
int avail = width > 0 ? width : INT_MAX; int avail = width > 0 ? width : INT_MAX;
mbdigits[n] = _NL_CURRENT (LC_CTYPE, mbdigits[n]
_NL_CTYPE_INDIGITS0_MB + n); = curctype->values[_NL_CTYPE_INDIGITS0_MB + n].string;
for (level = 0; level < from_level; level++) for (level = 0; level < from_level; level++)
mbdigits[n] = strchr (mbdigits[n], '\0') + 1; mbdigits[n] = strchr (mbdigits[n], '\0') + 1;
@ -2316,14 +2251,19 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
&& (char *) str == *strptr + strsize) && (char *) str == *strptr + strsize)
{ {
/* Enlarge the buffer. */ /* Enlarge the buffer. */
str = (char *) realloc (*strptr, 2 * strsize); size_t newsize = 2 * strsize;
allocagain:
str = (char *) realloc (*strptr, newsize);
if (str == NULL) if (str == NULL)
{ {
/* Can't allocate that much. Last-ditch /* Can't allocate that much. Last-ditch
effort. */ effort. */
str = (char *) realloc (*strptr, strsize + 1); if (newsize > strsize + 1)
if (str == NULL)
{ {
newsize = strsize + 1;
goto allocagain;
}
/* We lose. Oh well. Terminate the /* We lose. Oh well. Terminate the
string and stop converting, string and stop converting,
so at least we don't skip any input. */ so at least we don't skip any input. */
@ -2335,14 +2275,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
*strptr = (char *) str; *strptr = (char *) str;
str += strsize; str += strsize;
++strsize; strsize = newsize;
}
}
else
{
*strptr = (char *) str;
str += strsize;
strsize *= 2;
} }
} }
} }
@ -2428,13 +2361,16 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
ungetc (c, s); ungetc (c, s);
} }
errout:
/* Unlock stream. */ /* Unlock stream. */
UNLOCK_STREAM (s); UNLOCK_STREAM (s);
if (errp != NULL)
*errp |= errval;
return done; return done;
} }
#ifdef USE_IN_LIBIO
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
int int
__vfwscanf (FILE *s, const wchar_t *format, va_list argptr) __vfwscanf (FILE *s, const wchar_t *format, va_list argptr)
@ -2449,7 +2385,6 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
} }
libc_hidden_def (__vfscanf) libc_hidden_def (__vfscanf)
#endif #endif
#endif
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
weak_alias (__vfwscanf, vfwscanf) weak_alias (__vfwscanf, vfwscanf)