diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-09-18 19:57:24 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-09-18 19:57:24 +0000 |
commit | 7913ba4d91b848ec4e5698c59d43198a3ef9215d (patch) | |
tree | afc73f6e0376ae6d07526c5efa9e941641ce1f6d /libio | |
parent | cedf9b89dd3b436ff7fad4c75d3f288ee4cd4ecd (diff) | |
download | glibc-7913ba4d91b848ec4e5698c59d43198a3ef9215d.tar.gz |
Updated to fedora-glibc-20070918T1931cvs/fedora-glibc-2_6_90-14
Diffstat (limited to 'libio')
-rw-r--r-- | libio/bits/stdio-ldbl.h | 19 | ||||
-rw-r--r-- | libio/bits/stdio.h | 9 | ||||
-rw-r--r-- | libio/bits/stdio2.h | 156 | ||||
-rw-r--r-- | libio/libio.h | 3 | ||||
-rw-r--r-- | libio/libioP.h | 2 | ||||
-rw-r--r-- | libio/stdio.h | 66 |
6 files changed, 228 insertions, 27 deletions
diff --git a/libio/bits/stdio-ldbl.h b/libio/bits/stdio-ldbl.h index 7a4291225e..c93e6c48fb 100644 --- a/libio/bits/stdio-ldbl.h +++ b/libio/bits/stdio-ldbl.h @@ -1,5 +1,5 @@ /* -mlong-double-64 compatibility mode for stdio functions. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -28,9 +28,17 @@ __LDBL_REDIR_DECL (sprintf) __LDBL_REDIR_DECL (vfprintf) __LDBL_REDIR_DECL (vprintf) __LDBL_REDIR_DECL (vsprintf) +#if defined __USE_ISOC99 && !defined __USE_GNU \ + && !defined __REDIRECT \ + && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) +__LDBL_REDIR1_DECL (fscanf, __nldbl___isoc99_fscanf) +__LDBL_REDIR1_DECL (scanf, __nldbl___isoc99_scanf) +__LDBL_REDIR1_DECL (sscanf, __nldbl___isoc99_sscanf) +#else __LDBL_REDIR_DECL (fscanf) __LDBL_REDIR_DECL (scanf) __LDBL_REDIR_DECL (sscanf) +#endif __END_NAMESPACE_STD #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 @@ -42,9 +50,16 @@ __END_NAMESPACE_C99 #ifdef __USE_ISOC99 __BEGIN_NAMESPACE_C99 +# if !defined __USE_GNU && !defined __REDIRECT \ + && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) +__LDBL_REDIR1_DECL (vfscanf, __nldbl___isoc99_vfscanf) +__LDBL_REDIR1_DECL (vscanf, __nldbl___isoc99_vscanf) +__LDBL_REDIR1_DECL (vsscanf, __nldbl___isoc99_vsscanf) +# else __LDBL_REDIR_DECL (vfscanf) __LDBL_REDIR_DECL (vsscanf) __LDBL_REDIR_DECL (vscanf) +# endif __END_NAMESPACE_C99 #endif @@ -58,7 +73,7 @@ __LDBL_REDIR_DECL (obstack_printf) __LDBL_REDIR_DECL (obstack_vprintf) #endif -#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus +#if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline __LDBL_REDIR_DECL (__sprintf_chk) __LDBL_REDIR_DECL (__vsprintf_chk) # if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h index 4d23f28db0..49303c6900 100644 --- a/libio/bits/stdio.h +++ b/libio/bits/stdio.h @@ -21,7 +21,7 @@ # error "Never include <bits/stdio.h> directly; use <stdio.h> instead." #endif -#ifdef __cplusplus +#ifndef __extern_inline # define __STDIO_INLINE inline #else # define __STDIO_INLINE __extern_inline @@ -29,12 +29,16 @@ #ifdef __USE_EXTERN_INLINES +/* For -D_FORTIFY_SOURCE{,=2} bits/stdio2.h will define a different + inline. */ +# if !(__USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline) /* Write formatted output to stdout from argument list ARG. */ __STDIO_INLINE int vprintf (__const char *__restrict __fmt, _G_va_list __arg) { return vfprintf (stdout, __fmt, __arg); } +# endif /* Read a character from stdin. */ __STDIO_INLINE int @@ -135,7 +139,8 @@ __NTH (ferror_unlocked (FILE *__stream)) #endif /* Use extern inlines. */ -#if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__ +#if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__ \ + && !defined __cplusplus /* Perform some simple optimizations. */ # define fread_unlocked(ptr, size, n, stream) \ (__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \ diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index 8fd4a16076..841a0ff6aa 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -27,11 +27,26 @@ extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen, __const char *__restrict __format, _G_va_list __ap) __THROW; -#define sprintf(str, ...) \ +#ifdef __va_arg_pack +__extern_always_inline int +__NTH (sprintf (char *__restrict __s, __const char *__restrict __fmt, ...)) +{ + return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, + __bos (__s), __fmt, __va_arg_pack ()); +} +#elif !defined __cplusplus +# define sprintf(str, ...) \ __builtin___sprintf_chk (str, __USE_FORTIFY_LEVEL - 1, __bos (str), \ __VA_ARGS__) -#define vsprintf(str, fmt, ap) \ - __builtin___vsprintf_chk (str, __USE_FORTIFY_LEVEL - 1, __bos (str), fmt, ap) +#endif + +__extern_always_inline int +__NTH (vsprintf (char *__restrict __s, __const char *__restrict __fmt, + _G_va_list __ap)) +{ + return __builtin___vsprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, + __bos (__s), __fmt, __ap); +} #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 @@ -42,12 +57,27 @@ extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, size_t __slen, __const char *__restrict __format, _G_va_list __ap) __THROW; -# define snprintf(str, len, ...) \ +# ifdef __va_arg_pack +__extern_always_inline int +__NTH (snprintf (char *__restrict __s, size_t __n, + __const char *__restrict __fmt, ...)) +{ + return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, + __bos (__s), __fmt, __va_arg_pack ()); +} +# elif !defined __cplusplus +# define snprintf(str, len, ...) \ __builtin___snprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \ __VA_ARGS__) -# define vsnprintf(str, len, fmt, ap) \ - __builtin___vsnprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \ - fmt, ap) +# endif + +__extern_always_inline int +__NTH (vsnprintf (char *__restrict __s, size_t __n, + __const char *__restrict __fmt, _G_va_list __ap)) +{ + return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, + __bos (__s), __fmt, __ap); +} #endif @@ -61,26 +91,43 @@ extern int __vfprintf_chk (FILE *__restrict __stream, int __flag, extern int __vprintf_chk (int __flag, __const char *__restrict __format, _G_va_list __ap); -# if __GNUC_PREREQ (4, 0) +# ifdef __va_arg_pack +__extern_always_inline int +fprintf (FILE *__restrict __stream, __const char *__restrict __fmt, ...) +{ + return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, + __va_arg_pack ()); +} + +__extern_always_inline int +printf (__const char *__restrict __fmt, ...) +{ + return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); +} +# elif !defined __cplusplus # define printf(...) \ __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # define fprintf(stream, ...) \ __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define vprintf(format, ap) \ - __vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap) -# define vfprintf(stream, format, ap) \ - __vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap) -# else -# define printf(...) \ - __builtin___printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define fprintf(stream, ...) \ - __builtin___fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define vprintf(format, ap) \ - __builtin___vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap) -# define vfprintf(stream, format, ap) \ - __builtin___vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap) # endif +__extern_always_inline int +vprintf (__const char *__restrict __fmt, _G_va_list __ap) +{ +#ifdef __USE_EXTERN_INLINES + return __vfprintf_chk (stdout, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); +#else + return __vprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __ap); +#endif +} + +__extern_always_inline int +vfprintf (FILE *__restrict __stream, + __const char *__restrict __fmt, _G_va_list __ap) +{ + return __vfprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); +} + #endif extern char *__gets_chk (char *__str, size_t) __wur; @@ -109,6 +156,27 @@ fgets (char *__restrict __s, int __n, FILE *__restrict __stream) return __fgets_alias (__s, __n, __stream); } +extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream) __wur; +extern size_t __REDIRECT (__fread_alias, + (void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __stream), + fread) __wur; + +__extern_always_inline __wur size_t +fread (void *__restrict __ptr, size_t __size, size_t __n, + FILE *__restrict __stream) +{ + if (__bos0 (__ptr) != (size_t) -1 + && (!__builtin_constant_p (__size) + || !__builtin_constant_p (__n) + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)) + || __size * __n > __bos0 (__ptr))) + return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); + return __fread_alias (__ptr, __size, __n, __stream); +} + #ifdef __USE_GNU extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __wur; @@ -125,3 +193,49 @@ fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) return __fgets_unlocked_alias (__s, __n, __stream); } #endif + +#ifdef __USE_MISC +# undef fread_unlocked +extern size_t __fread_unlocked_chk (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream) __wur; +extern size_t __REDIRECT (__fread_unlocked_alias, + (void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __stream), + fread_unlocked) __wur; + +__extern_always_inline __wur size_t +fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, + FILE *__restrict __stream) +{ + if (__bos0 (__ptr) != (size_t) -1 + && (!__builtin_constant_p (__size) + || !__builtin_constant_p (__n) + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)) + || __size * __n > __bos0 (__ptr))) + return __fread_unlocked_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); + +# ifdef __USE_EXTERN_INLINES + if (__builtin_constant_p (__size) + && __builtin_constant_p (__n) + && (__size | __n) < (((size_t) 1) << (8 * sizeof (size_t) / 2)) + && __size * __n <= 8) + { + size_t __cnt = __size * __n; + char *__cptr = (char *) __ptr; + if (__cnt == 0) + return 0; + + for (; __cnt > 0; --__cnt) + { + int __c = _IO_getc_unlocked (__stream); + if (__c == EOF) + break; + *__cptr++ = __c; + } + return (__cptr - (char *) __ptr) / __size; + } +# endif + return __fread_unlocked_alias (__ptr, __size, __n, __stream); +} +#endif diff --git a/libio/libio.h b/libio/libio.h index a807883856..643812f72b 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -143,6 +143,9 @@ # define _IO_FLAGS2_FORTIFY 4 #endif #define _IO_FLAGS2_USER_WBUF 8 +#ifdef _LIBC +# define _IO_FLAGS2_SCANF_STD 16 +#endif /* These are "formatting flags" matching the iostream fmtflags enum values. */ #define _IO_SKIPWS 01 diff --git a/libio/libioP.h b/libio/libioP.h index b99b81743f..854f049291 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -974,7 +974,7 @@ __attribute__ ((__always_inline__)) _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p) { _IO_FILE *fp = *p; - fp->_flags &= ~_IO_FLAGS2_FORTIFY; + fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD); if ((fp->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (fp); } diff --git a/libio/stdio.h b/libio/stdio.h index 46274623c0..c14df27400 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -412,6 +412,34 @@ extern int scanf (__const char *__restrict __format, ...) __wur; /* Read formatted input from S. */ extern int sscanf (__const char *__restrict __s, __const char *__restrict __format, ...) __THROW; + +#if defined __USE_ISOC99 && !defined __USE_GNU \ + && (!defined __LDBL_COMPAT || !defined __REDIRECT) \ + && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) +# ifdef __REDIRECT +/* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[ + GNU extension which conflicts with valid %a followed by letter + s, S or [. */ +extern int __REDIRECT (fscanf, (FILE *__restrict __stream, + __const char *__restrict __format, ...), + __isoc99_fscanf) __wur; +extern int __REDIRECT (scanf, (__const char *__restrict __format, ...), + __isoc99_scanf) __wur; +extern int __REDIRECT (sscanf, (__const char *__restrict __s, + __const char *__restrict __format, ...), + __isoc99_sscanf) __THROW; +# else +extern int __isoc99_fscanf (FILE *__restrict __stream, + __const char *__restrict __format, ...) __wur; +extern int __isoc99_scanf (__const char *__restrict __format, ...) __wur; +extern int __isoc99_sscanf (__const char *__restrict __s, + __const char *__restrict __format, ...) __THROW; +# define fscanf __isoc99_fscanf +# define scanf __isoc99_scanf +# define sscanf __isoc99_sscanf +# endif +#endif + __END_NAMESPACE_STD #ifdef __USE_ISOC99 @@ -435,6 +463,42 @@ extern int vscanf (__const char *__restrict __format, _G_va_list __arg) extern int vsscanf (__const char *__restrict __s, __const char *__restrict __format, _G_va_list __arg) __THROW __attribute__ ((__format__ (__scanf__, 2, 0))); + +# if !defined __USE_GNU \ + && (!defined __LDBL_COMPAT || !defined __REDIRECT) \ + && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) +# ifdef __REDIRECT +/* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[ + GNU extension which conflicts with valid %a followed by letter + s, S or [. */ +extern int __REDIRECT (vfscanf, + (FILE *__restrict __s, + __const char *__restrict __format, _G_va_list __arg), + __isoc99_vfscanf) + __attribute__ ((__format__ (__scanf__, 2, 0))) __wur; +extern int __REDIRECT (vscanf, (__const char *__restrict __format, + _G_va_list __arg), __isoc99_vfscanf) + __attribute__ ((__format__ (__scanf__, 1, 0))) __wur; +extern int __REDIRECT (vsscanf, + (__const char *__restrict __s, + __const char *__restrict __format, _G_va_list __arg), + __isoc99_vsscanf) + __THROW __attribute__ ((__format__ (__scanf__, 2, 0))); +# else +extern int __isoc99_vfscanf (FILE *__restrict __s, + __const char *__restrict __format, + _G_va_list __arg) __wur; +extern int __isoc99_vscanf (__const char *__restrict __format, + _G_va_list __arg) __wur; +extern int __isoc99_vsscanf (__const char *__restrict __s, + __const char *__restrict __format, + _G_va_list __arg) __THROW; +# define vfscanf __isoc99_vfscanf +# define vscanf __isoc99_vsscanf +# define vsscanf __isoc99_vsscanf +# endif +# endif + __END_NAMESPACE_C99 #endif /* Use ISO C9x. */ @@ -840,7 +904,7 @@ extern void funlockfile (FILE *__stream) __THROW; #ifdef __USE_EXTERN_INLINES # include <bits/stdio.h> #endif -#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus +#if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline # include <bits/stdio2.h> #endif #ifdef __LDBL_COMPAT |