diff options
Diffstat (limited to 'libio')
62 files changed, 528 insertions, 1739 deletions
diff --git a/libio/Makefile b/libio/Makefile index 553fbda74a..a97623f14a 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1995-2002,2003,2004,2006 Free Software Foundation, Inc. +# Copyright (C) 1995-2002, 2003, 2004 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 @@ -22,7 +22,7 @@ subdir := libio headers := stdio.h libio.h _G_config.h bits/stdio.h bits/stdio-lock.h \ - bits/sys_errlist.h bits/stdio2.h bits/stdio-ldbl.h bits/libio-ldbl.h + bits/sys_errlist.h bits/stdio2.h routines := \ filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \ @@ -35,7 +35,7 @@ routines := \ iofputws iofputws_u iogetwline iowpadn ioungetwc putwc putwc_u \ putwchar putwchar_u putchar putchar_u fwprintf swprintf vwprintf \ wprintf wscanf fwscanf vwscanf vswprintf iovswscanf swscanf wgenops \ - wstrops wfileops iofwide fwide wmemstream \ + wstrops wfileops iofwide fwide \ \ clearerr feof ferror fileno fputc freopen fseek getc getchar \ memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \ @@ -54,11 +54,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \ tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \ tst-mmap2-eofsync tst-mmap-offend bug-fopena+ bug-wfflush \ - bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \ - tst-memstream1 tst-memstream2 \ - tst-wmemstream1 tst-wmemstream2 \ - bug-memstream1 bug-wmemstream1 \ - tst-setvbuf1 + bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 test-srcs = test-freopen all: # Make this the default target; it will be defined in Rules. diff --git a/libio/Versions b/libio/Versions index e7a96daca5..c870494872 100644 --- a/libio/Versions +++ b/libio/Versions @@ -145,9 +145,6 @@ libc { # w* wprintf; wscanf; } - GLIBC_2.4 { - open_wmemstream; - } GLIBC_PRIVATE { # Used by NPTL and librt __libc_fatal; diff --git a/libio/bits/libio-ldbl.h b/libio/bits/libio-ldbl.h deleted file mode 100644 index 8674bcb0b8..0000000000 --- a/libio/bits/libio-ldbl.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -mlong-double-64 compatibility mode for libio functions. - Copyright (C) 2006 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _IO_STDIO_H -# error "Never include <bits/libio-ldbl.h> directly; use <libio.h> instead." -#endif - -__LDBL_REDIR_DECL (_IO_vfscanf) -__LDBL_REDIR_DECL (_IO_vfprintf) diff --git a/libio/bits/stdio-ldbl.h b/libio/bits/stdio-ldbl.h deleted file mode 100644 index 7a4291225e..0000000000 --- a/libio/bits/stdio-ldbl.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -mlong-double-64 compatibility mode for stdio functions. - Copyright (C) 2006 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _STDIO_H -# error "Never include <bits/stdio-ldbl.h> directly; use <stdio.h> instead." -#endif - -__BEGIN_NAMESPACE_STD -__LDBL_REDIR_DECL (fprintf) -__LDBL_REDIR_DECL (printf) -__LDBL_REDIR_DECL (sprintf) -__LDBL_REDIR_DECL (vfprintf) -__LDBL_REDIR_DECL (vprintf) -__LDBL_REDIR_DECL (vsprintf) -__LDBL_REDIR_DECL (fscanf) -__LDBL_REDIR_DECL (scanf) -__LDBL_REDIR_DECL (sscanf) -__END_NAMESPACE_STD - -#if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 -__BEGIN_NAMESPACE_C99 -__LDBL_REDIR_DECL (snprintf) -__LDBL_REDIR_DECL (vsnprintf) -__END_NAMESPACE_C99 -#endif - -#ifdef __USE_ISOC99 -__BEGIN_NAMESPACE_C99 -__LDBL_REDIR_DECL (vfscanf) -__LDBL_REDIR_DECL (vsscanf) -__LDBL_REDIR_DECL (vscanf) -__END_NAMESPACE_C99 -#endif - -#ifdef __USE_GNU -__LDBL_REDIR_DECL (vdprintf) -__LDBL_REDIR_DECL (dprintf) -__LDBL_REDIR_DECL (vasprintf) -__LDBL_REDIR_DECL (__asprintf) -__LDBL_REDIR_DECL (asprintf) -__LDBL_REDIR_DECL (obstack_printf) -__LDBL_REDIR_DECL (obstack_vprintf) -#endif - -#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus -__LDBL_REDIR_DECL (__sprintf_chk) -__LDBL_REDIR_DECL (__vsprintf_chk) -# if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 -__LDBL_REDIR_DECL (__snprintf_chk) -__LDBL_REDIR_DECL (__vsnprintf_chk) -# endif -# if __USE_FORTIFY_LEVEL > 1 -__LDBL_REDIR_DECL (__fprintf_chk) -__LDBL_REDIR_DECL (__printf_chk) -__LDBL_REDIR_DECL (__vfprintf_chk) -__LDBL_REDIR_DECL (__vprintf_chk) -# endif -#endif diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h index 2d44fad1f5..9e951ad8e4 100644 --- a/libio/bits/stdio.h +++ b/libio/bits/stdio.h @@ -1,5 +1,5 @@ /* Optimizing macros and inline functions for stdio functions. - Copyright (C) 1998, 2000, 2001, 2004, 2007 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2001, 2004 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 @@ -44,16 +44,6 @@ getchar (void) } -# ifdef __USE_MISC -/* Faster version when locking is not necessary. */ -__STDIO_INLINE int -fgetc_unlocked (FILE *__fp) -{ - return _IO_getc_unlocked (__fp); -} -# endif /* misc */ - - # if defined __USE_POSIX || defined __USE_MISC /* This is defined in POSIX.1:1996. */ __STDIO_INLINE int diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index f1d745c699..acf07ea91b 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -1,5 +1,5 @@ /* Checking macros for stdio functions. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004 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 @@ -49,7 +49,7 @@ extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, __builtin___vsnprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \ fmt, ap) -#endif +#endif #if __USE_FORTIFY_LEVEL > 1 @@ -61,67 +61,18 @@ extern int __vfprintf_chk (FILE *__restrict __stream, int __flag, extern int __vprintf_chk (int __flag, __const char *__restrict __format, _G_va_list __ap); -# if __GNUC_PREREQ (4, 0) -# define printf(...) \ +# define printf(...) \ __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define fprintf(stream, ...) \ +# define fprintf(stream, ...) \ __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define vprintf(format, ap) \ +# define vprintf(format, ap) \ __vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap) -# define vfprintf(stream, format, ap) \ +# define vfprintf(stream, format, ap) \ __vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap) -# else -# define printf(...) \ - __builtin___printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define fprintf(stream, ...) \ - __builtin___fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -# define vprintf(format, ap) \ - __builtin___vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap) -# define vfprintf(stream, format, ap) \ - __builtin___vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap) -# endif #endif -extern char *__gets_chk (char *__str, size_t) __wur; -extern char *__REDIRECT (__gets_alias, (char *__str), gets) __wur; - -extern __always_inline __wur char * -gets (char *__str) -{ - if (__bos (__str) != (size_t) -1) - return __gets_chk (__str, __bos (__str)); - return __gets_alias (__str); -} - -extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, - FILE *__restrict __stream) __wur; -extern char *__REDIRECT (__fgets_alias, - (char *__restrict __s, int __n, - FILE *__restrict __stream), fgets) __wur; - -extern __always_inline __wur char * -fgets (char *__restrict __s, int __n, FILE *__restrict __stream) -{ - if (__bos (__s) != (size_t) -1 - && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) - return __fgets_chk (__s, __bos (__s), __n, __stream); - return __fgets_alias (__s, __n, __stream); -} - -#ifdef __USE_GNU -extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, - int __n, FILE *__restrict __stream) __wur; -extern char *__REDIRECT (__fgets_unlocked_alias, - (char *__restrict __s, int __n, - FILE *__restrict __stream), fgets_unlocked) __wur; - -extern __always_inline __wur char * -fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) -{ - if (__bos (__s) != (size_t) -1 - && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) - return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream); - return __fgets_unlocked_alias (__s, __n, __stream); -} -#endif +extern char *__gets_chk (char *__str, size_t); +#define gets(__str) \ + ((__bos (__str) == (size_t) -1) \ + ? (gets) (__str) : __gets_chk (__str, __bos (__str))) diff --git a/libio/bug-memstream1.c b/libio/bug-memstream1.c deleted file mode 100644 index 8af36fee2d..0000000000 --- a/libio/bug-memstream1.c +++ /dev/null @@ -1,133 +0,0 @@ -#include <stdio.h> -#include <string.h> - - -static int -do_test (void) -{ - size_t size; - char *buf; - FILE *fp = open_memstream (&buf, &size); - if (fp == NULL) - { - puts ("open_memstream failed"); - return 1; - } - - off64_t off = ftello64 (fp); - if (off != 0) - { - puts ("initial position wrong"); - return 1; - } - - if (fseek (fp, 32768, SEEK_SET) != 0) - { - puts ("fseek failed"); - return 1; - } - - if (fputs ("foo", fp) == EOF) - { - puts ("fputs failed"); - return 1; - } - - if (fclose (fp) == EOF) - { - puts ("fclose failed"); - return 1; - } - - if (size != 32768 + 3) - { - printf ("expected size %d, got %zu\n", 32768 + 3, size); - return 1; - } - - for (int i = 0; i < 32768; ++i) - if (buf[i] != '\0') - { - printf ("byte at offset %d is %#hhx\n", i, buf[i]); - return 1; - } - - if (memcmp (buf + 32768, "foo", 3) != 0) - { - puts ("written string incorrect"); - return 1; - } - - /* Mark the buffer. */ - memset (buf, 'A', size); - free (buf); - - /* Try again, this time with write mode enabled before the seek. */ - fp = open_memstream (&buf, &size); - if (fp == NULL) - { - puts ("2nd open_memstream failed"); - return 1; - } - - off = ftello64 (fp); - if (off != 0) - { - puts ("2nd initial position wrong"); - return 1; - } - - if (fputs ("bar", fp) == EOF) - { - puts ("2nd fputs failed"); - return 1; - } - - if (fseek (fp, 32768, SEEK_SET) != 0) - { - puts ("2nd fseek failed"); - return 1; - } - - if (fputs ("foo", fp) == EOF) - { - puts ("3rd fputs failed"); - return 1; - } - - if (fclose (fp) == EOF) - { - puts ("2nd fclose failed"); - return 1; - } - - if (size != 32768 + 3) - { - printf ("2nd expected size %d, got %zu\n", 32768 + 3, size); - return 1; - } - - if (memcmp (buf, "bar", 3) != 0) - { - puts ("initial string incorrect in 2nd try"); - return 1; - } - - for (int i = 3; i < 32768; ++i) - if (buf[i] != '\0') - { - printf ("byte at offset %d is %#hhx in 2nd try\n", i, buf[i]); - return 1; - } - - if (memcmp (buf + 32768, "foo", 3) != 0) - { - puts ("written string incorrect in 2nd try"); - return 1; - } - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/libio/bug-wmemstream1.c b/libio/bug-wmemstream1.c deleted file mode 100644 index 22d67f71e9..0000000000 --- a/libio/bug-wmemstream1.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <wchar.h> - - -static int -do_test (void) -{ - size_t size; - wchar_t *buf; - FILE *fp = open_wmemstream (&buf, &size); - if (fp == NULL) - { - puts ("open_wmemstream failed"); - return 1; - } - - off64_t off = ftello64 (fp); - if (off != 0) - { - puts ("initial position wrong"); - return 1; - } - - if (fseek (fp, 32768, SEEK_SET) != 0) - { - puts ("fseek failed"); - return 1; - } - - if (fputws (L"foo", fp) == EOF) - { - puts ("fputws failed"); - return 1; - } - - if (fclose (fp) == EOF) - { - puts ("fclose failed"); - return 1; - } - - if (size != 32768 + 3) - { - printf ("expected size %d, got %zu\n", 32768 + 3, size); - return 1; - } - - for (int i = 0; i < 32768; ++i) - if (buf[i] != L'\0') - { - printf ("wide character at offset %d is %#x\n", - i, (unsigned int) buf[i]); - return 1; - } - - if (wmemcmp (buf + 32768, L"foo", 3) != 0) - { - puts ("written string incorrect"); - return 1; - } - - /* Mark the buffer. */ - wmemset (buf, L'A', size); - free (buf); - - /* Try again, this time with write mode enabled before the seek. */ - fp = open_wmemstream (&buf, &size); - if (fp == NULL) - { - puts ("2nd open_wmemstream failed"); - return 1; - } - - off = ftello64 (fp); - if (off != 0) - { - puts ("2nd initial position wrong"); - return 1; - } - - if (fputws (L"bar", fp) == EOF) - { - puts ("2nd fputws failed"); - return 1; - } - - if (fseek (fp, 32768, SEEK_SET) != 0) - { - puts ("2nd fseek failed"); - return 1; - } - - if (fputws (L"foo", fp) == EOF) - { - puts ("3rd fputws failed"); - return 1; - } - - if (fclose (fp) == EOF) - { - puts ("2nd fclose failed"); - return 1; - } - - if (size != 32768 + 3) - { - printf ("2nd expected size %d, got %zu\n", 32768 + 3, size); - return 1; - } - - if (wmemcmp (buf, L"bar", 3) != 0) - { - puts ("initial string incorrect in 2nd try"); - return 1; - } - - for (int i = 3; i < 32768; ++i) - if (buf[i] != L'\0') - { - printf ("wide character at offset %d is %#x in 2nd try\n", - i, (unsigned int) buf[i]); - return 1; - } - - if (wmemcmp (buf + 32768, L"foo", 3) != 0) - { - puts ("written string incorrect in 2nd try"); - return 1; - } - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/libio/fileops.c b/libio/fileops.c index 886b3729c3..19151cf188 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2005, 2006, 2007 - Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner <bothner@cygnus.com>. @@ -175,8 +174,14 @@ _IO_new_file_close_it (fp) close_status = _IO_SYSCLOSE (fp); /* Free buffer. */ + if (fp->_mode <= 0) + { + INTUSE(_IO_setb) (fp, NULL, NULL, 0); + _IO_setg (fp, NULL, NULL, NULL); + _IO_setp (fp, NULL, NULL); + } #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T - if (fp->_mode > 0) + else { if (_IO_have_wbackup (fp)) INTUSE(_IO_free_wbackup_area) (fp); @@ -185,9 +190,6 @@ _IO_new_file_close_it (fp) _IO_wsetp (fp, NULL, NULL); } #endif - INTUSE(_IO_setb) (fp, NULL, NULL, 0); - _IO_setg (fp, NULL, NULL, NULL); - _IO_setp (fp, NULL, NULL); INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp); fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS; @@ -397,9 +399,6 @@ _IO_new_file_fopen (fp, filename, mode, is32not64) /* And now the transliteration. */ cc->__cd_out.__cd.__data[0].__trans = &__libio_translit; - /* From now on use the wide character callback functions. */ - ((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable; - /* Set the mode now. */ result->_mode = 1; } @@ -473,7 +472,7 @@ _IO_file_setbuf_mmap (fp, p, len) return result; } -static _IO_size_t new_do_write (_IO_FILE *, const char *, _IO_size_t); +static _IO_size_t new_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW; /* Write TO_DO bytes from DATA to FP. Then mark FP as having empty buffers. */ @@ -827,10 +826,10 @@ _IO_new_file_overflow (f, ch) return EOF; } /* If currently reading or no buffer allocated. */ - if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == NULL) + if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == 0) { /* Allocate a buffer if needed. */ - if (f->_IO_write_base == NULL) + if (f->_IO_write_base == 0) { INTUSE(_IO_doallocbuf) (f); _IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base); @@ -1282,7 +1281,7 @@ _IO_new_file_xsputn (f, data, n) register const char *s = (const char *) data; _IO_size_t to_do = n; int must_flush = 0; - _IO_size_t count = 0; + _IO_size_t count; if (n <= 0) return 0; @@ -1291,6 +1290,7 @@ _IO_new_file_xsputn (f, data, n) (or the filebuf is unbuffered), use sys_write directly. */ /* First figure out how much space is available in the buffer. */ + count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING)) { count = f->_IO_buf_end - f->_IO_write_ptr; @@ -1308,9 +1308,6 @@ _IO_new_file_xsputn (f, data, n) } } } - else if (f->_IO_write_end > f->_IO_write_ptr) - count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ - /* Then fill the buffer. */ if (count > 0) { @@ -1341,9 +1338,7 @@ _IO_new_file_xsputn (f, data, n) _IO_size_t block_size, do_write; /* Next flush the (full) buffer. */ if (_IO_OVERFLOW (f, EOF) == EOF) - /* If nothing else has to be written we must not signal the - caller that everything has been written. */ - return to_do == 0 ? EOF : n - to_do; + return n - to_do; /* Try to maintain alignment: write a whole number of blocks. dont_write is what gets left over. */ @@ -1469,7 +1464,8 @@ _IO_file_xsgetn (fp, data, n) } INTDEF(_IO_file_xsgetn) -static _IO_size_t _IO_file_xsgetn_mmap (_IO_FILE *, void *, _IO_size_t); +static _IO_size_t _IO_file_xsgetn_mmap (_IO_FILE *, void *, _IO_size_t) + __THROW; static _IO_size_t _IO_file_xsgetn_mmap (fp, data, n) _IO_FILE *fp; @@ -1528,7 +1524,8 @@ _IO_file_xsgetn_mmap (fp, data, n) return s - (char *) data; } -static _IO_size_t _IO_file_xsgetn_maybe_mmap (_IO_FILE *, void *, _IO_size_t); +static _IO_size_t _IO_file_xsgetn_maybe_mmap (_IO_FILE *, void *, _IO_size_t) + __THROW; static _IO_size_t _IO_file_xsgetn_maybe_mmap (fp, data, n) _IO_FILE *fp; diff --git a/libio/fmemopen.c b/libio/fmemopen.c index f3b280092c..ab6ffdd678 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -1,5 +1,5 @@ /* Fmemopen implementation. - Copyright (C) 2000, 2002, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2000, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Hanno Mueller, kontakt@hanno.de, 2000. @@ -27,6 +27,8 @@ * but couldn't find it in libio. The following snippet of code is an * attempt to implement what glibc's documentation describes. * + * No, it isn't really tested yet. :-) + * * * * I already see some potential problems: @@ -71,7 +73,6 @@ #include <libio.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> #include <sys/types.h> #include "libioP.h" @@ -127,7 +128,7 @@ fmemopen_write (void *cookie, const char *b, size_t s) if ((size_t) (c->pos + addnullc) == c->size) { __set_errno (ENOSPC); - return 0; + return -1; } s = c->size - c->pos - addnullc; } @@ -165,7 +166,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) break; case SEEK_END: - np = c->maxpos - *p; + np = c->size - *p; break; default: @@ -175,9 +176,9 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) if (np < 0 || (size_t) np > c->size) return -1; - *p = c->pos = np; + c->pos = np; - return 0; + return np; } @@ -202,13 +203,6 @@ fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; - if (__builtin_expect (len == 0, 0)) - { - einval: - __set_errno (EINVAL); - return NULL; - } - c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); if (c == NULL) return NULL; @@ -226,15 +220,7 @@ fmemopen (void *buf, size_t len, const char *mode) c->buffer[0] = '\0'; } else - { - if (__builtin_expect ((uintptr_t) len > -(uintptr_t) buf, 0)) - { - free (c); - goto einval; - } - - c->buffer = buf; - } + c->buffer = buf; c->size = len; diff --git a/libio/fputwc.c b/libio/fputwc.c index 42cf9d716c..8c749435a0 100644 --- a/libio/fputwc.c +++ b/libio/fputwc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1996,1997,1998,1999,2003, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993,1996,1997,1998,1999,2003 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 @@ -33,7 +33,7 @@ fputwc (wc, fp) wchar_t wc; _IO_FILE *fp; { - wint_t result; + int result; CHECK_FILE (fp, EOF); _IO_acquire_lock (fp); if (_IO_fwide (fp, 1) < 0) diff --git a/libio/fputwc_u.c b/libio/fputwc_u.c index 0478410cca..93cbcab3d3 100644 --- a/libio/fputwc_u.c +++ b/libio/fputwc_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1999, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1996, 1997, 1999 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 @@ -35,7 +35,7 @@ fputwc_unlocked (wc, fp) wchar_t wc; _IO_FILE *fp; { - CHECK_FILE (fp, WEOF); + CHECK_FILE (fp, EOF); if (_IO_fwide (fp, 1) < 0) return WEOF; return _IO_putwc_unlocked (wc, fp); diff --git a/libio/fwprintf.c b/libio/fwprintf.c index 9d9111d7c6..cadeda04ab 100644 --- a/libio/fwprintf.c +++ b/libio/fwprintf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991, 1997, 1999, 2000, 2001, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1991, 1997, 1999, 2000, 2001 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 @@ -17,7 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -37,4 +35,4 @@ __fwprintf (FILE *stream, const wchar_t *format, ...) return done; } -ldbl_weak_alias (__fwprintf, fwprintf) +weak_alias (__fwprintf, fwprintf) diff --git a/libio/fwscanf.c b/libio/fwscanf.c index 17296fa3d6..411e1825c0 100644 --- a/libio/fwscanf.c +++ b/libio/fwscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1997, 1999, 2000, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1997, 1999, 2000 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 @@ -16,7 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -24,7 +23,7 @@ /* Read formatted input from STREAM according to the format string FORMAT. */ /* VARARGS2 */ int -__fwscanf (FILE *stream, const wchar_t *format, ...) +fwscanf (FILE *stream, const wchar_t *format, ...) { va_list arg; int done; @@ -35,4 +34,3 @@ __fwscanf (FILE *stream, const wchar_t *format, ...) return done; } -ldbl_strong_alias (__fwscanf, fwscanf) diff --git a/libio/genops.c b/libio/genops.c index 8d62da7781..741ed77f86 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2002, 2003, 2004, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2002, 2003, 2004 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 @@ -33,10 +32,6 @@ #include <stdlib.h> #endif #include <string.h> -#include <stdbool.h> -#ifdef _LIBC -#include <sched.h> -#endif #ifdef _IO_MTSAFE_IO static _IO_lock_t list_all_lock = _IO_lock_initializer; @@ -367,7 +362,7 @@ __uflow (fp) #endif if (fp->_mode == 0) - _IO_fwide (fp, -1); + _IO_fwide (fp, -11); if (_IO_in_put_mode (fp)) if (INTUSE(_IO_switch_to_get_mode) (fp) == EOF) return EOF; @@ -662,7 +657,6 @@ _IO_no_init (fp, flags, orientation, wd, jmp) fp->_wide_data->_wide_vtable = jmp; } #endif - fp->_freeres_list = NULL; } int @@ -920,27 +914,10 @@ INTDEF(_IO_flush_all_linebuffered) weak_alias (_IO_flush_all_linebuffered, _flushlbf) #endif - -/* The following is a bit tricky. In general, we want to unbuffer the - streams so that all output which follows is seen. If we are not - looking for memory leaks it does not make much sense to free the - actual buffer because this will happen anyway once the program - terminated. If we do want to look for memory leaks we have to free - the buffers. Whether something is freed is determined by the - function sin the libc_freeres section. Those are called as part of - the atexit routine, just like _IO_cleanup. The problem is we do - not know whether the freeres code is called first or _IO_cleanup. - if the former is the case, we set the DEALLOC_BUFFER variable to - true and _IO_unbuffer_write will take care of the rest. If - _IO_unbuffer_write is called first we add the streams to a list - which the freeres function later can walk through. */ static void _IO_unbuffer_write (void); -static bool dealloc_buffers; -static _IO_FILE *freeres_list; - static void -_IO_unbuffer_write (void) +_IO_unbuffer_write () { struct _IO_FILE *fp; for (fp = (_IO_FILE *) INTUSE(_IO_list_all); fp; fp = fp->_chain) @@ -950,32 +927,7 @@ _IO_unbuffer_write (void) || (fp->_flags & _IO_IS_APPENDING)) /* Iff stream is un-orientated, it wasn't used. */ && fp->_mode != 0) - { - int cnt; -#define MAXTRIES 2 - for (cnt = 0; cnt < MAXTRIES; ++cnt) - if (_IO_lock_trylock (*fp->_lock) == 0) - break; - else - /* Give the other thread time to finish up its use of the - stream. */ - __sched_yield (); - - if (! dealloc_buffers && !(fp->_flags & _IO_USER_BUF)) - { - fp->_flags |= _IO_USER_BUF; - - fp->_freeres_list = freeres_list; - freeres_list = fp; - fp->_freeres_buf = fp->_IO_buf_base; - fp->_freeres_size = _IO_blen (fp); - } - - _IO_SETBUF (fp, NULL, 0); - - if (cnt < MAXTRIES) - _IO_lock_unlock (*fp->_lock); - } + _IO_SETBUF (fp, NULL, 0); /* Make sure that never again the wide char functions can be used. */ @@ -983,25 +935,11 @@ _IO_unbuffer_write (void) } } - -libc_freeres_fn (buffer_free) -{ - dealloc_buffers = true; - - while (freeres_list != NULL) - { - FREE_BUF (freeres_list->_freeres_buf, freeres_list->_freeres_size); - - freeres_list = freeres_list->_freeres_list; - } -} - - int _IO_cleanup () { /* We do *not* want locking. Some threads might use streams but - that is their problem, we flush them underneath them. */ + that is there problem, we flush them underneath them. */ int result = _IO_flush_all_lockp (0); /* We currently don't have a reliable mechanism for making sure that diff --git a/libio/getwc_u.c b/libio/getwc_u.c index 229343cc61..bdad3c8bf3 100644 --- a/libio/getwc_u.c +++ b/libio/getwc_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1996,1997,1999,2000, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1996,1997,1999,2000 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 @@ -33,7 +33,7 @@ wint_t __getwc_unlocked (FILE *fp) { - CHECK_FILE (fp, WEOF); + CHECK_FILE (fp, EOF); return _IO_getwc_unlocked (fp); } diff --git a/libio/iofclose.c b/libio/iofclose.c index aa2ba40064..a372ae2b24 100644 --- a/libio/iofclose.c +++ b/libio/iofclose.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2003,2004 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 @@ -62,8 +62,8 @@ _IO_new_fclose (fp) status = INTUSE(_IO_file_close_it) (fp); else status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; - _IO_release_lock (fp); _IO_FINISH (fp); + _IO_release_lock (fp); if (fp->_mode > 0) { #if _LIBC diff --git a/libio/iofgets.c b/libio/iofgets.c index 601b1746a1..879cc975a3 100644 --- a/libio/iofgets.c +++ b/libio/iofgets.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005 +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -41,14 +41,6 @@ _IO_fgets (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; - if (__builtin_expect (n == 1, 0)) - { - /* Another irregular case: since we have to store a NUL byte and - there is only room for exactly one byte, we don't have to - read anything. */ - buf[0] = '\0'; - return buf; - } _IO_acquire_lock (fp); /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this diff --git a/libio/iofgets_u.c b/libio/iofgets_u.c index 4fb5b1c0fd..ded2a7c83c 100644 --- a/libio/iofgets_u.c +++ b/libio/iofgets_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995-1998,2002,2005 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1996,1997,1998,2002 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 @@ -40,14 +40,6 @@ fgets_unlocked (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; - if (__builtin_expect (n == 1, 0)) - { - /* Another irregular case: since we have to store a NUL byte and - there is only room for exactly one byte, we don't have to - read anything. */ - buf[0] = '\0'; - return buf; - } /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ diff --git a/libio/iofgetws.c b/libio/iofgetws.c index 775391137a..654c051a28 100644 --- a/libio/iofgetws.c +++ b/libio/iofgetws.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2001, 2005 +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -41,14 +41,6 @@ fgetws (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; - if (__builtin_expect (n == 1, 0)) - { - /* Another irregular case: since we have to store a NUL byte and - there is only room for exactly one byte, we don't have to - read anything. */ - buf[0] = L'\0'; - return buf; - } _IO_acquire_lock (fp); /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this diff --git a/libio/iofgetws_u.c b/libio/iofgetws_u.c index 9fb8a5cac1..1253564566 100644 --- a/libio/iofgetws_u.c +++ b/libio/iofgetws_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 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 @@ -40,14 +40,6 @@ fgetws_unlocked (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; - if (__builtin_expect (n == 1, 0)) - { - /* Another irregular case: since we have to store a NUL byte and - there is only room for exactly one byte, we don't have to - read anything. */ - buf[0] = L'\0'; - return buf; - } /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ diff --git a/libio/iofopncook.c b/libio/iofopncook.c index 976ff5093a..321eb67b8d 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993,95,97,99,2000,2002,2004, 2005 - Free Software Foundation, Inc. +/* Copyright (C) 1993,95,97,99,2000,2002,2004 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 @@ -37,8 +36,6 @@ static _IO_ssize_t _IO_cookie_read (register _IO_FILE* fp, void* buf, static _IO_ssize_t _IO_cookie_write (register _IO_FILE* fp, const void* buf, _IO_ssize_t size); static _IO_off64_t _IO_cookie_seek (_IO_FILE *fp, _IO_off64_t offset, int dir); -static _IO_off64_t _IO_cookie_seekoff (_IO_FILE *fp, _IO_off64_t offset, - int dir, int mode); static int _IO_cookie_close (_IO_FILE* fp); static _IO_ssize_t @@ -64,16 +61,9 @@ _IO_cookie_write (fp, buf, size) struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; if (cfile->__io_functions.write == NULL) - { - fp->_flags |= _IO_ERR_SEEN; - return 0; - } - - _IO_ssize_t n = cfile->__io_functions.write (cfile->__cookie, buf, size); - if (n < size) - fp->_flags |= _IO_ERR_SEEN; + return -1; - return n; + return cfile->__io_functions.write (cfile->__cookie, buf, size); } static _IO_off64_t @@ -104,20 +94,6 @@ _IO_cookie_close (fp) } -static _IO_off64_t -_IO_cookie_seekoff (fp, offset, dir, mode) - _IO_FILE *fp; - _IO_off64_t offset; - int dir; - int mode; -{ - /* We must force the fileops code to always use seek to determine - the position. */ - fp->_offset = _IO_pos_BAD; - return INTUSE(_IO_file_seekoff) (fp, offset, dir, mode); -} - - static const struct _IO_jump_t _IO_cookie_jumps = { JUMP_INIT_DUMMY, JUMP_INIT(finish, INTUSE(_IO_file_finish)), @@ -127,7 +103,7 @@ static const struct _IO_jump_t _IO_cookie_jumps = { JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)), JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)), JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)), - JUMP_INIT(seekoff, _IO_cookie_seekoff), + JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)), JUMP_INIT(seekpos, _IO_default_seekpos), JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)), JUMP_INIT(sync, INTUSE(_IO_file_sync)), @@ -247,7 +223,7 @@ static const struct _IO_jump_t _IO_old_cookie_jumps = { JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)), JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)), JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)), - JUMP_INIT(seekoff, _IO_cookie_seekoff), + JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)), JUMP_INIT(seekpos, _IO_default_seekpos), JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)), JUMP_INIT(sync, INTUSE(_IO_file_sync)), diff --git a/libio/iofwide.c b/libio/iofwide.c index a9936687dd..03124219ad 100644 --- a/libio/iofwide.c +++ b/libio/iofwide.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999-2003, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2000, 2001, 2002, 2003 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 @@ -40,7 +40,6 @@ # include <wcsmbs/wcsmbsload.h> # include <iconv/gconv_int.h> # include <shlib-compat.h> -# include <sysdep.h> #endif @@ -69,7 +68,7 @@ static int do_always_noconv (struct _IO_codecvt *codecvt); /* The functions used in `codecvt' for libio are always the same. */ -const struct _IO_codecvt __libio_codecvt = +struct _IO_codecvt __libio_codecvt = { .__codecvt_destr = NULL, /* Destructor, never used. */ .__codecvt_do_out = do_out, @@ -83,7 +82,7 @@ const struct _IO_codecvt __libio_codecvt = #ifdef _LIBC -const struct __gconv_trans_data __libio_translit attribute_hidden = +struct __gconv_trans_data __libio_translit attribute_hidden = { .__trans_fct = __gconv_transliterate }; @@ -127,11 +126,12 @@ _IO_fwide (fp, mode) selected locale for LC_CTYPE. */ #ifdef _LIBC { + struct gconv_fcts fcts; + /* Clear the state. We start all over again. */ memset (&fp->_wide_data->_IO_state, '\0', sizeof (__mbstate_t)); memset (&fp->_wide_data->_IO_last_state, '\0', sizeof (__mbstate_t)); - struct gconv_fcts fcts; __wcsmbs_clone_conv (&fcts); assert (fcts.towc_nsteps == 1); assert (fcts.tomb_nsteps == 1); @@ -159,8 +159,7 @@ _IO_fwide (fp, mode) cc->__cd_out.__cd.__data[0].__statep = &fp->_wide_data->_IO_state; /* And now the transliteration. */ - cc->__cd_out.__cd.__data[0].__trans - = (struct __gconv_trans_data *) &__libio_translit; + cc->__cd_out.__cd.__data[0].__trans = &__libio_translit; } #else # ifdef _GLIBCPP_USE_WCHAR_T @@ -229,23 +228,17 @@ do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep, size_t dummy; const unsigned char *from_start_copy = (unsigned char *) from_start; - codecvt->__cd_out.__cd.__data[0].__outbuf = (unsigned char *) to_start; - codecvt->__cd_out.__cd.__data[0].__outbufend = (unsigned char *) to_end; + codecvt->__cd_out.__cd.__data[0].__outbuf = to_start; + codecvt->__cd_out.__cd.__data[0].__outbufend = to_end; codecvt->__cd_out.__cd.__data[0].__statep = statep; - __gconv_fct fct = gs->__fct; -#ifdef PTR_DEMANGLE - if (gs->__shlib_handle != NULL) - PTR_DEMANGLE (fct); -#endif - - status = DL_CALL_FCT (fct, + status = DL_CALL_FCT (gs->__fct, (gs, codecvt->__cd_out.__cd.__data, &from_start_copy, (const unsigned char *) from_end, NULL, &dummy, 0, 0)); *from_stop = (wchar_t *) from_start_copy; - *to_stop = (char *) codecvt->__cd_out.__cd.__data[0].__outbuf; + *to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf; switch (status) { @@ -301,21 +294,15 @@ do_unshift (struct _IO_codecvt *codecvt, __mbstate_t *statep, int status; size_t dummy; - codecvt->__cd_out.__cd.__data[0].__outbuf = (unsigned char *) to_start; - codecvt->__cd_out.__cd.__data[0].__outbufend = (unsigned char *) to_end; + codecvt->__cd_out.__cd.__data[0].__outbuf = to_start; + codecvt->__cd_out.__cd.__data[0].__outbufend = to_end; codecvt->__cd_out.__cd.__data[0].__statep = statep; - __gconv_fct fct = gs->__fct; -#ifdef PTR_DEMANGLE - if (gs->__shlib_handle != NULL) - PTR_DEMANGLE (fct); -#endif - - status = DL_CALL_FCT (fct, + status = DL_CALL_FCT (gs->__fct, (gs, codecvt->__cd_out.__cd.__data, NULL, NULL, NULL, &dummy, 1, 0)); - *to_stop = (char *) codecvt->__cd_out.__cd.__data[0].__outbuf; + *to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf; switch (status) { @@ -370,22 +357,15 @@ do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep, size_t dummy; const unsigned char *from_start_copy = (unsigned char *) from_start; - codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *) to_start; - codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *) to_end; + codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_start; + codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) to_end; codecvt->__cd_in.__cd.__data[0].__statep = statep; - __gconv_fct fct = gs->__fct; -#ifdef PTR_DEMANGLE - if (gs->__shlib_handle != NULL) - PTR_DEMANGLE (fct); -#endif - - status = DL_CALL_FCT (fct, + status = DL_CALL_FCT (gs->__fct, (gs, codecvt->__cd_in.__cd.__data, &from_start_copy, - (const unsigned char *) from_end, NULL, - &dummy, 0, 0)); + from_end, NULL, &dummy, 0, 0)); - *from_stop = (const char *) from_start_copy; + *from_stop = from_start_copy; *to_stop = (wchar_t *) codecvt->__cd_in.__cd.__data[0].__outbuf; switch (status) @@ -474,20 +454,13 @@ do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep, int status; size_t dummy; - codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *) to_buf; - codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *) &to_buf[max]; + codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_buf; + codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) &to_buf[max]; codecvt->__cd_in.__cd.__data[0].__statep = statep; - __gconv_fct fct = gs->__fct; -#ifdef PTR_DEMANGLE - if (gs->__shlib_handle != NULL) - PTR_DEMANGLE (fct); -#endif - - status = DL_CALL_FCT (fct, - (gs, codecvt->__cd_in.__cd.__data, &cp, - (const unsigned char *) from_end, NULL, - &dummy, 0, 0)); + status = DL_CALL_FCT (gs->__fct, + (gs, codecvt->__cd_in.__cd.__data, &cp, from_end, + NULL, &dummy, 0, 0)); result = cp - (const unsigned char *) from_start; #else diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c index a362bf978a..3d0c976f9c 100644 --- a/libio/iogetdelim.c +++ b/libio/iogetdelim.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994,1996-1998,2001,2003,2005 Free Software Foundation, Inc. +/* Copyright (C) 1994,1996,1997,1998,2001,2003 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 @@ -45,7 +45,7 @@ _IO_getdelim (lineptr, n, delimiter, fp) int delimiter; _IO_FILE *fp; { - _IO_ssize_t result; + int result; _IO_ssize_t cur_len = 0; _IO_ssize_t len; @@ -91,12 +91,6 @@ _IO_getdelim (lineptr, n, delimiter, fp) t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len); if (t != NULL) len = (t - fp->_IO_read_ptr) + 1; - if (__builtin_expect (cur_len + len + 1 < 0, 0)) - { - __set_errno (EOVERFLOW); - result = -1; - goto unlock_return; - } /* Make enough space for len+1 (for final NUL) bytes. */ needed = cur_len + len + 1; if (needed > *n) diff --git a/libio/iogetline.c b/libio/iogetline.c index 022a444f77..eca38cf773 100644 --- a/libio/iogetline.c +++ b/libio/iogetline.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993,1997,1998,2000,2001,2002,2005 - Free Software Foundation, Inc. +/* Copyright (C) 1993,1997,1998,2000,2001,2002 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 @@ -74,8 +73,7 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof) int c = __uflow (fp); if (c == EOF) { - if (eof) - *eof = c; + if (eof) *eof = c; break; } if (c == delim) @@ -91,31 +89,31 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof) *ptr++ = c; n--; } - else - { - char *t; - if ((_IO_size_t) len >= n) - len = n; - t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len); - if (t != NULL) - { - _IO_size_t old_len = ptr-buf; - len = t - fp->_IO_read_ptr; - if (extract_delim >= 0) - { - ++t; - if (extract_delim > 0) - ++len; - } - memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); - fp->_IO_read_ptr = t; - return old_len + len; - } - memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); - fp->_IO_read_ptr += len; - ptr += len; - n -= len; - } + else + { + char *t; + if ((_IO_size_t) len >= n) + len = n; + t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len); + if (t != NULL) + { + _IO_size_t old_len = ptr-buf; + len = t - fp->_IO_read_ptr; + if (extract_delim >= 0) + { + ++t; + if (extract_delim > 0) + ++len; + } + memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); + fp->_IO_read_ptr = t; + return old_len + len; + } + memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); + fp->_IO_read_ptr += len; + ptr += len; + n -= len; + } } return ptr - buf; } diff --git a/libio/iogetwline.c b/libio/iogetwline.c index 45db478423..e529b7d832 100644 --- a/libio/iogetwline.c +++ b/libio/iogetwline.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1997-2000,2002,2005 Free Software Foundation, Inc. +/* Copyright (C) 1993,1997,1998,1999,2000,2002 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 @@ -87,9 +87,9 @@ _IO_getwline_info (fp, buf, n, delim, extract_delim, eof) *ptr++ = wc; else if (extract_delim < 0) INTUSE(_IO_sputbackc) (fp, wc); + return ptr - buf; if (extract_delim > 0) ++len; - return ptr - buf; } *ptr++ = wc; n--; diff --git a/libio/ioungetwc.c b/libio/ioungetwc.c index f7b6866617..00d3e965b5 100644 --- a/libio/ioungetwc.c +++ b/libio/ioungetwc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2006 +/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -34,7 +34,7 @@ ungetwc (c, fp) wint_t c; _IO_FILE *fp; { - wint_t result; + int result; CHECK_FILE (fp, WEOF); _IO_acquire_lock (fp); _IO_fwide (fp, 1); diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c index edab849a44..e81d870ca7 100644 --- a/libio/iovdprintf.c +++ b/libio/iovdprintf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1995, 1997-2000, 2001, 2002, 2003, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1995,1997-2000,2001,2002,2003 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 @@ -26,7 +25,7 @@ This exception applies to code released by its copyright holders in files containing the exception. */ -#include <libioP.h> +#include "libioP.h" #include <stdio_ext.h> int @@ -64,4 +63,7 @@ _IO_vdprintf (d, format, arg) return done; } -ldbl_weak_alias (_IO_vdprintf, vdprintf) + +#ifdef weak_alias +weak_alias (_IO_vdprintf, vdprintf) +#endif diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c index 7fcd0a156e..b26a99b271 100644 --- a/libio/iovsprintf.c +++ b/libio/iovsprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997-2003, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003 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 @@ -29,7 +29,10 @@ #include "strfile.h" int -__IO_vsprintf (char *string, const char *format, _IO_va_list args) +_IO_vsprintf (string, format, args) + char *string; + const char *format; + _IO_va_list args; { _IO_strfile sf; int ret; @@ -44,7 +47,8 @@ __IO_vsprintf (char *string, const char *format, _IO_va_list args) _IO_putc_unlocked ('\0', (_IO_FILE *) &sf._sbf); return ret; } -INTDEF2(__IO_vsprintf, _IO_vsprintf) +INTDEF(_IO_vsprintf) -ldbl_strong_alias (__IO_vsprintf, _IO_vsprintf) -ldbl_weak_alias (__IO_vsprintf, vsprintf) +#ifdef weak_alias +weak_alias (_IO_vsprintf, vsprintf) +#endif diff --git a/libio/iovsscanf.c b/libio/iovsscanf.c index 10e4b0a9ac..1a965c2d92 100644 --- a/libio/iovsscanf.c +++ b/libio/iovsscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997-2003, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003 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 @@ -45,5 +45,8 @@ _IO_vsscanf (string, format, args) ret = INTUSE(_IO_vfscanf) ((_IO_FILE *) &sf._sbf, format, args, NULL); return ret; } -ldbl_weak_alias (_IO_vsscanf, __vsscanf) -ldbl_weak_alias (_IO_vsscanf, vsscanf) + +#ifdef weak_alias +weak_alias (_IO_vsscanf, __vsscanf) +weak_alias (_IO_vsscanf, vsscanf) +#endif diff --git a/libio/iovswscanf.c b/libio/iovswscanf.c index 182d8da410..1bbddd442f 100644 --- a/libio/iovswscanf.c +++ b/libio/iovswscanf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993, 1997-2000, 2001, 2002, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2000, 2001, 2002 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 @@ -31,7 +30,10 @@ #include <wchar.h> int -__vswscanf (const wchar_t *string, const wchar_t *format, _IO_va_list args) +vswscanf (string, format, args) + const wchar_t *string; + const wchar_t *format; + _IO_va_list args; { int ret; _IO_strfile sf; @@ -45,5 +47,4 @@ __vswscanf (const wchar_t *string, const wchar_t *format, _IO_va_list args) ret = _IO_vfwscanf ((_IO_FILE *) &sf._sbf, format, args, NULL); return ret; } -ldbl_hidden_def (__vswscanf, vswscanf) -ldbl_strong_alias (__vswscanf, vswscanf) +libc_hidden_def (vswscanf) diff --git a/libio/libc_fatal.c b/libio/libc_fatal.c deleted file mode 100644 index be23849829..0000000000 --- a/libio/libc_fatal.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1993, 1995, 1997, 2003 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - -/* Abort with an error message. */ -void -__libc_fatal (message) - const char *message; -{ - /* This function should write MESSAGE out in the most reliable way. - It is called in situations like internal stdio lossage. */ - - abort (); -} -libc_hidden_def (__libc_fatal) diff --git a/libio/libio.h b/libio/libio.h index 9df08614ee..3b6facdddb 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1995,1997-2005,2006 Free Software Foundation, Inc. +/* Copyright (C) 1991-1995, 1997-2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner <bothner@cygnus.com>. @@ -142,7 +142,6 @@ #ifdef _LIBC # define _IO_FLAGS2_FORTIFY 4 #endif -#define _IO_FLAGS2_USER_WBUF 8 /* These are "formatting flags" matching the iostream fmtflags enum values. */ #define _IO_SKIPWS 01 @@ -318,19 +317,13 @@ struct _IO_FILE_complete /* Wide character stream stuff. */ struct _IO_codecvt *_codecvt; struct _IO_wide_data *_wide_data; - struct _IO_FILE *_freeres_list; - void *_freeres_buf; - size_t _freeres_size; # else void *__pad1; void *__pad2; - void *__pad3; - void *__pad4; - size_t __pad5; # endif int _mode; /* Make sure we don't get into trouble again. */ - char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; + char _unused2[15 * sizeof (int) - 2 * sizeof (void *)]; #endif }; @@ -410,15 +403,15 @@ extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write, extern "C" { #endif -extern int __underflow (_IO_FILE *); -extern int __uflow (_IO_FILE *); -extern int __overflow (_IO_FILE *, int); -extern _IO_wint_t __wunderflow (_IO_FILE *); -extern _IO_wint_t __wuflow (_IO_FILE *); -extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t); +extern int __underflow (_IO_FILE *) __THROW; +extern int __uflow (_IO_FILE *) __THROW; +extern int __overflow (_IO_FILE *, int) __THROW; +extern _IO_wint_t __wunderflow (_IO_FILE *) __THROW; +extern _IO_wint_t __wuflow (_IO_FILE *) __THROW; +extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t) __THROW; #if __GNUC__ >= 3 -# define _IO_BE(expr, res) __builtin_expect ((expr), res) +# define _IO_BE(expr, res) __builtin_expect (expr, res) #else # define _IO_BE(expr, res) (expr) #endif @@ -448,12 +441,12 @@ extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t); #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) -extern int _IO_getc (_IO_FILE *__fp); -extern int _IO_putc (int __c, _IO_FILE *__fp); +extern int _IO_getc (_IO_FILE *__fp) __THROW; +extern int _IO_putc (int __c, _IO_FILE *__fp) __THROW; extern int _IO_feof (_IO_FILE *__fp) __THROW; extern int _IO_ferror (_IO_FILE *__fp) __THROW; -extern int _IO_peekc_locked (_IO_FILE *__fp); +extern int _IO_peekc_locked (_IO_FILE *__fp) __THROW; /* This one is for Emacs. */ #define _IO_PENDING_OUTPUT_COUNT(_fp) \ @@ -479,20 +472,20 @@ extern int _IO_ftrylockfile (_IO_FILE *) __THROW; #endif /* !_IO_MTSAFE_IO */ extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, - _IO_va_list, int *__restrict); + _IO_va_list, int *__restrict) __THROW; extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, - _IO_va_list); -extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t); -extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t); + _IO_va_list) __THROW; +extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW; +extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW; -extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int); -extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int); +extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW; +extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW; extern void _IO_free_backup_area (_IO_FILE *) __THROW; #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T -extern _IO_wint_t _IO_getwc (_IO_FILE *__fp); -extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp); +extern _IO_wint_t _IO_getwc (_IO_FILE *__fp) __THROW; +extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp) __THROW; extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW; # if __GNUC__ >= 2 /* While compiling glibc we have to handle compatibility with very old @@ -528,17 +521,13 @@ weak_extern (_IO_stdin_used); # endif extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict, - _IO_va_list, int *__restrict); + _IO_va_list, int *__restrict) __THROW; extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict, - _IO_va_list); -extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t); + _IO_va_list) __THROW; +extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW; extern void _IO_free_wbackup_area (_IO_FILE *) __THROW; #endif -#ifdef __LDBL_COMPAT -# include <bits/libio-ldbl.h> -#endif - #ifdef __cplusplus } #endif diff --git a/libio/libioP.h b/libio/libioP.h index a574b40f77..319b0fd5f3 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -1,5 +1,4 @@ -/* Copyright (C) 1993, 1997-2003,2004,2005,2006,2007 - Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003, 2004 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 @@ -36,8 +35,6 @@ /*# include <comthread.h>*/ #endif -#include <math_ldbl_opt.h> - #include "iolibio.h" /* Control of exported symbols. Used in glibc. By default we don't @@ -380,7 +377,7 @@ typedef struct _IO_FILE *_IO_ITER; extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW; extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW; -extern int _IO_switch_to_get_mode (_IO_FILE *); +extern int _IO_switch_to_get_mode (_IO_FILE *) __THROW; extern void _IO_init (_IO_FILE *, int) __THROW; extern int _IO_sputbackc (_IO_FILE *, int) __THROW; extern int _IO_sungetc (_IO_FILE *) __THROW; @@ -394,7 +391,7 @@ extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW; extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW; extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW; -extern int _IO_switch_to_wget_mode (_IO_FILE *); +extern int _IO_switch_to_wget_mode (_IO_FILE *) __THROW; extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW; extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW; extern wint_t _IO_sungetwc (_IO_FILE *) __THROW; @@ -404,8 +401,8 @@ extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW; /* Marker-related function. */ -extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *); -extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *); +extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *) __THROW; +extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *) __THROW; extern void _IO_remove_marker (struct _IO_marker *) __THROW; extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *) __THROW; @@ -434,22 +431,22 @@ libc_hidden_proto (_IO_list_resetlock) /* Default jumptable functions. */ extern int _IO_default_underflow (_IO_FILE *) __THROW; -extern int _IO_default_uflow (_IO_FILE *); -extern wint_t _IO_wdefault_uflow (_IO_FILE *); +extern int _IO_default_uflow (_IO_FILE *) __THROW; +extern wint_t _IO_wdefault_uflow (_IO_FILE *) __THROW; extern int _IO_default_doallocate (_IO_FILE *) __THROW; extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW; extern void _IO_default_finish (_IO_FILE *, int) __THROW; extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW; extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW; extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW; -extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t); +extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW; extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t); extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t); extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t); extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t); extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW; -extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int); +extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW; extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t); extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t); extern int _IO_default_stat (_IO_FILE *, void *) __THROW; @@ -472,23 +469,23 @@ extern const struct _IO_jump_t _IO_streambuf_jumps; extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden; extern const struct _IO_jump_t _IO_str_jumps attribute_hidden; extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden; -extern const struct _IO_codecvt __libio_codecvt attribute_hidden; -extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t); -extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t); -extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t); -extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t); -extern int _IO_flush_all_lockp (int); -extern int _IO_flush_all (void); -extern int _IO_cleanup (void); -extern void _IO_flush_all_linebuffered (void); -extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *); -extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *); -extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *); -extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *); -extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *); -extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *); -extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *); -extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *); +extern struct _IO_codecvt __libio_codecvt attribute_hidden; +extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW; +extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW; +extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW; +extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t) __THROW; +extern int _IO_flush_all_lockp (int) __THROW; +extern int _IO_flush_all (void) __THROW; +extern int _IO_cleanup (void) __THROW; +extern void _IO_flush_all_linebuffered (void) __THROW; +extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *) __THROW; +extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *) __THROW; +extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *) __THROW; +extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *) __THROW; +extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *) __THROW; +extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *) __THROW; +extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *) __THROW; +extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *) __THROW; extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW; @@ -534,79 +531,95 @@ extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW; /* Jumptable functions for files. */ extern int _IO_file_doallocate (_IO_FILE *) __THROW; -extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); -extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); +extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW; +extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int) + __THROW; extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int) __THROW; -extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t); -extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t); +extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t) + __THROW; +extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t) __THROW; extern int _IO_file_stat (_IO_FILE *, void *) __THROW; extern int _IO_file_close (_IO_FILE *) __THROW; extern int _IO_file_close_mmap (_IO_FILE *) __THROW; -extern int _IO_file_underflow (_IO_FILE *); -extern int _IO_file_underflow_mmap (_IO_FILE *); -extern int _IO_file_underflow_maybe_mmap (_IO_FILE *); -extern int _IO_file_overflow (_IO_FILE *, int); +extern int _IO_file_underflow (_IO_FILE *) __THROW; +extern int _IO_file_underflow_mmap (_IO_FILE *) __THROW; +extern int _IO_file_underflow_maybe_mmap (_IO_FILE *) __THROW; +extern int _IO_file_overflow (_IO_FILE *, int) __THROW; #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1) extern void _IO_file_init (struct _IO_FILE_plus *) __THROW; -extern _IO_FILE* _IO_file_attach (_IO_FILE *, int); -extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int); +extern _IO_FILE* _IO_file_attach (_IO_FILE *, int) __THROW; +extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int) + __THROW; libc_hidden_proto (_IO_file_open) -extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int); -extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t); -extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t); -extern int _IO_file_sync (_IO_FILE *); -extern int _IO_file_close_it (_IO_FILE *); +extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int) + __THROW; +extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t) + __THROW; +extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t) __THROW; +extern int _IO_file_sync (_IO_FILE *) __THROW; +extern int _IO_file_close_it (_IO_FILE *) __THROW; extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW; -extern void _IO_file_finish (_IO_FILE *, int); +extern void _IO_file_finish (_IO_FILE *, int) __THROW; -extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int); -extern int _IO_new_file_close_it (_IO_FILE *); -extern void _IO_new_file_finish (_IO_FILE *, int); +extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int) __THROW; +extern int _IO_new_file_close_it (_IO_FILE *) __THROW; +extern void _IO_new_file_finish (_IO_FILE *, int) __THROW; extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *, - int); + int) __THROW; extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *, const struct _IO_jump_t *) __THROW; extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW; -extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); -extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t); -extern int _IO_new_file_sync (_IO_FILE *); -extern int _IO_new_file_underflow (_IO_FILE *); -extern int _IO_new_file_overflow (_IO_FILE *, int); -extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); -extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t); -extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t); - -extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); -extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); -extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t); -extern int _IO_old_file_underflow (_IO_FILE *); -extern int _IO_old_file_overflow (_IO_FILE *, int); +extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW; +extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t) + __THROW; +extern int _IO_new_file_sync (_IO_FILE *) __THROW; +extern int _IO_new_file_underflow (_IO_FILE *) __THROW; +extern int _IO_new_file_overflow (_IO_FILE *, int) __THROW; +extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int) + __THROW; +extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t) + __THROW; +extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t) + __THROW; + +extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW; +extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int) + __THROW; +extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t) + __THROW; +extern int _IO_old_file_underflow (_IO_FILE *) __THROW; +extern int _IO_old_file_overflow (_IO_FILE *, int) __THROW; extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW; -extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int); -extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *); -extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t); -extern int _IO_old_file_sync (_IO_FILE *); -extern int _IO_old_file_close_it (_IO_FILE *); -extern void _IO_old_file_finish (_IO_FILE *, int); +extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int) __THROW; +extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *) + __THROW; +extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t) + __THROW; +extern int _IO_old_file_sync (_IO_FILE *) __THROW; +extern int _IO_old_file_close_it (_IO_FILE *) __THROW; +extern void _IO_old_file_finish (_IO_FILE *, int) __THROW; extern int _IO_wfile_doallocate (_IO_FILE *) __THROW; -extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t); -extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t); -extern wint_t _IO_wfile_sync (_IO_FILE *); -extern wint_t _IO_wfile_underflow (_IO_FILE *); -extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t); -extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int); +extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t) + __THROW; +extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t) __THROW; +extern wint_t _IO_wfile_sync (_IO_FILE *) __THROW; +extern wint_t _IO_wfile_underflow (_IO_FILE *) __THROW; +extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t) __THROW; +extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int) + __THROW; /* Jumptable functions for proc_files. */ extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *) __THROW; extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *) __THROW; -extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *); +extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *) + __THROW; extern int _IO_proc_close (_IO_FILE *) __THROW; extern int _IO_new_proc_close (_IO_FILE *) __THROW; -extern int _IO_old_proc_close (_IO_FILE *); +extern int _IO_old_proc_close (_IO_FILE *) __THROW; /* Jumptable functions for strfiles. */ extern int _IO_str_underflow (_IO_FILE *) __THROW; @@ -636,7 +649,7 @@ extern void _IO_wstr_finish (_IO_FILE *, int) __THROW; extern int _IO_vasprintf (char **result_ptr, __const char *format, _IO_va_list args) __THROW; -extern int _IO_vdprintf (int d, __const char *format, _IO_va_list arg); +extern int _IO_vdprintf (int d, __const char *format, _IO_va_list arg) __THROW; extern int _IO_vsnprintf (char *string, _IO_size_t maxlen, __const char *format, _IO_va_list args) __THROW; @@ -644,62 +657,73 @@ extern int _IO_vsnprintf (char *string, _IO_size_t maxlen, extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int); extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t, int, int, int *); -extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *); +extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *) + __THROW; extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int); extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int, wint_t *); +extern double _IO_strtod (const char *, char **) __THROW; +extern char *_IO_dtoa (double __d, int __mode, int __ndigits, + int *__decpt, int *__sign, char **__rve) __THROW; +extern int _IO_outfloat (double __value, _IO_FILE *__sb, int __type, + int __width, int __precision, int __flags, + int __sign_mode, int __fill) __THROW; extern struct _IO_FILE_plus *_IO_list_all; extern void (*_IO_cleanup_registration_needed) (void); /* Prototype for functions with alternative entry point. */ -extern int _IO_flush_all_internal (void); -extern unsigned _IO_adjust_column_internal (unsigned, const char *, int); +extern int _IO_flush_all_internal (void) __THROW; +extern unsigned _IO_adjust_column_internal (unsigned, const char *, int) + __THROW; -extern int _IO_default_uflow_internal (_IO_FILE *); +extern int _IO_default_uflow_internal (_IO_FILE *) __THROW; extern void _IO_default_finish_internal (_IO_FILE *, int) __THROW; extern int _IO_default_pbackfail_internal (_IO_FILE *, int) __THROW; extern _IO_size_t _IO_default_xsputn_internal (_IO_FILE *, const void *, - _IO_size_t); -extern _IO_size_t _IO_default_xsgetn_internal (_IO_FILE *, void *, _IO_size_t); + _IO_size_t) __THROW; +extern _IO_size_t _IO_default_xsgetn_internal (_IO_FILE *, void *, _IO_size_t) + __THROW; extern int _IO_default_doallocate_internal (_IO_FILE *) __THROW; extern void _IO_wdefault_finish_internal (_IO_FILE *, int) __THROW; extern wint_t _IO_wdefault_pbackfail_internal (_IO_FILE *, wint_t) __THROW; extern _IO_size_t _IO_wdefault_xsputn_internal (_IO_FILE *, const void *, - _IO_size_t); + _IO_size_t) __THROW; extern _IO_size_t _IO_wdefault_xsgetn_internal (_IO_FILE *, void *, - _IO_size_t); + _IO_size_t) __THROW; extern int _IO_wdefault_doallocate_internal (_IO_FILE *) __THROW; -extern wint_t _IO_wdefault_uflow_internal (_IO_FILE *); +extern wint_t _IO_wdefault_uflow_internal (_IO_FILE *) __THROW; extern int _IO_file_doallocate_internal (_IO_FILE *) __THROW; -extern _IO_FILE* _IO_file_setbuf_internal (_IO_FILE *, char *, _IO_ssize_t); +extern _IO_FILE* _IO_file_setbuf_internal (_IO_FILE *, char *, _IO_ssize_t) + __THROW; extern _IO_off64_t _IO_file_seekoff_internal (_IO_FILE *, _IO_off64_t, - int, int); + int, int) __THROW; extern _IO_size_t _IO_file_xsputn_internal (_IO_FILE *, const void *, - _IO_size_t); -extern _IO_size_t _IO_file_xsgetn_internal (_IO_FILE *, void *, _IO_size_t); + _IO_size_t) __THROW; +extern _IO_size_t _IO_file_xsgetn_internal (_IO_FILE *, void *, _IO_size_t) + __THROW; extern int _IO_file_stat_internal (_IO_FILE *, void *) __THROW; extern int _IO_file_close_internal (_IO_FILE *) __THROW; -extern int _IO_file_close_it_internal (_IO_FILE *); -extern int _IO_file_underflow_internal (_IO_FILE *); -extern int _IO_file_overflow_internal (_IO_FILE *, int); +extern int _IO_file_close_it_internal (_IO_FILE *) __THROW; +extern int _IO_file_underflow_internal (_IO_FILE *) __THROW; +extern int _IO_file_overflow_internal (_IO_FILE *, int) __THROW; extern void _IO_file_init_internal (struct _IO_FILE_plus *) __THROW; -extern _IO_FILE* _IO_file_attach_internal (_IO_FILE *, int); +extern _IO_FILE* _IO_file_attach_internal (_IO_FILE *, int) __THROW; extern _IO_FILE* _IO_file_fopen_internal (_IO_FILE *, const char *, - const char *, int); + const char *, int) __THROW; extern _IO_ssize_t _IO_file_read_internal (_IO_FILE *, void *, _IO_ssize_t); -extern int _IO_file_sync_internal (_IO_FILE *); +extern int _IO_file_sync_internal (_IO_FILE *) __THROW; extern _IO_off64_t _IO_file_seek_internal (_IO_FILE *, _IO_off64_t, int) __THROW; -extern void _IO_file_finish_internal (_IO_FILE *, int); +extern void _IO_file_finish_internal (_IO_FILE *, int) __THROW; extern _IO_size_t _IO_wfile_xsputn_internal (_IO_FILE *, const void *, - _IO_size_t); + _IO_size_t) __THROW; extern _IO_off64_t _IO_wfile_seekoff_internal (_IO_FILE *, _IO_off64_t, - int, int); -extern wint_t _IO_wfile_sync_internal (_IO_FILE *); + int, int) __THROW; +extern wint_t _IO_wfile_sync_internal (_IO_FILE *) __THROW; extern int _IO_str_underflow_internal (_IO_FILE *) __THROW; extern int _IO_str_overflow_internal (_IO_FILE *, int) __THROW; @@ -720,12 +744,12 @@ extern void _IO_wdoallocbuf_internal (_IO_FILE *) __THROW; extern _IO_size_t _IO_sgetn_internal (_IO_FILE *, void *, _IO_size_t); extern void _IO_flush_all_linebuffered_internal (void) __THROW; -extern int _IO_switch_to_wget_mode_internal (_IO_FILE *); +extern int _IO_switch_to_wget_mode_internal (_IO_FILE *) __THROW; extern void _IO_unsave_markers_internal (_IO_FILE *) __THROW; extern void _IO_switch_to_main_wget_area_internal (_IO_FILE *) __THROW; extern int _IO_wdo_write_internal (_IO_FILE *, const wchar_t *, _IO_size_t); extern int _IO_do_write_internal (_IO_FILE *, const char *, _IO_size_t); -extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t); +extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t) __THROW; extern _IO_size_t _IO_getline_info_internal (_IO_FILE *,char *, _IO_size_t, int, int, int *); extern _IO_size_t _IO_getline_internal (_IO_FILE *, char *, _IO_size_t, int, @@ -735,7 +759,7 @@ extern void _IO_free_backup_area_internal (_IO_FILE *) __THROW; extern void _IO_switch_to_wbackup_area_internal (_IO_FILE *) __THROW; extern void _IO_setb_internal (_IO_FILE *, char *, char *, int) __THROW; extern wint_t _IO_sputbackwc_internal (_IO_FILE *, wint_t) __THROW; -extern int _IO_switch_to_get_mode_internal (_IO_FILE *); +extern int _IO_switch_to_get_mode_internal (_IO_FILE *) __THROW; extern int _IO_vfscanf_internal (_IO_FILE * __restrict, const char * __restrict, _IO_va_list, int *__restrict); @@ -745,9 +769,9 @@ extern void _IO_doallocbuf_internal (_IO_FILE *) __THROW; extern void _IO_wsetb_internal (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW; extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int) - attribute_hidden; + attribute_hidden __THROW; extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int) - attribute_hidden; + attribute_hidden __THROW; extern int _IO_putc_internal (int __c, _IO_FILE *__fp); extern void _IO_init_internal (_IO_FILE *, int) __THROW; extern void _IO_un_link_internal (struct _IO_FILE_plus *) __THROW; @@ -839,6 +863,12 @@ extern void _IO_un_link_internal (struct _IO_FILE_plus *) __THROW; #ifndef OS_FSTAT # define OS_FSTAT fstat #endif +struct stat; +extern _IO_ssize_t _IO_read (int, void *, _IO_size_t); +extern _IO_ssize_t _IO_write (int, const void *, _IO_size_t); +extern _IO_off64_t _IO_lseek (int, _IO_off64_t, int) __THROW; +extern int _IO_close (int); +extern int _IO_fstat (int, struct stat *) __THROW; extern int _IO_vscanf (const char *, _IO_va_list) __THROW; /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */ diff --git a/libio/memstream.c b/libio/memstream.c index 877383f3a8..4cc9ab2dfc 100644 --- a/libio/memstream.c +++ b/libio/memstream.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-97,99,2000,2002-2004,2006 Free Software Foundation, Inc. +/* Copyright (C) 1995-97,99,2000,2002,2003,2004 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 @@ -83,7 +83,7 @@ open_memstream (bufloc, sizeloc) new_f->fp._sf._sbf._f._lock = &new_f->lock; #endif - buf = calloc (1, _IO_BUFSIZ); + buf = malloc (_IO_BUFSIZ); if (buf == NULL) return NULL; INTUSE(_IO_init) (&new_f->fp._sf._sbf._f, 0); @@ -106,6 +106,11 @@ _IO_mem_sync (fp) _IO_FILE* fp; { struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp; + int res; + + res = _IO_default_sync (fp); + if (res < 0) + return res; if (fp->_IO_write_ptr == fp->_IO_write_end) { @@ -135,9 +140,9 @@ _IO_mem_finish (fp, dummy) { (*mp->bufloc)[fp->_IO_write_ptr - fp->_IO_write_base] = '\0'; *mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base; - - fp->_IO_buf_base = NULL; } - _IO_str_finish (fp, 0); + fp->_IO_buf_base = NULL; + + INTUSE(_IO_default_finish) (fp, 0); } diff --git a/libio/obprintf.c b/libio/obprintf.c index 0a50c8e0fc..19300e80a3 100644 --- a/libio/obprintf.c +++ b/libio/obprintf.c @@ -1,6 +1,5 @@ /* Print output of stream to given obstack. - Copyright (C) 1996,1997,1999,2000,2001,2002,2003,2004,2005,2006 - Free Software Foundation, Inc. + Copyright (C) 1996,1997,1999-2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -24,7 +23,6 @@ #include <stdlib.h> #endif #include "libioP.h" -#include "strfile.h" #include <assert.h> #include <string.h> #include <errno.h> @@ -176,7 +174,9 @@ _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) return result; } -ldbl_weak_alias (_IO_obstack_vprintf, obstack_vprintf) +#ifdef weak_alias +weak_alias (_IO_obstack_vprintf, obstack_vprintf) +#endif int @@ -189,4 +189,6 @@ _IO_obstack_printf (struct obstack *obstack, const char *format, ...) va_end (ap); return result; } -ldbl_weak_alias (_IO_obstack_printf, obstack_printf) +#ifdef weak_alias +weak_alias (_IO_obstack_printf, obstack_printf) +#endif diff --git a/libio/oldfileops.c b/libio/oldfileops.c index 3bd0aa175b..b9efca7aa8 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2004, 2005, 2007 - Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner <bothner@cygnus.com>. @@ -272,7 +271,7 @@ _IO_old_file_setbuf (fp, p, len) return fp; } -static int old_do_write (_IO_FILE *, const char *, _IO_size_t); +static int old_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW; /* Write TO_DO bytes from DATA to FP. Then mark FP as having empty buffers. */ @@ -696,7 +695,7 @@ _IO_old_file_xsputn (f, data, n) register const char *s = (char *) data; _IO_size_t to_do = n; int must_flush = 0; - _IO_size_t count = 0; + _IO_size_t count; if (n <= 0) return 0; @@ -705,6 +704,7 @@ _IO_old_file_xsputn (f, data, n) (or the filebuf is unbuffered), use sys_write directly. */ /* First figure out how much space is available in the buffer. */ + count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING)) { count = f->_IO_buf_end - f->_IO_write_ptr; @@ -722,9 +722,6 @@ _IO_old_file_xsputn (f, data, n) } } } - else if (f->_IO_write_end > f->_IO_write_ptr) - count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ - /* Then fill the buffer. */ if (count > 0) { @@ -755,7 +752,7 @@ _IO_old_file_xsputn (f, data, n) _IO_size_t block_size, do_write; /* Next flush the (full) buffer. */ if (__overflow (f, EOF) == EOF) - return to_do == 0 ? EOF : n - to_do; + return n - to_do; /* Try to maintain alignment: write a whole number of blocks. dont_write is what gets left over. */ diff --git a/libio/oldiofclose.c b/libio/oldiofclose.c index 62c3154118..8dd321b054 100644 --- a/libio/oldiofclose.c +++ b/libio/oldiofclose.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2002,2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2002, 2004 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 @@ -58,8 +58,8 @@ _IO_old_fclose (fp) status = _IO_old_file_close_it (fp); else status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; - _IO_release_lock (fp); _IO_FINISH (fp); + _IO_release_lock (fp); if (_IO_have_backup (fp)) INTUSE(_IO_free_backup_area) (fp); if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr) diff --git a/libio/stdio.h b/libio/stdio.h index c8fe52cf31..e1081c9039 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -1,5 +1,5 @@ /* Define ISO C stdio on top of C++ iostreams. - Copyright (C) 1991,1994-2004,2005,2006 Free Software Foundation, Inc. + Copyright (C) 1991,1994-2002,2003,2004 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 @@ -142,12 +142,10 @@ typedef _G_fpos64_t fpos64_t; extern struct _IO_FILE *stdin; /* Standard input stream. */ extern struct _IO_FILE *stdout; /* Standard output stream. */ extern struct _IO_FILE *stderr; /* Standard error output stream. */ -#ifdef __STDC__ /* C89/C99 say they're macros. Make them happy. */ #define stdin stdin #define stdout stdout #define stderr stderr -#endif __BEGIN_NAMESPACE_STD /* Remove file FILENAME. */ @@ -156,11 +154,6 @@ extern int remove (__const char *__filename) __THROW; extern int rename (__const char *__old, __const char *__new) __THROW; __END_NAMESPACE_STD -#ifdef __USE_ATFILE -/* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */ -extern int renameat (int __oldfd, __const char *__old, int __newfd, - __const char *__new) __THROW; -#endif __BEGIN_NAMESPACE_STD /* Create a temporary file and open it read/write. @@ -293,7 +286,8 @@ extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW; /* Open a stream that writes into a malloc'd buffer that is expanded as necessary. *BUFLOC and *SIZELOC are updated with the buffer's location and the number of characters written on fflush or fclose. */ -extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW; +extern FILE *open_memstream (char **__restrict __bufloc, + size_t *__restrict __sizeloc) __THROW; #endif @@ -397,12 +391,12 @@ __BEGIN_NAMESPACE_STD This function is a possible cancellation point and therefore not marked with __THROW. */ extern int fscanf (FILE *__restrict __stream, - __const char *__restrict __format, ...) __wur; + __const char *__restrict __format, ...); /* Read formatted input from stdin. This function is a possible cancellation point and therefore not marked with __THROW. */ -extern int scanf (__const char *__restrict __format, ...) __wur; +extern int scanf (__const char *__restrict __format, ...); /* Read formatted input from S. */ extern int sscanf (__const char *__restrict __s, __const char *__restrict __format, ...) __THROW; @@ -416,14 +410,14 @@ __BEGIN_NAMESPACE_C99 marked with __THROW. */ extern int vfscanf (FILE *__restrict __s, __const char *__restrict __format, _G_va_list __arg) - __attribute__ ((__format__ (__scanf__, 2, 0))) __wur; + __attribute__ ((__format__ (__scanf__, 2, 0))); /* Read formatted input from stdin into argument list ARG. This function is a possible cancellation point and therefore not marked with __THROW. */ extern int vscanf (__const char *__restrict __format, _G_va_list __arg) - __attribute__ ((__format__ (__scanf__, 1, 0))) __wur; + __attribute__ ((__format__ (__scanf__, 1, 0))); /* Read formatted input from S into argument list ARG. */ extern int vsscanf (__const char *__restrict __s, @@ -529,15 +523,14 @@ __BEGIN_NAMESPACE_STD This function is a possible cancellation point and therefore not marked with __THROW. */ -extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) - __wur; +extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream); /* Get a newline-terminated string from stdin, removing the newline. DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. This function is a possible cancellation point and therefore not marked with __THROW. */ -extern char *gets (char *__s) __wur; +extern char *gets (char *__s); __END_NAMESPACE_STD #ifdef __USE_GNU @@ -548,7 +541,7 @@ __END_NAMESPACE_STD or due to the implementation it is a cancellation point and therefore not marked with __THROW. */ extern char *fgets_unlocked (char *__restrict __s, int __n, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream); #endif @@ -565,10 +558,10 @@ extern char *fgets_unlocked (char *__restrict __s, int __n, therefore not marked with __THROW. */ extern _IO_ssize_t __getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream); extern _IO_ssize_t getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream); /* Like `getdelim', but reads up to a newline. @@ -578,7 +571,7 @@ extern _IO_ssize_t getdelim (char **__restrict __lineptr, therefore not marked with __THROW. */ extern _IO_ssize_t getline (char **__restrict __lineptr, size_t *__restrict __n, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream); #endif @@ -608,13 +601,13 @@ extern int ungetc (int __c, FILE *__stream); This function is a possible cancellation points and therefore not marked with __THROW. */ extern size_t fread (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) __wur; + size_t __n, FILE *__restrict __stream); /* Write chunks of generic data to STREAM. This function is a possible cancellation points and therefore not marked with __THROW. */ extern size_t fwrite (__const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __s) __wur; + size_t __n, FILE *__restrict __s); __END_NAMESPACE_STD #ifdef __USE_GNU @@ -636,9 +629,9 @@ extern int fputs_unlocked (__const char *__restrict __s, or due to the implementation they are cancellation points and therefore not marked with __THROW. */ extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) __wur; + size_t __n, FILE *__restrict __stream); extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) __wur; + size_t __n, FILE *__restrict __stream); #endif @@ -652,7 +645,7 @@ extern int fseek (FILE *__stream, long int __off, int __whence); This function is a possible cancellation point and therefore not marked with __THROW. */ -extern long int ftell (FILE *__stream) __wur; +extern long int ftell (FILE *__stream); /* Rewind to the beginning of STREAM. This function is a possible cancellation point and therefore not @@ -676,7 +669,7 @@ extern int fseeko (FILE *__stream, __off_t __off, int __whence); This function is a possible cancellation point and therefore not marked with __THROW. */ -extern __off_t ftello (FILE *__stream) __wur; +extern __off_t ftello (FILE *__stream); # else # ifdef __REDIRECT extern int __REDIRECT (fseeko, @@ -717,7 +710,7 @@ __END_NAMESPACE_STD #ifdef __USE_LARGEFILE64 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence); -extern __off64_t ftello64 (FILE *__stream) __wur; +extern __off64_t ftello64 (FILE *__stream); extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos); extern int fsetpos64 (FILE *__stream, __const fpos64_t *__pos); #endif @@ -726,16 +719,16 @@ __BEGIN_NAMESPACE_STD /* Clear the error and EOF indicators for STREAM. */ extern void clearerr (FILE *__stream) __THROW; /* Return the EOF indicator for STREAM. */ -extern int feof (FILE *__stream) __THROW __wur; +extern int feof (FILE *__stream) __THROW; /* Return the error indicator for STREAM. */ -extern int ferror (FILE *__stream) __THROW __wur; +extern int ferror (FILE *__stream) __THROW; __END_NAMESPACE_STD #ifdef __USE_MISC /* Faster versions when locking is not required. */ extern void clearerr_unlocked (FILE *__stream) __THROW; -extern int feof_unlocked (FILE *__stream) __THROW __wur; -extern int ferror_unlocked (FILE *__stream) __THROW __wur; +extern int feof_unlocked (FILE *__stream) __THROW; +extern int ferror_unlocked (FILE *__stream) __THROW; #endif @@ -756,12 +749,12 @@ __END_NAMESPACE_STD #ifdef __USE_POSIX /* Return the system file descriptor for STREAM. */ -extern int fileno (FILE *__stream) __THROW __wur; +extern int fileno (FILE *__stream) __THROW; #endif /* Use POSIX. */ #ifdef __USE_MISC /* Faster version when locking is not required. */ -extern int fileno_unlocked (FILE *__stream) __THROW __wur; +extern int fileno_unlocked (FILE *__stream) __THROW; #endif @@ -771,7 +764,7 @@ extern int fileno_unlocked (FILE *__stream) __THROW __wur; This function is a possible cancellation point and therefore not marked with __THROW. */ -extern FILE *popen (__const char *__command, __const char *__modes) __wur; +extern FILE *popen (__const char *__command, __const char *__modes); /* Close a stream opened by popen and return the status of its child. @@ -815,7 +808,7 @@ extern void flockfile (FILE *__stream) __THROW; /* Try to acquire ownership of STREAM but do not block if it is not possible. */ -extern int ftrylockfile (FILE *__stream) __THROW __wur; +extern int ftrylockfile (FILE *__stream) __THROW; /* Relinquish the ownership granted for STREAM. */ extern void funlockfile (FILE *__stream) __THROW; @@ -837,9 +830,6 @@ extern void funlockfile (FILE *__stream) __THROW; #if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus # include <bits/stdio2.h> #endif -#ifdef __LDBL_COMPAT -# include <bits/stdio-ldbl.h> -#endif __END_DECLS diff --git a/libio/strfile.h b/libio/strfile.h index 53a36a3db8..b91111a9d6 100644 --- a/libio/strfile.h +++ b/libio/strfile.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 1998, 1999, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 1998, 1999 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 @@ -73,14 +73,3 @@ typedef struct } _IO_strnfile; extern const struct _IO_jump_t _IO_strn_jumps attribute_hidden; - - -typedef struct -{ - _IO_strfile f; - /* This is used for the characters which do not fit in the buffer - provided by the user. */ - wchar_t overflow_buf[64]; -} _IO_wstrnfile; - -extern const struct _IO_jump_t _IO_wstrn_jumps attribute_hidden; diff --git a/libio/strops.c b/libio/strops.c index 05270ce407..2de83403a2 100644 --- a/libio/strops.c +++ b/libio/strops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997-2003, 2004, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003, 2004 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 @@ -25,12 +25,43 @@ This exception applies to code released by its copyright holders in files containing the exception. */ -#include <assert.h> #include "strfile.h" #include "libioP.h" #include <string.h> #include <stdio_ext.h> +#if 0 +/* The following definitions are for exposition only. + They map the terminology used in the ANSI/ISO C++ draft standard + to the implementation. */ + +/* allocated: set when a dynamic array object has been allocated, and + hence should be freed by the destructor for the strstreambuf object. */ +#define ALLOCATED(FP) ((FP)->_f._IO_buf_base && DYNAMIC(FP)) + +/* constant: set when the array object has const elements, + so the output sequence cannot be written. */ +#define CONSTANT(FP) ((FP)->_f._IO_file_flags & _IO_NO_WRITES) + +/* alsize: the suggested minimum size for a dynamic array object. */ +#define ALSIZE(FP) ??? /* not stored */ + +/* palloc: points to the function to call to allocate a dynamic array object.*/ +#define PALLOC(FP) \ + ((FP)->_s._allocate_buffer == default_alloc ? 0 : (FP)->_s._allocate_buffer) + +/* pfree: points to the function to call to free a dynamic array object. */ +#define PFREE(FP) \ + ((FP)->_s._free_buffer == default_free ? 0 : (FP)->_s._free_buffer) + +#endif + +#ifdef TODO +/* An "unbounded buffer" is when a buffer is supplied, but with no + specified length. An example is the buffer argument to sprintf. + */ +#endif + void _IO_str_init_static_internal (sf, ptr, size, pstart) _IO_strfile *sf; @@ -103,7 +134,7 @@ _IO_str_overflow (fp, c) fp->_IO_write_ptr = fp->_IO_read_ptr; fp->_IO_read_ptr = fp->_IO_read_end; } - pos = fp->_IO_write_ptr - fp->_IO_write_base; + pos = fp->_IO_write_ptr - fp->_IO_write_base; if (pos >= (_IO_size_t) (_IO_blen (fp) + flush_only)) { if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */ @@ -112,10 +143,7 @@ _IO_str_overflow (fp, c) { char *new_buf; char *old_buf = fp->_IO_buf_base; - size_t old_blen = _IO_blen (fp); - _IO_size_t new_size = 2 * old_blen + 100; - if (new_size < old_blen) - return EOF; + _IO_size_t new_size = 2 * _IO_blen (fp) + 100; new_buf = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size); if (new_buf == NULL) @@ -125,13 +153,15 @@ _IO_str_overflow (fp, c) } if (old_buf) { - memcpy (new_buf, old_buf, old_blen); + memcpy (new_buf, old_buf, _IO_blen (fp)); (*((_IO_strfile *) fp)->_s._free_buffer) (old_buf); /* Make sure _IO_setb won't try to delete _IO_buf_base. */ fp->_IO_buf_base = NULL; } - memset (new_buf + old_blen, '\0', new_size - old_blen); - +#if 0 + if (lenp == &LEN(fp)) /* use '\0'-filling */ + memset (new_buf + pos, 0, blen() - pos); +#endif INTUSE(_IO_setb) (fp, new_buf, new_buf + new_size, 1); fp->_IO_read_base = new_buf + (fp->_IO_read_base - old_buf); fp->_IO_read_ptr = new_buf + (fp->_IO_read_ptr - old_buf); @@ -181,71 +211,6 @@ _IO_str_count (fp) - fp->_IO_read_base); } - -static int -enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading) -{ - if ((_IO_ssize_t) offset <= _IO_blen (fp)) - return 0; - - _IO_ssize_t oldend = fp->_IO_write_end - fp->_IO_write_base; - - /* Try to enlarge the buffer. */ - if (fp->_flags & _IO_USER_BUF) - /* User-provided buffer. */ - return 1; - - _IO_size_t newsize = offset + 100; - char *oldbuf = fp->_IO_buf_base; - char *newbuf - = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize); - if (newbuf == NULL) - return 1; - - if (oldbuf != NULL) - { - memcpy (newbuf, oldbuf, _IO_blen (fp)); - (*((_IO_strfile *) fp)->_s._free_buffer) (oldbuf); - /* Make sure _IO_setb won't try to delete - _IO_buf_base. */ - fp->_IO_buf_base = NULL; - } - - INTUSE(_IO_setb) (fp, newbuf, newbuf + newsize, 1); - - if (reading) - { - fp->_IO_write_base = newbuf + (fp->_IO_write_base - oldbuf); - fp->_IO_write_ptr = newbuf + (fp->_IO_write_ptr - oldbuf); - fp->_IO_write_end = newbuf + (fp->_IO_write_end - oldbuf); - fp->_IO_read_ptr = newbuf + (fp->_IO_read_ptr - oldbuf); - - fp->_IO_read_base = newbuf; - fp->_IO_read_end = fp->_IO_buf_end; - } - else - { - fp->_IO_read_base = newbuf + (fp->_IO_read_base - oldbuf); - fp->_IO_read_ptr = newbuf + (fp->_IO_read_ptr - oldbuf); - fp->_IO_read_end = newbuf + (fp->_IO_read_end - oldbuf); - fp->_IO_write_ptr = newbuf + (fp->_IO_write_ptr - oldbuf); - - fp->_IO_write_base = newbuf; - fp->_IO_write_end = fp->_IO_buf_end; - } - - /* Clear the area between the last write position and th - new position. */ - assert (offset >= oldend); - if (reading) - memset (fp->_IO_read_base + oldend, '\0', offset - oldend); - else - memset (fp->_IO_write_base + oldend, '\0', offset - oldend); - - return 0; -} - - _IO_off64_t _IO_str_seekoff (fp, offset, dir, mode) _IO_FILE *fp; @@ -286,10 +251,7 @@ _IO_str_seekoff (fp, offset, dir, mode) default: /* case _IO_seek_set: */ break; } - if (offset < 0) - return EOF; - if ((_IO_ssize_t) offset > cur_size - && enlarge_userbuf (fp, offset, 1) != 0) + if (offset < 0 || (_IO_ssize_t) offset > cur_size) return EOF; fp->_IO_read_ptr = fp->_IO_read_base + offset; fp->_IO_read_end = fp->_IO_read_base + cur_size; @@ -310,10 +272,7 @@ _IO_str_seekoff (fp, offset, dir, mode) default: /* case _IO_seek_set: */ break; } - if (offset < 0) - return EOF; - if ((_IO_ssize_t) offset > cur_size - && enlarge_userbuf (fp, offset, 0) != 0) + if (offset < 0 || (_IO_ssize_t) offset > cur_size) return EOF; fp->_IO_write_ptr = fp->_IO_write_base + offset; new_pos = offset; diff --git a/libio/swprintf.c b/libio/swprintf.c index ea0bdfd33c..298c1e7537 100644 --- a/libio/swprintf.c +++ b/libio/swprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,1995,1997,1998,1999,2000,2003,2004,2006 +/* Copyright (C) 1991,1995,1997,1998,1999,2000,2003 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -17,14 +17,13 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <wchar.h> /* Write formatted output into S, according to the format string FORMAT. */ /* VARARGS3 */ int -__swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) +swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) { va_list arg; int done; @@ -35,4 +34,3 @@ __swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) return done; } -ldbl_strong_alias (__swprintf, swprintf) diff --git a/libio/swscanf.c b/libio/swscanf.c index f93d207416..c837ad14f6 100644 --- a/libio/swscanf.c +++ b/libio/swscanf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1998, 1999, 2003, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1991,1995,1996,1998,1999,2003 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 @@ -17,14 +16,13 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <wchar.h> /* Read formatted input from S, according to the format string FORMAT. */ /* VARARGS2 */ int -__swscanf (const wchar_t *s, const wchar_t *format, ...) +swscanf (const wchar_t *s, const wchar_t *format, ...) { va_list arg; int done; @@ -35,4 +33,3 @@ __swscanf (const wchar_t *s, const wchar_t *format, ...) return done; } -ldbl_strong_alias (__swscanf, swscanf) diff --git a/libio/tst-fopenloc2.c b/libio/tst-fopenloc2.c deleted file mode 100644 index 5ddd63446b..0000000000 --- a/libio/tst-fopenloc2.c +++ /dev/null @@ -1,116 +0,0 @@ -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <wchar.h> - - -static const struct -{ - const char *enc; - const char *data; - size_t datalen; - const wchar_t *expected; - size_t expectedlen; -} tests[] = - { - { "UCS-4LE", "a\0\0\0b\0\0\0", 8, L"ab", 2 }, - { "UCS-4BE", "\0\0\0a\0\0\0b", 8, L"ab", 2 }, - }; -#define ntests (sizeof (tests) / sizeof (tests[0])) - - -static int do_test (void); -#define TEST_FUNCTION do_test () - -static void prepare (void); -#define PREPARE(argc, argv) prepare (); - -#include "../test-skeleton.c" - - -static int fd; -static char *tmpname; - - -static void -prepare (void) -{ - fd = create_temp_file ("tst-fopenloc2", &tmpname); - if (fd == -1) - { - puts ("cannot open temp file"); - exit (1); - } -} - - -static int -do_test (void) -{ - for (int i = 0; i < ntests; ++i) - { - if (ftruncate (fd, 0) != 0) - { - printf ("ftruncate in round %d failed\n", i + 1); - return 1; - } - - if (TEMP_FAILURE_RETRY (write (fd, tests[i].data, tests[i].datalen)) - != tests[i].datalen) - { - printf ("write in round %d failed\n", i + 1); - return 1; - } - - if (lseek (fd, 0, SEEK_SET) != 0) - { - printf ("lseek in round %d failed\n", i + 1); - return 1; - } - - char *ccs; - if (asprintf (&ccs, "r,ccs=%s", tests[i].enc) == -1) - { - printf ("asprintf in round %d failed\n", i + 1); - return 1; - } - - FILE *fp = fopen (tmpname, ccs); - if (fp == NULL) - { - printf ("fopen in round %d failed\n", i + 1); - return 1; - } - -#define LINELEN 100 - wchar_t line[LINELEN]; - if (fgetws (line, LINELEN, fp) != line) - { - printf ("fgetws in round %d failed\n", i + 1); - return 1; - } - - if (wcslen (line) != tests[i].expectedlen) - { - printf ("round %d: expected length %zu, got length %zu\n", - i + 1, tests[i].expectedlen, wcslen (line)); - return 1; - } - - if (wcscmp (tests[i].expected, line) != 0) - { - printf ("round %d: expected L\"%ls\", got L\"%ls\"\n", - i + 1, tests[i].expected, line); - return 1; - } - - fclose (fp); - - free (ccs); - } - - close (fd); - - return 0; -} diff --git a/libio/tst-memstream1.c b/libio/tst-memstream1.c deleted file mode 100644 index d18f5cc22a..0000000000 --- a/libio/tst-memstream1.c +++ /dev/null @@ -1,89 +0,0 @@ -#include <mcheck.h> -#include <stdio.h> - - -#ifndef CHAR_T -# define CHAR_T char -# define W(o) o -# define OPEN_MEMSTREAM open_memstream -#endif - -#define S(s) S1 (s) -#define S1(s) #s - - -static void -mcheck_abort (enum mcheck_status ev) -{ - printf ("mecheck failed with status %d\n", (int) ev); - exit (1); -} - - -static int -do_test (void) -{ - mcheck_pedantic (mcheck_abort); - - CHAR_T *buf = (CHAR_T *) 1l; - size_t len = 12345; - FILE *fp = OPEN_MEMSTREAM (&buf, &len); - if (fp == NULL) - { - printf ("%s failed\n", S(OPEN_MEMSTREAM)); - return 1; - } - - if (fflush (fp) != 0) - { - puts ("fflush failed"); - return 1; - } - - if (len != 0) - { - puts ("string after no write not empty"); - return 1; - } - if (buf == (CHAR_T *) 1l) - { - puts ("buf not updated"); - return 1; - } - if (buf[0] != W('\0')) - { - puts ("buf[0] != 0"); - return 1; - } - - buf = (CHAR_T *) 1l; - len = 12345; - if (fclose (fp) != 0) - { - puts ("fclose failed"); - return 1; - } - - if (len != 0) - { - puts ("string after close with no write not empty"); - return 1; - } - if (buf == (CHAR_T *) 1l) - { - puts ("buf not updated"); - return 1; - } - if (buf[0] != W('\0')) - { - puts ("buf[0] != 0"); - return 1; - } - - free (buf); - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/libio/tst-memstream2.c b/libio/tst-memstream2.c deleted file mode 100644 index 9619d7725d..0000000000 --- a/libio/tst-memstream2.c +++ /dev/null @@ -1,104 +0,0 @@ -#include <mcheck.h> -#include <stdio.h> - - -#ifndef CHAR_T -# define CHAR_T char -# define W(o) o -# define OPEN_MEMSTREAM open_memstream -#endif - -#define S(s) S1 (s) -#define S1(s) #s - - -static void -mcheck_abort (enum mcheck_status ev) -{ - printf ("mecheck failed with status %d\n", (int) ev); - exit (1); -} - - -static int -do_test (void) -{ - mcheck_pedantic (mcheck_abort); - - CHAR_T *buf = (CHAR_T *) 1l; - size_t len = 12345; - FILE *fp = OPEN_MEMSTREAM (&buf, &len); - if (fp == NULL) - { - printf ("%s failed\n", S(OPEN_MEMSTREAM)); - return 1; - } - - for (int outer = 0; outer < 800; ++outer) - { - for (int inner = 0; inner < 100; ++inner) - if (fputc (W('a') + (outer * 100 + inner) % 26, fp) == EOF) - { - printf ("fputc at %d:%d failed\n", outer, inner); - return 1; - } - - if (fflush (fp) != 0) - { - puts ("fflush failed"); - return 1; - } - - if (len != (outer + 1) * 100) - { - printf ("string in round %d not %d bytest long\n", - outer + 1, (outer + 1) * 100); - return 1; - } - if (buf == (CHAR_T *) 1l) - { - printf ("round %d: buf not updated\n", outer + 1); - return 1; - } - for (int inner = 0; inner < (outer + 1) * 100; ++inner) - if (buf[inner] != W('a') + inner % 26) - { - printf ("round %d: buf[%d] != '%c'\n", outer + 1, inner, - (char) (W('a') + inner % 26)); - return 1; - } - } - - buf = (CHAR_T *) 1l; - len = 12345; - if (fclose (fp) != 0) - { - puts ("fclose failed"); - return 1; - } - - if (len != 800 * 100) - { - puts ("string after close not 80000 bytes long"); - return 1; - } - if (buf == (CHAR_T *) 1l) - { - puts ("buf not updated"); - return 1; - } - for (int inner = 0; inner < 800 * 100; ++inner) - if (buf[inner] != W('a') + inner % 26) - { - printf ("after close: buf[%d] != %c\n", inner, - (char) (W('a') + inner % 26)); - return 1; - } - - free (buf); - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/libio/tst-setvbuf1.c b/libio/tst-setvbuf1.c deleted file mode 100644 index 9222d4050d..0000000000 --- a/libio/tst-setvbuf1.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Dereived from the test case in BZ #2337. */ -#include <errno.h> -#include <error.h> -#include <fcntl.h> -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <wchar.h> - - -static char buf[512] __attribute__ ((aligned (4096))); - - -static int -do_test (void) -{ - setlocale (LC_ALL, "de_DE.UTF-8"); - - FILE *fp = fdopen (dup (STDOUT_FILENO), "a"); - if (fp == NULL) - error (EXIT_FAILURE, errno, "fdopen(,\"a\")"); - - setvbuf (fp, buf, _IOFBF, sizeof (buf)); - - /* fwprintf to unbuffered stream. */ - fwprintf (fp, L"hello.\n"); - - fclose (fp); - - /* touch my buffer */ - buf[45] = 'a'; - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/libio/tst-wmemstream1.c b/libio/tst-wmemstream1.c deleted file mode 100644 index f8b308bc6c..0000000000 --- a/libio/tst-wmemstream1.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <wchar.h> - -#define CHAR_T wchar_t -#define W(o) L##o -#define OPEN_MEMSTREAM open_wmemstream - -#include "tst-memstream1.c" diff --git a/libio/tst-wmemstream2.c b/libio/tst-wmemstream2.c deleted file mode 100644 index e2442ebfac..0000000000 --- a/libio/tst-wmemstream2.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <wchar.h> - -#define CHAR_T wchar_t -#define W(o) L##o -#define OPEN_MEMSTREAM open_wmemstream - -#include "tst-memstream2.c" diff --git a/libio/vasprintf.c b/libio/vasprintf.c index 2fdb9f6ed2..e32a488438 100644 --- a/libio/vasprintf.c +++ b/libio/vasprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1997,1999-2002,2004,2006 Free Software Foundation, Inc. +/* Copyright (C) 1995,1997,1999-2002,2004 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 @@ -46,8 +46,6 @@ _IO_vasprintf (result_ptr, format, args) int ret; _IO_size_t needed; _IO_size_t allocated; - /* No need to clear the memory here (unlike for open_memstream) since - we know we will never seek on the stream. */ string = (char *) malloc (init_string_size); if (string == NULL) return -1; @@ -89,4 +87,7 @@ _IO_vasprintf (result_ptr, format, args) (*result_ptr)[needed - 1] = '\0'; return ret; } -ldbl_weak_alias (_IO_vasprintf, vasprintf) + +#ifdef weak_alias +weak_alias (_IO_vasprintf, vasprintf) +#endif diff --git a/libio/vscanf.c b/libio/vscanf.c index 78c30eefdf..477cbaee84 100644 --- a/libio/vscanf.c +++ b/libio/vscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 2002, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 2002 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 @@ -37,4 +37,7 @@ _IO_vscanf (format, args) { return INTUSE(_IO_vfscanf) (_IO_stdin, format, args, NULL); } -ldbl_weak_alias (_IO_vscanf, vscanf) + +#ifdef weak_alias +weak_alias (_IO_vscanf, vscanf) +#endif diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c index 289160e540..4250c2d2de 100644 --- a/libio/vsnprintf.c +++ b/libio/vsnprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994,1997,1999-2003, 2004, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1994,1997,1999-2003, 2004 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 @@ -123,5 +123,8 @@ _IO_vsnprintf (string, maxlen, format, args) *sf.f._sbf._f._IO_write_ptr = '\0'; return ret; } -ldbl_weak_alias (_IO_vsnprintf, __vsnprintf) -ldbl_weak_alias (_IO_vsnprintf, vsnprintf) + +#ifdef weak_alias +weak_alias (_IO_vsnprintf, __vsnprintf) +weak_alias (_IO_vsnprintf, vsnprintf) +#endif diff --git a/libio/vswprintf.c b/libio/vswprintf.c index 5bbd20227b..42168aade4 100644 --- a/libio/vswprintf.c +++ b/libio/vswprintf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1994, 1997, 1999-2002, 2004, 2005, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1994,1997,1999-2002,2004 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 @@ -30,6 +29,15 @@ #include "strfile.h" +typedef struct +{ + _IO_strfile f; + /* This is used for the characters which do not fit in the buffer + provided by the user. */ + wchar_t overflow_buf[64]; +} _IO_wstrnfile; + + static wint_t _IO_wstrn_overflow (_IO_FILE *fp, wint_t c) __THROW; static wint_t @@ -67,7 +75,7 @@ _IO_wstrn_overflow (fp, c) } -const struct _IO_jump_t _IO_wstrn_jumps attribute_hidden = +static const struct _IO_jump_t _IO_wstrn_jumps = { JUMP_INIT_DUMMY, JUMP_INIT(finish, _IO_wstr_finish), @@ -127,5 +135,8 @@ _IO_vswprintf (string, maxlen, format, args) return ret; } + +#ifdef weak_alias weak_alias (_IO_vswprintf, __vswprintf) -ldbl_weak_alias (_IO_vswprintf, vswprintf) +weak_alias (_IO_vswprintf, vswprintf) +#endif diff --git a/libio/vwprintf.c b/libio/vwprintf.c index bd9a950c7c..814fdf32bf 100644 --- a/libio/vwprintf.c +++ b/libio/vwprintf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991, 1993, 1995, 1997, 1999, 2001, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1991,1993,1995,1997,1999,2001 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 @@ -17,7 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -25,8 +23,9 @@ /* Write formatted output to stdout according to the format string FORMAT, using the argument list in ARG. */ int -__vwprintf (const wchar_t *format, __gnuc_va_list arg) +vwprintf (format, arg) + const wchar_t *format; + __gnuc_va_list arg; { return __vfwprintf (stdout, format, arg); } -ldbl_strong_alias (__vwprintf, vwprintf) diff --git a/libio/vwscanf.c b/libio/vwscanf.c index f6d04e8e87..cd7af9ce5b 100644 --- a/libio/vwscanf.c +++ b/libio/vwscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 1999, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 1999 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 @@ -29,8 +29,9 @@ #include <wchar.h> int -__vwscanf (const wchar_t *format, _IO_va_list args) +vwscanf (format, args) + const wchar_t *format; + _IO_va_list args; { return _IO_vfwscanf (_IO_stdin, format, args, NULL); } -ldbl_strong_alias (__vwscanf, vwscanf) diff --git a/libio/wfiledoalloc.c b/libio/wfiledoalloc.c index 67a05175b2..2f8140b0ac 100644 --- a/libio/wfiledoalloc.c +++ b/libio/wfiledoalloc.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1993, 1997, 1999, 2000, 2002, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 1999, 2000, 2002 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 @@ -86,20 +85,35 @@ _IO_wfile_doallocate (fp) _IO_FILE *fp; { _IO_size_t size; + int couldbetty; wchar_t *p; + struct _G_stat64 st; /* Allocate room for the external buffer. */ if (fp->_IO_buf_base == NULL) INTUSE(_IO_file_doallocate) (fp); - /* If narrow buffer is user allocated (set by setvbuf etc.), - use that size as the size of the wide buffer, when it is - allocated by _IO_file_doallocate, multiply that by size - of the wide character. */ - size = fp->_IO_buf_end - fp->_IO_buf_base; - if ((fp->_flags & _IO_USER_BUF)) - size = (size + sizeof (wchar_t) - 1) / sizeof (wchar_t); + if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0) + { + couldbetty = 0; + size = _IO_BUFSIZ; +#if 0 + /* do not try to optimise fseek() */ + fp->_flags |= __SNPT; +#endif + } + else + { + couldbetty = S_ISCHR (st.st_mode); +#if _IO_HAVE_ST_BLKSIZE + size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize; +#else + size = _IO_BUFSIZ; +#endif + } ALLOC_WBUF (p, size * sizeof (wchar_t), EOF); INTUSE(_IO_wsetb) (fp, p, p + size, 1); + if (couldbetty && isatty (fp->_fileno)) + fp->_flags |= _IO_LINE_BUF; return 1; } diff --git a/libio/wfileops.c b/libio/wfileops.c index b930aad067..5f9faac223 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2003,2004, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2003,2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@cygnus.com>. Based on the single byte version by Per Bothner <bothner@cygnus.com>. @@ -69,7 +69,7 @@ _IO_wdo_write (fp, data, to_do) { if (_IO_new_do_write (fp, fp->_IO_write_base, fp->_IO_write_ptr - fp->_IO_write_base) == EOF) - return WEOF; + return EOF; } do diff --git a/libio/wgenops.c b/libio/wgenops.c index 760a413dc3..a9cc7bf210 100644 --- a/libio/wgenops.c +++ b/libio/wgenops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2002,2004,2006 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2001,2002,2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@cygnus.com>. Based on the single byte version by Per Bothner <bothner@cygnus.com>. @@ -115,14 +115,14 @@ _IO_wsetb (f, b, eb, a) wchar_t *eb; int a; { - if (f->_wide_data->_IO_buf_base && !(f->_flags2 & _IO_FLAGS2_USER_WBUF)) - FREE_BUF (f->_wide_data->_IO_buf_base, _IO_wblen (f) * sizeof (wchar_t)); + if (f->_wide_data->_IO_buf_base && !(f->_flags & _IO_USER_BUF)) + FREE_BUF (f->_wide_data->_IO_buf_base, _IO_wblen (f)); f->_wide_data->_IO_buf_base = b; f->_wide_data->_IO_buf_end = eb; if (a) - f->_flags2 &= ~_IO_FLAGS2_USER_WBUF; + f->_flags &= ~_IO_USER_BUF; else - f->_flags2 |= _IO_FLAGS2_USER_WBUF; + f->_flags |= _IO_USER_BUF; } INTDEF(_IO_wsetb) @@ -198,7 +198,7 @@ _IO_wdefault_finish (fp, dummy) int dummy; { struct _IO_marker *mark; - if (fp->_wide_data->_IO_buf_base && !(fp->_flags2 & _IO_FLAGS2_USER_WBUF)) + if (fp->_wide_data->_IO_buf_base && !(fp->_flags & _IO_USER_BUF)) { FREE_BUF (fp->_wide_data->_IO_buf_base, _IO_wblen (fp) * sizeof (wchar_t)); diff --git a/libio/wmemstream.c b/libio/wmemstream.c deleted file mode 100644 index 7bf6a429ac..0000000000 --- a/libio/wmemstream.c +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright (C) 1995-97,99,2000,2002-2004,2006 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "libioP.h" -#include "strfile.h" -#include <stdio.h> -#include <stdlib.h> -#include <wchar.h> - - -struct _IO_FILE_wmemstream -{ - _IO_strfile _sf; - wchar_t **bufloc; - _IO_size_t *sizeloc; -}; - - -static int _IO_wmem_sync (_IO_FILE* fp) __THROW; -static void _IO_wmem_finish (_IO_FILE* fp, int) __THROW; - - -static const struct _IO_jump_t _IO_wmem_jumps = -{ - JUMP_INIT_DUMMY, - JUMP_INIT (finish, _IO_wmem_finish), - JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow), - JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow), - JUMP_INIT (uflow, (_IO_underflow_t) INTUSE(_IO_wdefault_uflow)), - JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), - JUMP_INIT (xsputn, INTUSE(_IO_wdefault_xsputn)), - JUMP_INIT (xsgetn, INTUSE(_IO_wdefault_xsgetn)), - JUMP_INIT (seekoff, _IO_wstr_seekoff), - JUMP_INIT (seekpos, _IO_default_seekpos), - JUMP_INIT (setbuf, _IO_default_setbuf), - JUMP_INIT (sync, _IO_wmem_sync), - JUMP_INIT (doallocate, INTUSE(_IO_wdefault_doallocate)), - JUMP_INIT (read, _IO_default_read), - JUMP_INIT (write, _IO_default_write), - JUMP_INIT (seek, _IO_default_seek), - JUMP_INIT (close, _IO_default_close), - JUMP_INIT (stat, _IO_default_stat), - JUMP_INIT (showmanyc, _IO_default_showmanyc), - JUMP_INIT (imbue, _IO_default_imbue) -}; - -/* Open a stream that writes into a malloc'd buffer that is expanded as - necessary. *BUFLOC and *SIZELOC are updated with the buffer's location - and the number of characters written on fflush or fclose. */ -_IO_FILE * -open_wmemstream (bufloc, sizeloc) - wchar_t **bufloc; - _IO_size_t *sizeloc; -{ - struct locked_FILE - { - struct _IO_FILE_wmemstream fp; -#ifdef _IO_MTSAFE_IO - _IO_lock_t lock; -#endif - struct _IO_wide_data wd; - } *new_f; - wchar_t *buf; - - new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); - if (new_f == NULL) - return NULL; -#ifdef _IO_MTSAFE_IO - new_f->fp._sf._sbf._f._lock = &new_f->lock; -#endif - - buf = calloc (1, _IO_BUFSIZ); - if (buf == NULL) - return NULL; - - _IO_no_init (&new_f->fp._sf._sbf._f, 0, 0, &new_f->wd, &_IO_wmem_jumps); - _IO_fwide (&new_f->fp._sf._sbf._f, 1); - _IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf, - _IO_BUFSIZ / sizeof (wchar_t), buf); - new_f->fp._sf._sbf._f._flags2 &= ~_IO_FLAGS2_USER_WBUF; - new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc; - new_f->fp._sf._s._free_buffer = (_IO_free_type) free; - - new_f->fp.bufloc = bufloc; - new_f->fp.sizeloc = sizeloc; - - return (_IO_FILE *) &new_f->fp._sf._sbf; -} - - -static int -_IO_wmem_sync (fp) - _IO_FILE* fp; -{ - struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; - - if (fp->_wide_data->_IO_write_ptr == fp->_wide_data->_IO_write_end) - { - _IO_wstr_overflow (fp, '\0'); - --fp->_wide_data->_IO_write_ptr; - } - else - *fp->_wide_data->_IO_write_ptr = '\0'; - - *mp->bufloc = fp->_wide_data->_IO_write_base; - *mp->sizeloc = (fp->_wide_data->_IO_write_ptr - - fp->_wide_data->_IO_write_base); - - return 0; -} - - -static void -_IO_wmem_finish (fp, dummy) - _IO_FILE* fp; - int dummy; -{ - struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; - - *mp->bufloc = (wchar_t *) realloc (fp->_wide_data->_IO_write_base, - (fp->_wide_data->_IO_write_ptr - - fp->_wide_data->_IO_write_base + 1) - * sizeof (wchar_t)); - if (*mp->bufloc != NULL) - { - size_t len = (fp->_wide_data->_IO_write_ptr - - fp->_wide_data->_IO_write_base); - (*mp->bufloc)[len] = '\0'; - *mp->sizeloc = len; - - fp->_wide_data->_IO_buf_base = NULL; - } - - _IO_wstr_finish (fp, 0); -} diff --git a/libio/wprintf.c b/libio/wprintf.c index d06451c15a..f418cf515d 100644 --- a/libio/wprintf.c +++ b/libio/wprintf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1997, 1999, 2001, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1991,1995,1996,1997,1999,2001 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 @@ -17,7 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -25,7 +23,7 @@ /* Write formatted output to stdout from the format string FORMAT. */ /* VARARGS1 */ int -__wprintf (const wchar_t *format, ...) +wprintf (const wchar_t *format, ...) { va_list arg; int done; @@ -36,4 +34,3 @@ __wprintf (const wchar_t *format, ...) return done; } -ldbl_strong_alias (__wprintf, wprintf) diff --git a/libio/wscanf.c b/libio/wscanf.c index 3eba6207c3..f4b8cd1b83 100644 --- a/libio/wscanf.c +++ b/libio/wscanf.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1997, 1999, 2006 - Free Software Foundation, Inc. +/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 @@ -17,7 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -26,7 +24,7 @@ /* Read formatted input from stdin according to the format string FORMAT. */ /* VARARGS1 */ int -__wscanf (const wchar_t *format, ...) +wscanf (const wchar_t *format, ...) { va_list arg; int done; @@ -37,4 +35,3 @@ __wscanf (const wchar_t *format, ...) return done; } -ldbl_strong_alias (__wscanf, wscanf) diff --git a/libio/wstrops.c b/libio/wstrops.c index c5aae7bc6a..32f7ef3cf7 100644 --- a/libio/wstrops.c +++ b/libio/wstrops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1997-1999,2001-2004, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1993,1997-1999,2001-2003,2004 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 @@ -25,13 +25,44 @@ This exception applies to code released by its copyright holders in files containing the exception. */ -#include <assert.h> #include "strfile.h" #include "libioP.h" #include <string.h> #include <wchar.h> #include <stdio_ext.h> +#if 0 +/* The following definitions are for exposition only. + They map the terminology used in the ANSI/ISO C++ draft standard + to the implementation. */ + +/* allocated: set when a dynamic array object has been allocated, and + hence should be freed by the destructor for the strstreambuf object. */ +#define ALLOCATED(FP) ((FP)->_f._IO_buf_base && DYNAMIC(FP)) + +/* constant: set when the array object has const elements, + so the output sequence cannot be written. */ +#define CONSTANT(FP) ((FP)->_f._IO_file_flags & _IO_NO_WRITES) + +/* alsize: the suggested minimum size for a dynamic array object. */ +#define ALSIZE(FP) ??? /* not stored */ + +/* palloc: points to the function to call to allocate a dynamic array object.*/ +#define PALLOC(FP) \ + ((FP)->_s._allocate_buffer == default_alloc ? 0 : (FP)->_s._allocate_buffer) + +/* pfree: points to the function to call to free a dynamic array object. */ +#define PFREE(FP) \ + ((FP)->_s._free_buffer == default_free ? 0 : (FP)->_s._free_buffer) + +#endif + +#ifdef TODO +/* An "unbounded buffer" is when a buffer is supplied, but with no + specified length. An example is the buffer argument to sprintf. + */ +#endif + void _IO_wstr_init_static (fp, ptr, size, pstart) _IO_FILE *fp; @@ -67,7 +98,7 @@ _IO_wstr_init_static (fp, ptr, size, pstart) fp->_wide_data->_IO_read_end = end; } /* A null _allocate_buffer function flags the strfile as being static. */ - (((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0; + (((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0; } _IO_wint_t @@ -85,19 +116,16 @@ _IO_wstr_overflow (fp, c) fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_read_ptr; fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end; } - pos = fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base; + pos = fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base; if (pos >= (_IO_size_t) (_IO_wblen (fp) + flush_only)) { - if (fp->_flags2 & _IO_FLAGS2_USER_WBUF) /* not allowed to enlarge */ + if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */ return WEOF; else { wchar_t *new_buf; wchar_t *old_buf = fp->_wide_data->_IO_buf_base; - size_t old_wblen = _IO_wblen (fp); - _IO_size_t new_size = 2 * old_wblen + 100; - if (new_size < old_wblen) - return EOF; + _IO_size_t new_size = 2 * _IO_wblen (fp) + 100; new_buf = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size * sizeof (wchar_t)); @@ -108,14 +136,11 @@ _IO_wstr_overflow (fp, c) } if (old_buf) { - __wmemcpy (new_buf, old_buf, old_wblen); + __wmemcpy (new_buf, old_buf, _IO_wblen (fp)); (*((_IO_strfile *) fp)->_s._free_buffer) (old_buf); /* Make sure _IO_setb won't try to delete _IO_buf_base. */ fp->_wide_data->_IO_buf_base = NULL; } - - wmemset (new_buf + old_wblen, L'\0', new_size - old_wblen); - INTUSE(_IO_wsetb) (fp, new_buf, new_buf + new_size, 1); fp->_wide_data->_IO_read_base = new_buf + (fp->_wide_data->_IO_read_base - old_buf); @@ -138,7 +163,6 @@ _IO_wstr_overflow (fp, c) return c; } - _IO_wint_t _IO_wstr_underflow (fp) _IO_FILE *fp; @@ -157,87 +181,17 @@ _IO_wstr_underflow (fp) return WEOF; } - /* The size of the valid part of the buffer. */ + _IO_ssize_t _IO_wstr_count (fp) _IO_FILE *fp; { - struct _IO_wide_data *wd = fp->_wide_data; - - return ((wd->_IO_write_ptr > wd->_IO_read_end - ? wd->_IO_write_ptr : wd->_IO_read_end) - - wd->_IO_read_base); + return ((fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_read_end + ? fp->_wide_data->_IO_write_ptr : fp->_wide_data->_IO_read_end) + - fp->_wide_data->_IO_read_base); } - -static int -enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading) -{ - if ((_IO_ssize_t) offset <= _IO_blen (fp)) - return 0; - - struct _IO_wide_data *wd = fp->_wide_data; - - _IO_ssize_t oldend = wd->_IO_write_end - wd->_IO_write_base; - - /* Try to enlarge the buffer. */ - if (fp->_flags2 & _IO_FLAGS2_USER_WBUF) - /* User-provided buffer. */ - return 1; - - _IO_size_t newsize = offset + 100; - wchar_t *oldbuf = wd->_IO_buf_base; - wchar_t *newbuf - = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize - * sizeof (wchar_t)); - if (newbuf == NULL) - return 1; - - if (oldbuf != NULL) - { - __wmemcpy (newbuf, oldbuf, _IO_wblen (fp)); - (*((_IO_strfile *) fp)->_s._free_buffer) (oldbuf); - /* Make sure _IO_setb won't try to delete - _IO_buf_base. */ - wd->_IO_buf_base = NULL; - } - - INTUSE(_IO_wsetb) (fp, newbuf, newbuf + newsize, 1); - - if (reading) - { - wd->_IO_write_base = newbuf + (wd->_IO_write_base - oldbuf); - wd->_IO_write_ptr = newbuf + (wd->_IO_write_ptr - oldbuf); - wd->_IO_write_end = newbuf + (wd->_IO_write_end - oldbuf); - wd->_IO_read_ptr = newbuf + (wd->_IO_read_ptr - oldbuf); - - wd->_IO_read_base = newbuf; - wd->_IO_read_end = wd->_IO_buf_end; - } - else - { - wd->_IO_read_base = newbuf + (wd->_IO_read_base - oldbuf); - wd->_IO_read_ptr = newbuf + (wd->_IO_read_ptr - oldbuf); - wd->_IO_read_end = newbuf + (wd->_IO_read_end - oldbuf); - wd->_IO_write_ptr = newbuf + (wd->_IO_write_ptr - oldbuf); - - wd->_IO_write_base = newbuf; - wd->_IO_write_end = wd->_IO_buf_end; - } - - /* Clear the area between the last write position and th - new position. */ - assert (offset >= oldend); - if (reading) - wmemset (wd->_IO_read_base + oldend, L'\0', offset - oldend); - else - wmemset (wd->_IO_write_base + oldend, L'\0', offset - oldend); - - return 0; -} - - _IO_off64_t _IO_wstr_seekoff (fp, offset, dir, mode) _IO_FILE *fp; @@ -280,10 +234,7 @@ _IO_wstr_seekoff (fp, offset, dir, mode) default: /* case _IO_seek_set: */ break; } - if (offset < 0) - return EOF; - if ((_IO_ssize_t) offset > cur_size - && enlarge_userbuf (fp, offset, 1) != 0) + if (offset < 0 || (_IO_ssize_t) offset > cur_size) return EOF; fp->_wide_data->_IO_read_ptr = (fp->_wide_data->_IO_read_base + offset); @@ -307,10 +258,7 @@ _IO_wstr_seekoff (fp, offset, dir, mode) default: /* case _IO_seek_set: */ break; } - if (offset < 0) - return EOF; - if ((_IO_ssize_t) offset > cur_size - && enlarge_userbuf (fp, offset, 0) != 0) + if (offset < 0 || (_IO_ssize_t) offset > cur_size) return EOF; fp->_wide_data->_IO_write_ptr = (fp->_wide_data->_IO_write_base + offset); @@ -335,7 +283,7 @@ _IO_wstr_finish (fp, dummy) _IO_FILE *fp; int dummy; { - if (fp->_wide_data->_IO_buf_base && !(fp->_flags2 & _IO_FLAGS2_USER_WBUF)) + if (fp->_wide_data->_IO_buf_base && !(fp->_flags & _IO_USER_BUF)) (((_IO_strfile *) fp)->_s._free_buffer) (fp->_wide_data->_IO_buf_base); fp->_wide_data->_IO_buf_base = NULL; |