summaryrefslogtreecommitdiff
path: root/libio/bits/stdio2.h
diff options
context:
space:
mode:
Diffstat (limited to 'libio/bits/stdio2.h')
-rw-r--r--libio/bits/stdio2.h156
1 files changed, 135 insertions, 21 deletions
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