summaryrefslogtreecommitdiff
path: root/include/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-08-23 07:52:27 -0400
commit6d350b3b179175b52172bd2cdd7de62186b3860d (patch)
tree9a16b8f077dd5dbafb28cba9361a36787aa2d9d7 /include/stdio.h
parent5a706f649de3952271930a8340db4ca8aa50f485 (diff)
downloadglibc-zack/dont-install-libio-h.tar.gz
Don't install libio.h or _G_config.h.zack/dont-install-libio-h
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 'include/stdio.h')
-rw-r--r--include/stdio.h51
1 files changed, 30 insertions, 21 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 509447c528..cb31621d4c 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,4 +1,7 @@
#ifndef _STDIO_H
+# if !defined _ISOMAC && defined _IO_MTSAFE_IO
+# include <stdio-lock.h>
+# endif
# include <libio/stdio.h>
# ifndef _ISOMAC
@@ -10,44 +13,44 @@ extern int __snprintf (char *__restrict __s, size_t __maxlen,
__attribute__ ((__format__ (__printf__, 3, 4)));
libc_hidden_proto (__snprintf)
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)
__attribute__ ((__format__ (__printf__, 3, 0)));
extern int __vfscanf (FILE *__restrict __s,
const char *__restrict __format,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 2, 0)));
libc_hidden_proto (__vfscanf)
extern int __vscanf (const char *__restrict __format,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 1, 0)));
-extern _IO_ssize_t __getline (char **__lineptr, size_t *__n,
+extern __ssize_t __getline (char **__lineptr, size_t *__n,
FILE *__stream);
extern int __vsscanf (const char *__restrict __s,
const char *__restrict __format,
- _G_va_list __arg)
+ __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 2, 0)));
extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW;
extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...)
__THROW;
extern int __vsprintf_chk (char *, int, size_t, const char *,
- _G_va_list) __THROW;
+ __gnuc_va_list) __THROW;
extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *,
- _G_va_list) __THROW;
+ __gnuc_va_list) __THROW;
extern int __printf_chk (int, const char *, ...);
extern int __fprintf_chk (FILE *, int, const char *, ...);
-extern int __vprintf_chk (int, const char *, _G_va_list);
-extern int __vfprintf_chk (FILE *, int, const char *, _G_va_list);
+extern int __vprintf_chk (int, const char *, __gnuc_va_list);
+extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list);
extern char *__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp);
extern char *__fgets_chk (char *buf, size_t size, int n, FILE *fp);
extern int __asprintf_chk (char **, int, const char *, ...) __THROW;
-extern int __vasprintf_chk (char **, int, const char *, _G_va_list) __THROW;
+extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
extern int __dprintf_chk (int, int, const char *, ...);
-extern int __vdprintf_chk (int, int, const char *, _G_va_list);
+extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
__THROW;
extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
- _G_va_list) __THROW;
+ __gnuc_va_list) __THROW;
extern int __isoc99_fscanf (FILE *__restrict __stream,
const char *__restrict __format, ...) __wur;
@@ -56,12 +59,12 @@ extern int __isoc99_sscanf (const char *__restrict __s,
const char *__restrict __format, ...) __THROW;
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;
libc_hidden_proto (__isoc99_vsscanf)
libc_hidden_proto (__isoc99_vfscanf)
@@ -106,9 +109,15 @@ libc_hidden_proto (__fortify_fail_abort)
/* Acquire ownership of STREAM. */
extern void __flockfile (FILE *__stream);
+# if IS_IN (libc)
+# define flockfile(stream) __flockfile(stream)
+# endif
/* Relinquish the ownership granted for STREAM. */
extern void __funlockfile (FILE *__stream);
+# if IS_IN (libc)
+# define funlockfile(stream) __funlockfile(stream)
+# endif
/* Try to acquire ownership of STREAM but do not block if it is not
possible. */
@@ -127,18 +136,18 @@ extern int _sys_nerr_internal attribute_hidden;
libc_hidden_proto (__asprintf)
# if IS_IN (libc)
-extern _IO_FILE *_IO_new_fopen (const char*, const char*);
+extern FILE *_IO_new_fopen (const char*, const char*);
# define fopen(fname, mode) _IO_new_fopen (fname, mode)
-extern _IO_FILE *_IO_new_fdopen (int, const char*);
+extern FILE *_IO_new_fdopen (int, const char*);
# define fdopen(fd, mode) _IO_new_fdopen (fd, mode)
-extern int _IO_new_fclose (_IO_FILE*);
+extern int _IO_new_fclose (FILE*);
# define fclose(fp) _IO_new_fclose (fp)
-extern int _IO_fputs (const char*, _IO_FILE*);
+extern int _IO_fputs (const char*, FILE*);
libc_hidden_proto (_IO_fputs)
# define fputs(str, fp) _IO_fputs (str, fp)
-extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
+extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
# define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp)
-extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
+extern int _IO_new_fgetpos (FILE *, __fpos_t *);
# define fgetpos(fp, posp) _IO_new_fgetpos (fp, posp)
# endif