summaryrefslogtreecommitdiff
path: root/libio/stdio.h
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-04-20 11:21:30 -0400
committerZack Weinberg <zackw@panix.com>2017-06-20 20:33:19 -0400
commitbdf5e4f8bdd50e276b9ed77181087312da849ec2 (patch)
tree63af5c5367e087dfc0e334ef4f1032d8ffea5c78 /libio/stdio.h
parentdf1fabcb39fddbe0a26a0d3f2cefba541d78cb25 (diff)
downloadglibc-zack/headers-cleanups.tar.gz
Don't install libio.h or _G_config.h.zack/headers-cleanups
This is an experimental patch which removes libio.h (and _G_config.h) from the set of application-exposed headers. After this change, the public stdio.h does not define any symbols whose names begin with _G_ nor _IO_, except that when optimizing, the guts of struct _IO_FILE and three of the flag constants are visible (see bits/stdio.h and bits/types/FILE_internals.h). There is a small amount of code duplication in bits/stdio.h, of macro bodies from libio.h that are no longer available. A number of internal .c files that were manually doing PLT bypass for flockfile/funlockfile can now rely on include/stdio.h to do it for them. It passes the testsuite on x86_64-linux, but it needs a great deal of additional testing; in particular I'm almost certain I broke the support for old-format (GLIBC_2.0) struct _IO_FILE, which is configured out on this target. Testing this properly would require someone to get their hands on _really_ old binaries, compiled against glibc 2.0, possibly statically-linked-but-using-NSS. Unfortunately, libc.so cannot be expected to be binary identical. However, this should be ready to feed into archive rebuilds to find out what applications break. Substantial clean-ups to the libio implementation are possible if this sticks, but I haven't done 'em; this is intended to be minimal. * libio/Makefile: Don't install libio.h or _G_config.h. Do install bits/types/FILE_internals.h, bits/types/cookie_io_functions_t.h, and bits/types/__fpos_t.h. * libio/stdio.h: Don't include libio.h. Get __gnuc_va_list directly from stdarg.h, __fpos_t and __fpos64_t from bits/types/__fpos_t.h, and the cookie types from bits/types/cookie_io_functions_t.h. Change all uses of _G_va_list, _G_fpos_t, _G_fpos64_t, _IO_FILE, _IO_cookie_io_functions_t, and _IO_ssize_t to __gnuc_va_list, __fpos_t, __fpos64_t, FILE, cookie_io_functions_t, and __ssize_t respectively. Do not define getc nor putc as macros. Define BUFSIZ as literal 8192. * libio/bits/types/FILE_internals.h: New header. Provide complete definition of struct _IO_FILE (the complete version) here. Duplicate definitions of _IO_EOF_SEEN, _IO_ERR_SEEN, and _IO_USER_LOCK here, with value assertions if they are already defined. * libio/bits/types/__fpos_t.h: New header. Define __fpos_t and __fpos64_t here. * libio/bits/types/cookie_io_functions_t.h: New header. Define cookie_read_function_t, cookie_write_function_t, cookie_seek_function_t, cookie_close_function_t, and cookie_io_functions_t here. * libio/libio.h: Include features.h first thing, then error out if either _LIBC or __USE_GNU is not defined, or if _ISOMAC is defined. Inline all of _G_config.h except _G_HAVE_MREMAP here. Get definitions of __mbstate_t, __fpos_t, __fpos64_t, struct _IO_FILE, and the cookie-related types from the relevant bits/types headers. Get definition of NULL from stddef.h. Make all #ifdef _LIBC and #if __GNUC__ >= (2,3) blocks unconditional. Remove all #if 0 and #ifdef __cplusplus blocks. Change all uses of _G_va_list, _G_fpos_t, and _G_fpos64_t to __gnuc_va_list, __fpos_t, __fpos64_t respectively. Provide definitions of _STDIO_USES_IOSTREAM, __HAVE_COLUMN, _IO_file_flags, __io_read_fn, __io_write_fn, __io_seek_fn, __io_close_fn, _IO_cookie_io_functions_t for the sake of the implementation. When _IO_USE_OLD_IO_FILE is defined, define struct _IO_FILE_old. * libio/libioP.h: When _IO_USE_OLD_IO_FILE is defined, define struct _IO_FILE_old_plus. Only declare _IO_old_file_init_internal when _IO_USE_OLD_IO_FILE is defined, and have it take an argument of type struct _IO_FILE_old_plus. * libio/oldfileops.c: Change all uses of _IO_FILE to _IO_FILE_old, _IO_FILE_plus to _IO_FILE_old_plus, _IO_FILE_complete to _IO_FILE, and _IO_FILE_complete_plus to _IO_FILE_plus. Then adjust types to match caller/callee's expectations. * libio/oldiofdopen.c, libio/oldiofopen.c, libio/oldiopopen.c * libio/oldstdfiles.c: Likewise. * sysdeps/generic/_G_config.h, sysdeps/unix/sysv/linux/_G_config.h: Only provide definition or non-definition of _G_HAVE_MREMAP. * sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c: Delete file. * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Remove iovfscanf. * sysdeps/ieee754/ldbl-opt/nldbl-compat.c: Define __nldbl__IO_vsprintf as alias to __nldbl_vsprintf instead of the other way around. * sysdeps/ieee754/ldbl-opt/nldbl-compat.h: Change all uses of _G_va_list to __gnuc_va_list. Remove NLDBL_DECL for _IO_vfscanf. * sysdeps/ieee754/ldbl-opt/nldbl-fscanf.c * sysdeps/ieee754/ldbl-opt/nldbl-scanf.c * sysdeps/ieee754/ldbl-opt/nldbl-vfscanf.c * sysdeps/ieee754/ldbl-opt/nldbl-vscanf.c: Use __nldbl_vfscanf, not __nldbl__IO_vfscanf. * libio/bits/stdio.h: Add multiple-inclusion guard. Include bits/types/FILE_internals.h. Declare __uflow and __overflow here. Remove redundant __USE_EXTERN_INLINES ifdef. Change all uses of _G_va_list to __gnuc_va_list and _IO_ssize_t to __ssize_t. (getchar): Use getc, not _IO_getc. (__getc_unlocked, __putc_unlocked): New inlines, duplicating the bodies of _IO_getc_unlocked and _IO_putc_unlocked. (fgetc_unlocked, getc_unlocked, getchar_unlocked, fread_unlocked): Use __getc_unlocked. (fputc_unlocked, putc_unlocked, putchar_unlocked, fwrite_unlocked): Use __putc_unlocked. (feof_unlocked): Duplicate the body of _IO_feof_unlocked here. (ferror_unlocked): Duplicate the body of _IO_ferror_unlocked here. * libio/bits/stdio2.h: Change all uses of _G_va_list to __gnuc_va_list. (fread_unlocked): Use __getc_unlocked. * libio/bits/types/FILE.h, libio/bits/types/__FILE.h: Explain in comments why the name _IO_FILE is used. * include/stdio.h: Change all uses of _G_va_list to __gnuc_va_list, _IO_ssize_t to __size_t, _IO_FILE to FILE, and _IO_fpos_t to __fpos_t. When IS_IN (libc), redirect flockfile and funlockfile to __flockfile and __funlockfile respectively. When _IO_MTSAFE_IO and not _ISOMAC, include stdio-lock.h before stdio.h proper. * include/stdio_ext.h: Include bits/types/FILE_internals.h for the sake of the inline definition of __fsetlocking. * include/libio.h: Adjust #ifdef nest to activate multiple-include optimization. * include/bits/types/FILE_internals.h, include/bits/types/__fpos_t.h * include/bits/types/cookie_io_functions_t.h: New trivial wrappers. * include/bits/stdio.h: New wrapper; mark __uflow and __overflow as hidden for intra-libc callers. * csu/init.c: Include libio.h, not _G_config.h. * grp/fgetgrent_r.c, grp/putgrent.c, gshadow/fgetsgent_r.c * gshadow/putsgent.c, misc/getpass.c, misc/getttyent.c * misc/mntent_r.c, posix/getopt.c, pwd/fgetpwent_r.c * shadow/fgetspent_r.c, shadow/putspent.c: Don't include libio/iolibio.h. Don't redefine flockfile or funlockfile. Don't use _IO_flockfile or _IO_funlockfile. * libio/__fbufsize.c, libio/__flbf.c, libio/__fpending.c * libio/__freadable.c, libio/__freading.c, libio/__fwritable.c * libio/__fwriting.c, malloc/malloc.c: Include libio.h. * misc/err.c: Include libio.h. Don't redefine flockfile or funlockfile. * stdio-common/tstgetln.c: Include sys/types.h. Don't redefine ssize_t. * conform/data/stdio.h-data: va_list may be defined as __gnuc_va_list, not _G_va_list. * benchtests/strcoll-inputs/filelist#en_US.UTF-8: Remove _G_config.h.
Diffstat (limited to 'libio/stdio.h')
-rw-r--r--libio/stdio.h82
1 files changed, 39 insertions, 43 deletions
diff --git a/libio/stdio.h b/libio/stdio.h
index 47490c8299..7019c1d28f 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -32,18 +32,22 @@ __BEGIN_DECLS
#define __need_NULL
#include <stddef.h>
+#define __need___va_list
+#include <stdarg.h>
+
#include <bits/types.h>
#include <bits/types/__FILE.h>
#include <bits/types/FILE.h>
+#include <bits/types/__fpos_t.h>
-#define _STDIO_USES_IOSTREAM
-
-#include <libio.h>
+#ifdef __USE_GNU
+# include <bits/types/cookie_io_functions_t.h>
+#endif
#if defined __USE_XOPEN || defined __USE_XOPEN2K8
# ifdef __GNUC__
# ifndef _VA_LIST_DEFINED
-typedef _G_va_list va_list;
+typedef __gnuc_va_list va_list;
# define _VA_LIST_DEFINED
# endif
# else
@@ -75,12 +79,12 @@ typedef __ssize_t ssize_t;
/* The type of the second argument to `fgetpos' and `fsetpos'. */
#ifndef __USE_FILE_OFFSET64
-typedef _G_fpos_t fpos_t;
+typedef __fpos_t fpos_t;
#else
-typedef _G_fpos64_t fpos_t;
+typedef __fpos64_t fpos_t;
#endif
#ifdef __USE_LARGEFILE64
-typedef _G_fpos64_t fpos64_t;
+typedef __fpos64_t fpos64_t;
#endif
/* The possibilities for the third argument to `setvbuf'. */
@@ -91,7 +95,7 @@ typedef _G_fpos64_t fpos64_t;
/* Default buffer size. */
#ifndef BUFSIZ
-# define BUFSIZ _IO_BUFSIZ
+# define BUFSIZ 8192
#endif
@@ -132,9 +136,9 @@ typedef _G_fpos64_t fpos64_t;
/* Standard streams. */
-extern struct _IO_FILE *stdin; /* Standard input stream. */
-extern struct _IO_FILE *stdout; /* Standard output stream. */
-extern struct _IO_FILE *stderr; /* Standard error output stream. */
+extern FILE *stdin; /* Standard input stream. */
+extern FILE *stdout; /* Standard output stream. */
+extern FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
@@ -270,7 +274,7 @@ extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
and uses the given functions for input and output. */
extern FILE *fopencookie (void *__restrict __magic_cookie,
const char *__restrict __modes,
- _IO_cookie_io_functions_t __io_funcs) __THROW __wur;
+ cookie_io_functions_t __io_funcs) __THROW __wur;
#endif
#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
@@ -325,15 +329,15 @@ extern int sprintf (char *__restrict __s,
This function is a possible cancellation point and therefore not
marked with __THROW. */
extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
- _G_va_list __arg);
+ __gnuc_va_list __arg);
/* Write formatted output to stdout from argument list ARG.
This function is a possible cancellation point and therefore not
marked with __THROW. */
-extern int vprintf (const char *__restrict __format, _G_va_list __arg);
+extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
/* Write formatted output to S from argument list ARG. */
extern int vsprintf (char *__restrict __s, const char *__restrict __format,
- _G_va_list __arg) __THROWNL;
+ __gnuc_va_list __arg) __THROWNL;
#if defined __USE_ISOC99 || defined __USE_UNIX98
/* Maximum chars of output to write in MAXLEN. */
@@ -342,7 +346,7 @@ extern int snprintf (char *__restrict __s, size_t __maxlen,
__THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
extern int vsnprintf (char *__restrict __s, size_t __maxlen,
- const char *__restrict __format, _G_va_list __arg)
+ const char *__restrict __format, __gnuc_va_list __arg)
__THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
#endif
@@ -350,7 +354,7 @@ extern int vsnprintf (char *__restrict __s, size_t __maxlen,
/* Write formatted output to a string dynamically allocated with `malloc'.
Store the address of the string in *PTR. */
extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
extern int __asprintf (char **__restrict __ptr,
const char *__restrict __fmt, ...)
@@ -363,7 +367,7 @@ extern int asprintf (char **__restrict __ptr,
#ifdef __USE_XOPEN2K8
/* Write formatted output to a file descriptor. */
extern int vdprintf (int __fd, const char *__restrict __fmt,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__attribute__ ((__format__ (__printf__, 2, 0)));
extern int dprintf (int __fd, const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
@@ -418,19 +422,19 @@ extern int __isoc99_sscanf (const char *__restrict __s,
This function is a possible cancellation point and therefore not
marked with __THROW. */
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
/* Read formatted input from stdin into argument list ARG.
This function is a possible cancellation point and therefore not
marked with __THROW. */
-extern int vscanf (const char *__restrict __format, _G_va_list __arg)
+extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
/* Read formatted input from S into argument list ARG. */
extern int vsscanf (const char *__restrict __s,
- const char *__restrict __format, _G_va_list __arg)
+ const char *__restrict __format, __gnuc_va_list __arg)
__THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
# if !defined __USE_GNU \
@@ -442,26 +446,26 @@ extern int vsscanf (const char *__restrict __s,
s, S or [. */
extern int __REDIRECT (vfscanf,
(FILE *__restrict __s,
- const char *__restrict __format, _G_va_list __arg),
+ const char *__restrict __format, __gnuc_va_list __arg),
__isoc99_vfscanf)
__attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
extern int __REDIRECT (vscanf, (const char *__restrict __format,
- _G_va_list __arg), __isoc99_vscanf)
+ __gnuc_va_list __arg), __isoc99_vscanf)
__attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
extern int __REDIRECT_NTH (vsscanf,
(const char *__restrict __s,
const char *__restrict __format,
- _G_va_list __arg), __isoc99_vsscanf)
+ __gnuc_va_list __arg), __isoc99_vsscanf)
__attribute__ ((__format__ (__scanf__, 2, 0)));
# else
extern int __isoc99_vfscanf (FILE *__restrict __s,
const char *__restrict __format,
- _G_va_list __arg) __wur;
+ __gnuc_va_list __arg) __wur;
extern int __isoc99_vscanf (const char *__restrict __format,
- _G_va_list __arg) __wur;
+ __gnuc_va_list __arg) __wur;
extern int __isoc99_vsscanf (const char *__restrict __s,
const char *__restrict __format,
- _G_va_list __arg) __THROW;
+ __gnuc_va_list __arg) __THROW;
# define vfscanf __isoc99_vfscanf
# define vscanf __isoc99_vscanf
# define vsscanf __isoc99_vsscanf
@@ -483,10 +487,6 @@ extern int getc (FILE *__stream);
marked with __THROW. */
extern int getchar (void);
-/* The C standard explicitly says this is a macro, so we always do the
- optimization for it. */
-#define getc(_fp) _IO_getc (_fp)
-
#ifdef __USE_POSIX199506
/* These are defined in POSIX.1:1996.
@@ -523,10 +523,6 @@ extern int putc (int __c, FILE *__stream);
marked with __THROW. */
extern int putchar (int __c);
-/* The C standard explicitly says this can be a macro,
- so we always do the optimization for it. */
-#define putc(_ch, _fp) _IO_putc (_ch, _fp)
-
#ifdef __USE_MISC
/* Faster version when locking is not necessary.
@@ -600,12 +596,12 @@ extern char *fgets_unlocked (char *__restrict __s, int __n,
cancellation point. But due to similarity with an POSIX interface
or due to the implementation they are cancellation points and
therefore not marked with __THROW. */
-extern _IO_ssize_t __getdelim (char **__restrict __lineptr,
- size_t *__restrict __n, int __delimiter,
- FILE *__restrict __stream) __wur;
-extern _IO_ssize_t getdelim (char **__restrict __lineptr,
+extern __ssize_t __getdelim (char **__restrict __lineptr,
size_t *__restrict __n, int __delimiter,
FILE *__restrict __stream) __wur;
+extern __ssize_t getdelim (char **__restrict __lineptr,
+ size_t *__restrict __n, int __delimiter,
+ FILE *__restrict __stream) __wur;
/* Like `getdelim', but reads up to a newline.
@@ -613,9 +609,9 @@ extern _IO_ssize_t getdelim (char **__restrict __lineptr,
cancellation point. But due to similarity with an POSIX interface
or due to the implementation it is a cancellation point and
therefore not marked with __THROW. */
-extern _IO_ssize_t getline (char **__restrict __lineptr,
- size_t *__restrict __n,
- FILE *__restrict __stream) __wur;
+extern __ssize_t getline (char **__restrict __lineptr,
+ size_t *__restrict __n,
+ FILE *__restrict __stream) __wur;
#endif
@@ -828,7 +824,7 @@ extern int obstack_printf (struct obstack *__restrict __obstack,
__THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
extern int obstack_vprintf (struct obstack *__restrict __obstack,
const char *__restrict __format,
- _G_va_list __args)
+ __gnuc_va_list __args)
__THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
#endif /* Use GNU. */