mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 15:20:10 +00:00
63fb8f9aa9
Nearly everything in _G_config.h is either junk or more appropriately defined elsewhere: * _G_fpos_t, _G_fpos64_t, and _G_BUFSIZ are already completely unused. * All remaining uses of _G_va_list have been changed to __gnuc_va_list. * The definition of _G_HAVE_ST_BLKSIZE/_IO_HAVE_ST_BLKSIZE has been inlined into its sole use. * The complete definition of _G_iconv_t has been moved to libio.h and renamed _IO_iconv_t (all actual users used that name). * _G_IO_IO_FILE_VERSION is vestigial; some code cares whether _IO_stdin_used exists, but nothing looks at its value. I've preserved the value as a hardwired constant in csu/init.c. This means csu/init.c no longer needs to include anything. * Many of the headers included by _G_config.h were already being included directly by either either libio.h or stdio.h; the remaining ones were moved to libio.h. * _G_HAVE_MREMAP is still relevant, because mremap genuinely is a Linux extension; it's not in POSIX and as far as I can tell it's not available on the Hurd either. I also preserved _G_HAVE_MMAP, since it's conceivable someone would want to port glibc to a MMU-less, mmap-less environment in the future. Both are now always defined to 1/0 as is the current convention, instead of the older 1/undef convention. These are the only symbols still defined in _G_config.h. * The actual inclusion of _G_config.h moves from libio.h to libioP.h, as this is where a potential override of _G_HAVE_MMAP happens. * The #ifdef logic in libioP.h controlling _IO_JUMPS_OFFSET has been simplified. After this patch, the only surviving _G_ symbols are the struct tag names _G_fpos_t and _G_fpos64_t, which are preserved for the sake of C++ mangled names in applications, and _G_HAVE_MMAP and _G_HAVE_MREMAP, which do not seem worth renaming. Installed stripped libraries are unchanged by this patch. * bits/_G_config.h: Move back to sysdeps/generic/_G_config.h. Delete all contents except for definitions of _G_HAVE_MMAP and _G_HAVE_MREMAP. Add commentary explaining those two symbols. * sysdeps/unix/sysv/linux/bits/_G_config.h: Move back to sysdeps/unix/sysv/linux/_G_config.h. Make same content change as above. * libio/libio.h: Don't include bits/_G_config.h here. Include stddef.h with __need_wchar_t defined. Include bits/types/__mbstate_t.h, bits/types/wint_t.h, and gconv.h. Define _IO_iconv_t here, directly. Don't define _IO_HAVE_ST_BLKSIZE. * libio/libioP.h: Include _G_config.h here. Move include of shlib-compat.h up with rest of includes. Simplify conditionals controlling definition of _IO_JUMPS_OFFSET. * csu/init.c: Remove always-true #if around entire file. Don't include stdio.h. Set _IO_stdin_used to hardwired constant 0x20001, and update commentary. * include/stdio.h, sysdeps/ieee754/ldbl-opt/nldbl-compat.h: Replace all uses of _G_va_list with __gnuc_va_list. * libio/filedoalloc.c: Use #if defined _STATBUF_ST_BLKSIZE instead of #if _IO_HAVE_ST_BLKSIZE. * libio/fileops.c: Test _G_HAVE_MREMAP with #if, not #ifdef. * libio/iofdopen.c, libio/iofopen.c: Test _G_HAVE_MMAP with #if, not #ifdef.
100 lines
3.2 KiB
C
100 lines
3.2 KiB
C
/* Copyright (C) 1993-2018 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
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
As a special exception, if you link the code in this file with
|
|
files compiled with a GNU compiler to produce an executable,
|
|
that does not cause the resulting executable to be covered by
|
|
the GNU Lesser General Public License. This exception does not
|
|
however invalidate any other reasons why the executable file
|
|
might be covered by the GNU Lesser General Public License.
|
|
This exception applies to code released by its copyright holders
|
|
in files containing the exception. */
|
|
|
|
#include "libioP.h"
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <stddef.h>
|
|
#include <shlib-compat.h>
|
|
|
|
_IO_FILE *
|
|
__fopen_maybe_mmap (_IO_FILE *fp)
|
|
{
|
|
#if _G_HAVE_MMAP
|
|
if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
|
|
{
|
|
/* Since this is read-only, we might be able to mmap the contents
|
|
directly. We delay the decision until the first read attempt by
|
|
giving it a jump table containing functions that choose mmap or
|
|
vanilla file operations and reset the jump table accordingly. */
|
|
|
|
if (fp->_mode <= 0)
|
|
_IO_JUMPS_FILE_plus (fp) = &_IO_file_jumps_maybe_mmap;
|
|
else
|
|
_IO_JUMPS_FILE_plus (fp) = &_IO_wfile_jumps_maybe_mmap;
|
|
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_maybe_mmap;
|
|
}
|
|
#endif
|
|
return fp;
|
|
}
|
|
|
|
|
|
_IO_FILE *
|
|
__fopen_internal (const char *filename, const char *mode, int is32)
|
|
{
|
|
struct locked_FILE
|
|
{
|
|
struct _IO_FILE_plus fp;
|
|
#ifdef _IO_MTSAFE_IO
|
|
_IO_lock_t lock;
|
|
#endif
|
|
struct _IO_wide_data wd;
|
|
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
|
|
|
|
if (new_f == NULL)
|
|
return NULL;
|
|
#ifdef _IO_MTSAFE_IO
|
|
new_f->fp.file._lock = &new_f->lock;
|
|
#endif
|
|
_IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &_IO_wfile_jumps);
|
|
_IO_JUMPS (&new_f->fp) = &_IO_file_jumps;
|
|
_IO_new_file_init_internal (&new_f->fp);
|
|
#if !_IO_UNIFIED_JUMPTABLES
|
|
new_f->fp.vtable = NULL;
|
|
#endif
|
|
if (_IO_file_fopen ((_IO_FILE *) new_f, filename, mode, is32) != NULL)
|
|
return __fopen_maybe_mmap (&new_f->fp.file);
|
|
|
|
_IO_un_link (&new_f->fp);
|
|
free (new_f);
|
|
return NULL;
|
|
}
|
|
|
|
_IO_FILE *
|
|
_IO_new_fopen (const char *filename, const char *mode)
|
|
{
|
|
return __fopen_internal (filename, mode, 1);
|
|
}
|
|
|
|
strong_alias (_IO_new_fopen, __new_fopen)
|
|
versioned_symbol (libc, _IO_new_fopen, _IO_fopen, GLIBC_2_1);
|
|
versioned_symbol (libc, __new_fopen, fopen, GLIBC_2_1);
|
|
|
|
# if !defined O_LARGEFILE || O_LARGEFILE == 0
|
|
weak_alias (_IO_new_fopen, _IO_fopen64)
|
|
weak_alias (_IO_new_fopen, fopen64)
|
|
# endif
|