glibc/libio/fmemopen.c

227 lines
4.9 KiB
C
Raw Permalink Normal View History

libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
/* fmemopen implementation.
Copyright (C) 2015-2019 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/>. */
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
/* fmemopen() from 2.22 and forward works as defined by POSIX. It also
provides an older symbol, version 2.2.5, that behaves different regarding
SEEK_END (libio/oldfmemopen.c). */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
Update. 2002-08-04 Jakub Jelinek <jakub@redhat.com> * manual/debug.texi: Fix spelling to programmatically. Reported by <hayastan132@hotmail.com>. * include/libio.h: Add libc_hidden_proto for __uflow. * include/stdio.h: Map fopen, fdopen, fclose, fputs, fsetpos, and fgetpos to _IO_* names. Add libc_hidden_proto for fileno, fwrite, fseek, fflush_unlocked, fread_unlocked, fwrite_unlocked, fgets_unlocked, fputs_unlocked. * include/wchar.h: Add libc_hidden_proto for fputws_unlocked, putwc_unlocked, vswscanf. * libio/iolibio.h: Add libc_hidden_proto for _IO_fputs. * libio/fileno.c: Use <stdio.h> and libc_hidden_def. * libio/fseek.c: Likewise. * libio/fmemopen.c: Include "libioP.h". Call _IO_fopencookie and not fopencookie. * libio/genops.c (__uflow): Add libc_hidden_def. * libio/iofflush_u.c (fflush_unlocked): Likewise. * libio/iofgets_u.c (fgets_unlocked): Likewise. * libio/iofputs_u.c (fputs_unlocked): Likewise. * libio/iofputws_u.c (fputws_unlocked): Likewise. * libio/iofread_u.c (fread_unlocked): Likewise. * libio/iofwrite_u.c (fwrite_unlocked): Likewise. * libio/iovswscanf.c (vswscanf): Likewise. * libio/putwc_u.c (putwc_unlocked): Likewise. * libio/iofputs.c: Use libc_hidden_def instead of INTDEF. * malloc/malloc.c: Redirect fwrite calls to _IO_fwrite. * malloc/mtrace.c: Likewise. * sunrpc/clnt_perr.c: Remove fputs macro. * sunrpc/svc_simple.c: Likewise. * sunrpc/svc_tcp.c: Likewise. * sunrpc/svc_udp.c: Likewise. * sunrpc/xdr_rec.c: Likewise. * sunrpc/xdr_ref.c: Likewise. * iconv/Makefile: Add CPPFLAGS definitions with -DNOT_in_libc for iconv_prog, linereader, and charmap-dir. * locale/Makefile: Likewise for locale and charmap-dir. * malloc/Makefile: Likewise for memusagestat. * nscd/Makefile: Likewise for nscd, nscd_conf, and dbg_log. * sunrpc/Makefile: Likewise for rpc_main. * sysdeps/unix/sysv/linux/Makefile: Likewise for lddlibc4. * timezone/Makefile: Likewise for zic. * stdio-common/perror.c: Avoid multiple calls to fileno_unlocked.
2002-08-04 22:54:20 +02:00
#include "libioP.h"
typedef struct fmemopen_cookie_struct fmemopen_cookie_t;
struct fmemopen_cookie_struct
{
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
char *buffer; /* memory buffer. */
int mybuffer; /* allocated my buffer? */
int append; /* buffer open for append? */
size_t size; /* buffer length in bytes. */
Mechanically remove _IO_ name aliases for types and constants. This patch mechanically removes all remaining uses, and the definitions, of the following libio name aliases: name replaced with ---- ------------- _IO_FILE FILE _IO_fpos_t __fpos_t _IO_fpos64_t __fpos64_t _IO_size_t size_t _IO_ssize_t ssize_t or __ssize_t _IO_off_t off_t _IO_off64_t off64_t _IO_pid_t pid_t _IO_uid_t uid_t _IO_wint_t wint_t _IO_va_list va_list or __gnuc_va_list _IO_BUFSIZ BUFSIZ _IO_cookie_io_functions_t cookie_io_functions_t __io_read_fn cookie_read_function_t __io_write_fn cookie_write_function_t __io_seek_fn cookie_seek_function_t __io_close_fn cookie_close_function_t I used __fpos_t and __fpos64_t instead of fpos_t and fpos64_t because the definitions of fpos_t and fpos64_t depend on the largefile mode. I used __ssize_t and __gnuc_va_list in a handful of headers where namespace cleanliness might be relevant even though they're internal-use-only. In all other cases, I used the public-namespace name. There are a tiny handful of places where I left a use of 'struct _IO_FILE' alone, because it was being used together with 'struct _IO_FILE_plus' or 'struct _IO_FILE_complete' in the same arithmetic expression. Because this patch was almost entirely done with search and replace, I may have introduced indentation botches. I did proofread the diff, but I may have missed something. The ChangeLog below calls out all of the places where this was not a pure search-and-replace change. Installed stripped libraries and executables are unchanged by this patch, except that some assertions in vfscanf.c change line numbers. * libio/libio.h (_IO_FILE): Delete; all uses changed to FILE. (_IO_fpos_t): Delete; all uses changed to __fpos_t. (_IO_fpos64_t): Delete; all uses changed to __fpos64_t. (_IO_size_t): Delete; all uses changed to size_t. (_IO_ssize_t): Delete; all uses changed to ssize_t or __ssize_t. (_IO_off_t): Delete; all uses changed to off_t. (_IO_off64_t): Delete; all uses changed to off64_t. (_IO_pid_t): Delete; all uses changed to pid_t. (_IO_uid_t): Delete; all uses changed to uid_t. (_IO_wint_t): Delete; all uses changed to wint_t. (_IO_va_list): Delete; all uses changed to va_list or __gnuc_va_list. (_IO_BUFSIZ): Delete; all uses changed to BUFSIZ. (_IO_cookie_io_functions_t): Delete; all uses changed to cookie_io_functions_t. (__io_read_fn): Delete; all uses changed to cookie_read_function_t. (__io_write_fn): Delete; all uses changed to cookie_write_function_t. (__io_seek_fn): Delete; all uses changed to cookie_seek_function_t. (__io_close_fn): Delete: all uses changed to cookie_close_function_t. * libio/iofopncook.c: Remove unnecessary forward declarations. * libio/iolibio.h: Correct outdated commentary. * malloc/malloc.c (__malloc_stats): Remove unnecessary casts. * stdio-common/fxprintf.c (__fxprintf_nocancel): Remove unnecessary casts. * stdio-common/getline.c: Use _IO_getdelim directly. Don't redefine ssize_t. * stdio-common/printf_fp.c, stdio_common/printf_fphex.c * stdio-common/printf_size.c: Don't redefine size_t or FILE. Remove outdated comments. * stdio-common/vfscanf.c: Don't redefine va_list.
2018-02-08 00:42:04 +01:00
off64_t pos; /* current position at the buffer. */
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
size_t maxpos; /* max position in buffer. */
};
static ssize_t
fmemopen_read (void *cookie, char *b, size_t s)
{
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
fmemopen_cookie_t *c = (fmemopen_cookie_t *) cookie;
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
if (c->pos + s > c->maxpos)
{
s = c->maxpos - c->pos;
if ((size_t) c->pos > c->maxpos)
s = 0;
}
memcpy (b, &(c->buffer[c->pos]), s);
c->pos += s;
return s;
}
static ssize_t
fmemopen_write (void *cookie, const char *b, size_t s)
{
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
fmemopen_cookie_t *c = (fmemopen_cookie_t *) cookie;;
Mechanically remove _IO_ name aliases for types and constants. This patch mechanically removes all remaining uses, and the definitions, of the following libio name aliases: name replaced with ---- ------------- _IO_FILE FILE _IO_fpos_t __fpos_t _IO_fpos64_t __fpos64_t _IO_size_t size_t _IO_ssize_t ssize_t or __ssize_t _IO_off_t off_t _IO_off64_t off64_t _IO_pid_t pid_t _IO_uid_t uid_t _IO_wint_t wint_t _IO_va_list va_list or __gnuc_va_list _IO_BUFSIZ BUFSIZ _IO_cookie_io_functions_t cookie_io_functions_t __io_read_fn cookie_read_function_t __io_write_fn cookie_write_function_t __io_seek_fn cookie_seek_function_t __io_close_fn cookie_close_function_t I used __fpos_t and __fpos64_t instead of fpos_t and fpos64_t because the definitions of fpos_t and fpos64_t depend on the largefile mode. I used __ssize_t and __gnuc_va_list in a handful of headers where namespace cleanliness might be relevant even though they're internal-use-only. In all other cases, I used the public-namespace name. There are a tiny handful of places where I left a use of 'struct _IO_FILE' alone, because it was being used together with 'struct _IO_FILE_plus' or 'struct _IO_FILE_complete' in the same arithmetic expression. Because this patch was almost entirely done with search and replace, I may have introduced indentation botches. I did proofread the diff, but I may have missed something. The ChangeLog below calls out all of the places where this was not a pure search-and-replace change. Installed stripped libraries and executables are unchanged by this patch, except that some assertions in vfscanf.c change line numbers. * libio/libio.h (_IO_FILE): Delete; all uses changed to FILE. (_IO_fpos_t): Delete; all uses changed to __fpos_t. (_IO_fpos64_t): Delete; all uses changed to __fpos64_t. (_IO_size_t): Delete; all uses changed to size_t. (_IO_ssize_t): Delete; all uses changed to ssize_t or __ssize_t. (_IO_off_t): Delete; all uses changed to off_t. (_IO_off64_t): Delete; all uses changed to off64_t. (_IO_pid_t): Delete; all uses changed to pid_t. (_IO_uid_t): Delete; all uses changed to uid_t. (_IO_wint_t): Delete; all uses changed to wint_t. (_IO_va_list): Delete; all uses changed to va_list or __gnuc_va_list. (_IO_BUFSIZ): Delete; all uses changed to BUFSIZ. (_IO_cookie_io_functions_t): Delete; all uses changed to cookie_io_functions_t. (__io_read_fn): Delete; all uses changed to cookie_read_function_t. (__io_write_fn): Delete; all uses changed to cookie_write_function_t. (__io_seek_fn): Delete; all uses changed to cookie_seek_function_t. (__io_close_fn): Delete: all uses changed to cookie_close_function_t. * libio/iofopncook.c: Remove unnecessary forward declarations. * libio/iolibio.h: Correct outdated commentary. * malloc/malloc.c (__malloc_stats): Remove unnecessary casts. * stdio-common/fxprintf.c (__fxprintf_nocancel): Remove unnecessary casts. * stdio-common/getline.c: Use _IO_getdelim directly. Don't redefine ssize_t. * stdio-common/printf_fp.c, stdio_common/printf_fphex.c * stdio-common/printf_size.c: Don't redefine size_t or FILE. Remove outdated comments. * stdio-common/vfscanf.c: Don't redefine va_list.
2018-02-08 00:42:04 +01:00
off64_t pos = c->append ? c->maxpos : c->pos;
int addnullc = (s == 0 || b[s - 1] != '\0');
if (pos + s > c->size)
{
if ((size_t) (c->pos + addnullc) >= c->size)
{
__set_errno (ENOSPC);
return 0;
}
s = c->size - pos;
}
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
memcpy (&(c->buffer[pos]), b, s);
c->pos = pos + s;
if ((size_t) c->pos > c->maxpos)
{
c->maxpos = c->pos;
if (c->maxpos < c->size && addnullc)
c->buffer[c->maxpos] = '\0';
/* A null byte is written in a stream open for update iff it fits. */
else if (c->append == 0 && addnullc != 0)
c->buffer[c->size-1] = '\0';
}
return s;
}
static int
Mechanically remove _IO_ name aliases for types and constants. This patch mechanically removes all remaining uses, and the definitions, of the following libio name aliases: name replaced with ---- ------------- _IO_FILE FILE _IO_fpos_t __fpos_t _IO_fpos64_t __fpos64_t _IO_size_t size_t _IO_ssize_t ssize_t or __ssize_t _IO_off_t off_t _IO_off64_t off64_t _IO_pid_t pid_t _IO_uid_t uid_t _IO_wint_t wint_t _IO_va_list va_list or __gnuc_va_list _IO_BUFSIZ BUFSIZ _IO_cookie_io_functions_t cookie_io_functions_t __io_read_fn cookie_read_function_t __io_write_fn cookie_write_function_t __io_seek_fn cookie_seek_function_t __io_close_fn cookie_close_function_t I used __fpos_t and __fpos64_t instead of fpos_t and fpos64_t because the definitions of fpos_t and fpos64_t depend on the largefile mode. I used __ssize_t and __gnuc_va_list in a handful of headers where namespace cleanliness might be relevant even though they're internal-use-only. In all other cases, I used the public-namespace name. There are a tiny handful of places where I left a use of 'struct _IO_FILE' alone, because it was being used together with 'struct _IO_FILE_plus' or 'struct _IO_FILE_complete' in the same arithmetic expression. Because this patch was almost entirely done with search and replace, I may have introduced indentation botches. I did proofread the diff, but I may have missed something. The ChangeLog below calls out all of the places where this was not a pure search-and-replace change. Installed stripped libraries and executables are unchanged by this patch, except that some assertions in vfscanf.c change line numbers. * libio/libio.h (_IO_FILE): Delete; all uses changed to FILE. (_IO_fpos_t): Delete; all uses changed to __fpos_t. (_IO_fpos64_t): Delete; all uses changed to __fpos64_t. (_IO_size_t): Delete; all uses changed to size_t. (_IO_ssize_t): Delete; all uses changed to ssize_t or __ssize_t. (_IO_off_t): Delete; all uses changed to off_t. (_IO_off64_t): Delete; all uses changed to off64_t. (_IO_pid_t): Delete; all uses changed to pid_t. (_IO_uid_t): Delete; all uses changed to uid_t. (_IO_wint_t): Delete; all uses changed to wint_t. (_IO_va_list): Delete; all uses changed to va_list or __gnuc_va_list. (_IO_BUFSIZ): Delete; all uses changed to BUFSIZ. (_IO_cookie_io_functions_t): Delete; all uses changed to cookie_io_functions_t. (__io_read_fn): Delete; all uses changed to cookie_read_function_t. (__io_write_fn): Delete; all uses changed to cookie_write_function_t. (__io_seek_fn): Delete; all uses changed to cookie_seek_function_t. (__io_close_fn): Delete: all uses changed to cookie_close_function_t. * libio/iofopncook.c: Remove unnecessary forward declarations. * libio/iolibio.h: Correct outdated commentary. * malloc/malloc.c (__malloc_stats): Remove unnecessary casts. * stdio-common/fxprintf.c (__fxprintf_nocancel): Remove unnecessary casts. * stdio-common/getline.c: Use _IO_getdelim directly. Don't redefine ssize_t. * stdio-common/printf_fp.c, stdio_common/printf_fphex.c * stdio-common/printf_size.c: Don't redefine size_t or FILE. Remove outdated comments. * stdio-common/vfscanf.c: Don't redefine va_list.
2018-02-08 00:42:04 +01:00
fmemopen_seek (void *cookie, off64_t *p, int w)
{
Mechanically remove _IO_ name aliases for types and constants. This patch mechanically removes all remaining uses, and the definitions, of the following libio name aliases: name replaced with ---- ------------- _IO_FILE FILE _IO_fpos_t __fpos_t _IO_fpos64_t __fpos64_t _IO_size_t size_t _IO_ssize_t ssize_t or __ssize_t _IO_off_t off_t _IO_off64_t off64_t _IO_pid_t pid_t _IO_uid_t uid_t _IO_wint_t wint_t _IO_va_list va_list or __gnuc_va_list _IO_BUFSIZ BUFSIZ _IO_cookie_io_functions_t cookie_io_functions_t __io_read_fn cookie_read_function_t __io_write_fn cookie_write_function_t __io_seek_fn cookie_seek_function_t __io_close_fn cookie_close_function_t I used __fpos_t and __fpos64_t instead of fpos_t and fpos64_t because the definitions of fpos_t and fpos64_t depend on the largefile mode. I used __ssize_t and __gnuc_va_list in a handful of headers where namespace cleanliness might be relevant even though they're internal-use-only. In all other cases, I used the public-namespace name. There are a tiny handful of places where I left a use of 'struct _IO_FILE' alone, because it was being used together with 'struct _IO_FILE_plus' or 'struct _IO_FILE_complete' in the same arithmetic expression. Because this patch was almost entirely done with search and replace, I may have introduced indentation botches. I did proofread the diff, but I may have missed something. The ChangeLog below calls out all of the places where this was not a pure search-and-replace change. Installed stripped libraries and executables are unchanged by this patch, except that some assertions in vfscanf.c change line numbers. * libio/libio.h (_IO_FILE): Delete; all uses changed to FILE. (_IO_fpos_t): Delete; all uses changed to __fpos_t. (_IO_fpos64_t): Delete; all uses changed to __fpos64_t. (_IO_size_t): Delete; all uses changed to size_t. (_IO_ssize_t): Delete; all uses changed to ssize_t or __ssize_t. (_IO_off_t): Delete; all uses changed to off_t. (_IO_off64_t): Delete; all uses changed to off64_t. (_IO_pid_t): Delete; all uses changed to pid_t. (_IO_uid_t): Delete; all uses changed to uid_t. (_IO_wint_t): Delete; all uses changed to wint_t. (_IO_va_list): Delete; all uses changed to va_list or __gnuc_va_list. (_IO_BUFSIZ): Delete; all uses changed to BUFSIZ. (_IO_cookie_io_functions_t): Delete; all uses changed to cookie_io_functions_t. (__io_read_fn): Delete; all uses changed to cookie_read_function_t. (__io_write_fn): Delete; all uses changed to cookie_write_function_t. (__io_seek_fn): Delete; all uses changed to cookie_seek_function_t. (__io_close_fn): Delete: all uses changed to cookie_close_function_t. * libio/iofopncook.c: Remove unnecessary forward declarations. * libio/iolibio.h: Correct outdated commentary. * malloc/malloc.c (__malloc_stats): Remove unnecessary casts. * stdio-common/fxprintf.c (__fxprintf_nocancel): Remove unnecessary casts. * stdio-common/getline.c: Use _IO_getdelim directly. Don't redefine ssize_t. * stdio-common/printf_fp.c, stdio_common/printf_fphex.c * stdio-common/printf_size.c: Don't redefine size_t or FILE. Remove outdated comments. * stdio-common/vfscanf.c: Don't redefine va_list.
2018-02-08 00:42:04 +01:00
off64_t np;
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
fmemopen_cookie_t *c = (fmemopen_cookie_t *) cookie;
switch (w)
{
case SEEK_SET:
np = *p;
break;
case SEEK_CUR:
np = c->pos + *p;
break;
case SEEK_END:
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
np = c->maxpos + *p;
break;
default:
return -1;
}
Update. 2002-08-24 Ulrich Drepper <drepper@redhat.com> * locale/programs/charmap.c (charmap_new_char): Don't use ULONG_MAX as maximum UCS4 value. * sysdeps/unix/sysv/linux/ia64/sys/user.h: New file. * sysdeps/generic/strtol.c: We don't need the isascii test in glibc. * malloc/hooks.c (public_sET_STATe): use size_t as type for i. * malloc/malloc.c (mALLINFo): Likewise. * libio/wstrops.c (_IO_wstr_pbackfail): Use WEOF in comparison. * libio/wfileops.c (_IO_wfile_overflow): Use EOF not WEOF when examining result of _IO_do_flush call. * stdio-common/vfprintf.c (vfprintf): Use correct type in va_arg. Use prec not spec when sizing buffers. * catgets/open_catalog.c (__open_catalog): Add casts to avoid warnings. * locale/loadarchive.c (_nl_load_locale_from_archive): Likewise. * locale/loadlocale.c (_nl_intern_locale_data): Likewise. * stdio-common/vfscanf.c (inchar): Likewise. * misc/efgcvt_r.c (fcvt_r): Likewise. * elf/dl-misc.c (_dl_debug_vdprintf): Likewise. * elf/readlib.c (process_file): Likewise. * elf/sprof.c (load_profdata): Likewise. * sysdeps/ia64/hp-timing.h (HP_TIMING_PRINT): Likewise. * locale/programs/linereader.c (get_toplvl_escape): Likewise. * locale/programs/charmap.c (charmap_read): Likewise. * libio/fileops.c: Likewise. * libio/fmemopen.c: Likewise. * stdlib/strtod.c: Likewise. * elf/dl-load.c: Likewise. * iconv/iconvconfig.c: Likewise. * iconv/iconv_prog.c (process_block): Likewise. * sysdeps/unix/sysv/linux/ia64/Makefile: Define _ASM_IA64_CURRENT_H macro to calm down the compiler. * iconv/gconv_cache.c (__gconv_load_cache): Add cast to avoid warning. * sysdeps/ia64/elf/initfini.c: Don't use newlines embedded in string. * sysdeps/unix/sysv/linux/i386/sysdep.S: Update comment regarding placement of errno definition. * sysdeps/unix/sysv/linux/m68k/sysdep.S: Likewise. * sysdeps/unix/sysv/linux/mips/sysdep.S: Likewise. * sysdeps/unix/sysv/linux/x86_64/sysdep.S: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S: Likewise. * resolv/nss_dns/dns-host.c (MAXPACKET): Increase minimum value from 1024 to 65536, to avoid buffer overrun. 2002-08-16 Paul Eggert <eggert@twinsun.com> * resolv/gethnamaddr.c (MAXPACKET): Increase minimum value from 1024 to 65536, to avoid buffer overrun. * resolv/res_query.c (MAXPACKET): Likewise. architectures.
2002-08-25 06:51:08 +02:00
if (np < 0 || (size_t) np > c->size)
{
__set_errno (EINVAL);
return -1;
}
*p = c->pos = np;
return 0;
}
static int
fmemopen_close (void *cookie)
{
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
fmemopen_cookie_t *c = (fmemopen_cookie_t *) cookie;
if (c->mybuffer)
free (c->buffer);
free (c);
return 0;
}
FILE *
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
__fmemopen (void *buf, size_t len, const char *mode)
{
cookie_io_functions_t iof;
fmemopen_cookie_t *c;
FILE *result;
c = (fmemopen_cookie_t *) calloc (sizeof (fmemopen_cookie_t), 1);
if (c == NULL)
return NULL;
c->mybuffer = (buf == NULL);
if (c->mybuffer)
{
c->buffer = (char *) malloc (len);
if (c->buffer == NULL)
{
free (c);
return NULL;
}
c->buffer[0] = '\0';
}
else
{
if (__glibc_unlikely ((uintptr_t) len > -(uintptr_t) buf))
* libio/fmemopen.c (fmemopen): Free stream memory in case of invalid length [Coverity CID 106]. * nss/nss_files/files-key.c (search): Close stream before successful return [Coverity CID 107]. * io/fts.c (fts_open): Don't allocate parent if *argv==NULL [Coverity CID 108]. * sunrpc/rpc_cout.c (inline_struct): Free sizestr after use [Coverity CID 110, 109]. * sunrpc/rpc_scan.c (docppline): Free file string if it is not going to be used [Coverity CID 111]. * sysdeps/unix/sysv/linux/getsourcefilter.c (getsourcefilter): Free memory if socket level value cannot be retrieved [Coverity CID 112]. * nis/nis_clone_dir.c (nis_clone_directory): Free all memory in error case [Coverity CID 114]. * nis/nis_clone_res.c (nis_clone_result): Free all memory in the error cases [Coverity CID 115]. * sunrpc/rpc_parse.c (get_definition): Free defp if tok == TOK_EOF [Coverity CID 116]. * sysdeps/unix/sysv/linux/setsourcefilter.c (setsourcefilter): Free memory if socket level value cannot be retrieved [Coverity CID 117]. * elf/cache.c (save_cache): Initialize pad to avoid writing uninitialized data to disk. * elf/cache.c (save_cache): Free file_entries_new [Coverity CID 118]. * intl/finddomain.c (_nl_find_domain): Avoid strdup of expand locale name, use strdupa. Remove free call [Coverity CID 119]. * sunrpc/rpc_main.c (generate_guard): Avoid extra allocation and the resulting leak [Coverity CID 121]. * sunrpc/rpc_main.c (mkfile_output): Free all allocated memory [Coverity CID 122]. * sunrpc/rpc_main.c (h_output): Free guard after we are done [Coverity CID 123]. * sunrpc/svc_udp.c (cache_set): Free victim if newbuf allocation fails [Coverity CID 126]. * sunrpc/svc_udp.c (svcudp_enablecache): Free memory in error cases [Coverity CID 127]. * nis/nis_table.c (__create_ib_request): Free ibreq in case strdup fails [Coverity CID 128]. * nis/nis_getservlist.c (nis_getservlist): Free all memory in case of an error [Coverity CID 130, 129]. * nis/nis_print_group_entry.c (nis_print_group_entry): If nis_lookup call failed, return. Free lookup result in error cases [Coverity CID 131]. * nis/nis_removemember.c (nis_removemember): Free all memory in error cases [Coverity CID 132]. * nis/nss_nisplus/nisplus-alias.c (_nss_nisplus_getaliasbyname_r): Always free lookup result [Coverity CID 134]. * nis/nss_nisplus/nisplus-ethers.c (_nss_nisplus_gethostton_r): Always free lookup result [Coverity CID 135]. * nis/nss_nisplus/nisplus-ethers.c (_nss_nisplus_getntohost_r): Always free lookup result [Coverity CID 136]. * nis/nss_nisplus/nisplus-network.c (_nss_nisplus_getnetbyaddr_r): Before retrying, free old result [Coverity CID 137]. * nis/nss_nisplus/nisplus-publickey.c (_nss_nisplus_netname2user): Free res in case UID is zero [Coverity CID 138]. * nis/ypclnt.c (yp_update): Always free master string [Coverity CID 140]. * nis/nis_creategroup.c (nis_creategroup): Free all memory in error cases [Coverity CID 143, 142, 141]. * nis/nss_nis/nis-publickey.c (_nss_nis_getpublickey): Free result if yp_match call succeeded [Coverity CID 155]. * nis/nss_nis/nis-publickey.c (_nss_nis_getsecretkey): Free string allocated in yp_match at all times [Coverity CID 157, 156]. * nscd/nscd.c (write_pid): Close stream also if writing failed [Coverity CID 165]. * nis/nis_table.c (nis_add_entry): Move test for NULL parameter ahead of first use [Coverity CID 167]. * nis/nss_nis/nis-alias.c (_nss_nis_getaliasbyname_r): Move test for NULL parameter ahead of first use [Coverity CID 168]. * intl/finddomain.c (_nl_find_domain): We never return NULL if we found the locale [Coverity CID 169]. * inet/getnameinfo.c (getnameinfo): __getservbyport_r does not set herrno [Coverity CID 178]. * nis/nis_checkpoint.c (nis_checkpoint): Don't access and returned freed object [Coverity CID 182].
2006-04-07 06:29:25 +02:00
{
free (c);
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
__set_errno (EINVAL);
return NULL;
* libio/fmemopen.c (fmemopen): Free stream memory in case of invalid length [Coverity CID 106]. * nss/nss_files/files-key.c (search): Close stream before successful return [Coverity CID 107]. * io/fts.c (fts_open): Don't allocate parent if *argv==NULL [Coverity CID 108]. * sunrpc/rpc_cout.c (inline_struct): Free sizestr after use [Coverity CID 110, 109]. * sunrpc/rpc_scan.c (docppline): Free file string if it is not going to be used [Coverity CID 111]. * sysdeps/unix/sysv/linux/getsourcefilter.c (getsourcefilter): Free memory if socket level value cannot be retrieved [Coverity CID 112]. * nis/nis_clone_dir.c (nis_clone_directory): Free all memory in error case [Coverity CID 114]. * nis/nis_clone_res.c (nis_clone_result): Free all memory in the error cases [Coverity CID 115]. * sunrpc/rpc_parse.c (get_definition): Free defp if tok == TOK_EOF [Coverity CID 116]. * sysdeps/unix/sysv/linux/setsourcefilter.c (setsourcefilter): Free memory if socket level value cannot be retrieved [Coverity CID 117]. * elf/cache.c (save_cache): Initialize pad to avoid writing uninitialized data to disk. * elf/cache.c (save_cache): Free file_entries_new [Coverity CID 118]. * intl/finddomain.c (_nl_find_domain): Avoid strdup of expand locale name, use strdupa. Remove free call [Coverity CID 119]. * sunrpc/rpc_main.c (generate_guard): Avoid extra allocation and the resulting leak [Coverity CID 121]. * sunrpc/rpc_main.c (mkfile_output): Free all allocated memory [Coverity CID 122]. * sunrpc/rpc_main.c (h_output): Free guard after we are done [Coverity CID 123]. * sunrpc/svc_udp.c (cache_set): Free victim if newbuf allocation fails [Coverity CID 126]. * sunrpc/svc_udp.c (svcudp_enablecache): Free memory in error cases [Coverity CID 127]. * nis/nis_table.c (__create_ib_request): Free ibreq in case strdup fails [Coverity CID 128]. * nis/nis_getservlist.c (nis_getservlist): Free all memory in case of an error [Coverity CID 130, 129]. * nis/nis_print_group_entry.c (nis_print_group_entry): If nis_lookup call failed, return. Free lookup result in error cases [Coverity CID 131]. * nis/nis_removemember.c (nis_removemember): Free all memory in error cases [Coverity CID 132]. * nis/nss_nisplus/nisplus-alias.c (_nss_nisplus_getaliasbyname_r): Always free lookup result [Coverity CID 134]. * nis/nss_nisplus/nisplus-ethers.c (_nss_nisplus_gethostton_r): Always free lookup result [Coverity CID 135]. * nis/nss_nisplus/nisplus-ethers.c (_nss_nisplus_getntohost_r): Always free lookup result [Coverity CID 136]. * nis/nss_nisplus/nisplus-network.c (_nss_nisplus_getnetbyaddr_r): Before retrying, free old result [Coverity CID 137]. * nis/nss_nisplus/nisplus-publickey.c (_nss_nisplus_netname2user): Free res in case UID is zero [Coverity CID 138]. * nis/ypclnt.c (yp_update): Always free master string [Coverity CID 140]. * nis/nis_creategroup.c (nis_creategroup): Free all memory in error cases [Coverity CID 143, 142, 141]. * nis/nss_nis/nis-publickey.c (_nss_nis_getpublickey): Free result if yp_match call succeeded [Coverity CID 155]. * nis/nss_nis/nis-publickey.c (_nss_nis_getsecretkey): Free string allocated in yp_match at all times [Coverity CID 157, 156]. * nscd/nscd.c (write_pid): Close stream also if writing failed [Coverity CID 165]. * nis/nis_table.c (nis_add_entry): Move test for NULL parameter ahead of first use [Coverity CID 167]. * nis/nss_nis/nis-alias.c (_nss_nis_getaliasbyname_r): Move test for NULL parameter ahead of first use [Coverity CID 168]. * intl/finddomain.c (_nl_find_domain): We never return NULL if we found the locale [Coverity CID 169]. * inet/getnameinfo.c (getnameinfo): __getservbyport_r does not set herrno [Coverity CID 178]. * nis/nis_checkpoint.c (nis_checkpoint): Don't access and returned freed object [Coverity CID 182].
2006-04-07 06:29:25 +02:00
}
c->buffer = buf;
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
/* POSIX states that w+ mode should truncate the buffer. */
if (mode[0] == 'w' && mode[1] == '+')
2011-03-04 06:49:46 +01:00
c->buffer[0] = '\0';
if (mode[0] == 'a')
c->maxpos = strnlen (c->buffer, len);
2011-03-04 06:49:46 +01:00
}
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
/* Mode | starting position (cookie::pos) | size (cookie::size)
------ |----------------------------------|-----------------------------
read | beginning of the buffer | size argument
write | beginning of the buffer | zero
append | first null or size buffer + 1 | first null or size argument
*/
2011-03-04 06:49:46 +01:00
c->size = len;
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
if (mode[0] == 'r')
c->maxpos = len;
c->append = mode[0] == 'a';
if (c->append)
c->pos = c->maxpos;
else
c->pos = 0;
iof.read = fmemopen_read;
iof.write = fmemopen_write;
iof.seek = fmemopen_seek;
iof.close = fmemopen_close;
result = _IO_fopencookie (c, mode, iof);
if (__glibc_unlikely (result == NULL))
{
if (c->mybuffer)
free (c->buffer);
free (c);
}
return result;
}
libio: fmemopen rewrite to POSIX compliance This patch added a new fmemopen version, for glibc 2.22, that aims to be POSIX complaint. It fixes some long-stading glibc fmemopen issues, such as: * it changes the way fseek with SEEK_END works on fmemopen to seek relative to buffer size instead of first '\0'. This is default mode and 'b' opening mode does not change internal behavior (bz#6544). * fix apending opening mode to use as start position either first null byte of len specified in function call (bz#13152 and #13151). * remove binary option 'b' and internal different handling (bz#12836) * fix seek/SEE_END with negative values (bz#14292). A compatibility symbol is provided to with old behavior for older symbols version (2.2.5). * include/stdio.h (fmemopen): Remove hidden prototype. (__fmemopen): Add new hidden prototype. * libio/Makefile: Add oldfmemopen object. * libio/Versions [GLIBC_2.22]: Add new fmemopen symbol. * libio/fmemopen.c (__fmemopen): Function rewrite to be POSIX compliance. * libio/oldfmemopen.c: New file: old fmemopen implementation for symbol compatibility. * stdio-common/Makefile [tests]: Add new tst-fmemopen3. * stdio-common/psiginfo.c [psiginfo]: Call __fmemopen instead of fmemopen. * stdio-common/tst-fmemopen3.c: New file: more fmemopen tests, focus on append and read mode. * sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.22]: Add fmemopen. * sysdeps/unix/sysv/linux/alpha/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist [GLIBC_2.22]: Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist [GLIBC_2.22]: Likewise.
2014-06-09 21:19:25 +02:00
libc_hidden_def (__fmemopen)
versioned_symbol (libc, __fmemopen, fmemopen, GLIBC_2_22);