From d64b6ad07585b8a37e5fecc9a47fcee766d52ede Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 16 Jun 1999 22:55:47 +0000 Subject: Update. * Versions.def: Add GLIBC_2.2 for libc. * iconv/gconv.h: Make header suitable for inclusion in public header by protecting all names with __. * iconv/gconv.c: Adapt for symbol name changes. * iconv/gconv.h: Likewise. * iconv/gconv_builtin.c: Likewise. * iconv/gconv_close.c: Likewise. * iconv/gconv_db.c: Likewise. * iconv/gconv_dl.c: Likewise. * iconv/gconv_int.h: Likewise. * iconv/gconv_open.c: Likewise. * iconv/gconv_simple.c: Likewise. * iconv/iconv.c: Likewise. * iconv/iconv_close.c: Likewise. * iconv/iconv_open.c: Likewise. * iconv/loop.c: Likewise. * iconv/skeleton.c: Likewise. * iconvdata/8bit-gap.c: Likewise. * iconvdata/8bit-generic.c: Likewise. * iconvdata/ansi_x3.110.c: Likewise. * iconvdata/big5.c: Likewise. * iconvdata/cns11643.h: Likewise. * iconvdata/cns11643l1.h: Likewise. * iconvdata/euc-cn.c: Likewise. * iconvdata/euc-jp.c: Likewise. * iconvdata/euc-kr.c: Likewise. * iconvdata/euc-tw.c: Likewise. * iconvdata/gb2312.h: Likewise. * iconvdata/iso-2022-jp.c: Likewise. * iconvdata/iso-2022-kr.c: Likewise. * iconvdata/iso646.c: Likewise. * iconvdata/iso8859-1.c: Likewise. * iconvdata/iso_6937-2.c: Likewise. * iconvdata/iso_6937.c: Likewise. * iconvdata/jis0201.h: Likewise. * iconvdata/jis0208.h: Likewise. * iconvdata/jis0212.h: Likewise. * iconvdata/johab.c: Likewise. * iconvdata/ksc5601.h: Likewise. * iconvdata/sjis.c: Likewise. * iconvdata/t.61.c: Likewise. * iconvdata/uhc.c: Likewise. * stdlib/mblen.c: Likewise. * stdlib/mbtowc.c: Likewise. * stdlib/wctomb.c: Likewise. * wcsmbs/btowc.c: Likewise. * wcsmbs/mbrtowc.c: Likewise. * wcsmbs/mbsnrtowcs.c: Likewise. * wcsmbs/mbsrtowcs.c: Likewise. * wcsmbs/wchar.h: Likewise. * wcsmbs/wcrtomb.c: Likewise. * wcsmbs/wcsmbsload.c: Likewise. * wcsmbs/wcsmbsload.h: Likewise. * wcsmbs/wcsnrtombs.c: Likewise. * wcsmbs/wcsrtombs.c: Likewise. * wcsmbs/wctob.c: Likewise. * include/limits.h (MB_LEN_MAX): Increase to 16. * sysdeps/generic/_G_config.h: Define _G_fpos_t as struct. Define _G_iconv_t. * sysdeps/unix/sysv/linux/_G_config.h: Likewise. * include/wchar.h: Change mbstate_t to __mbstate_t. * libio/Makefile (routines): Add wfiledoalloc, oldiofgetpos, oldiofgetpos64, oldiofsetpos, oldiofsetpos64, fputwc, fputwc_u, getwc, getwc_u, getwchar, getwchar_u, iofgetws, iofgetws_u, iofputws, iofputws_u, iogetwline, iowpadn, ioungetwc, putwc, putwc_u, putchar, putchar_u, swprintf, vwprintf, wprintf, wscanf, fwscanf, vwscanf, vswprintf, iovswscanf, swscanf, wgenops, wstrops, wfileops, and iofwide. (tests): Add tst_swprintf, tst_wprintf, tst_swscanf, and tst_wscanf. * libio/Versions: Add _IO_fgetpos, _IO_fgetpos64, _IO_fsetpos, _IO_fsetpos64, fgetpos, fgetpos64, fgetwc, fgetwc_unlocked, fgetws, fgetws_unlocked, fputwc, fputwc_unlocked, fputws, fputws_unlocked, fsetpos, fsetpos64, fwide, fwprintf, fwscanf, getwc, getwc_unlocked, getwchar, getwchar_unlocked, putwc, putwc_unlocked, putwchar, putwchar_unlocked, swprintf, swscanf, ungetwc, vfwprintf, vswprintf, vwprintf, vfwscanf, vswscanf, vwscanf, wprintf, and wscanf to GLIBC_2.2 for libc. * libio/libio.h: Define codecvt struct. Define _IO_wide_data. Extend _IO_file contain pointer to codecvt, widedata and mode. (_IO_getwc_unlocked): New macro. (_IO_putwc_unlocked): New macro. (_IO_fwide): New macro. * libio/libioP.h: Add new prototypes and adjust existing declarations. * libio/fileops.c (_IO_new_file_close_it): Reset normal or widedata buffers based on mode. (new_do_write): Set _IO_write_end to _IO_buf_end if stream is wide oriented. (_IO_new_file_overflow): Don't depend only on _IO_CURRENTLY_PUTTING flag to be enough to signal unallocated buffer. For wide oriented stream don't make it linebuffered. Don't use _IO_do_flush, use _IO_new_do_write directly. (_IO_new_file_seekoff): Change return value type to _IO_off64_t. (_IO_file_seek): Likewise. * libio/genops.c (_IO_least_marker): Make global. (__underflow): Orient stream if not already done. (__uflow): Likewise. (_IO_default_seekpos): Change to type _IO_off64_t. (_IO_default_seekoff): Likewise. (_IO_default_seek): Likewise. (_IO_no_init): New function. Similar to _IO_init but allows to orient in initialization. * libio/iolibio.h: Add prototype for _IO_vswprintf. Change _IO_pos_BAD to use _IO_off64_t. * libio/ftello.c: Use _IO_off_t. For now abort when use with wide char stream. * libio/ftello64.c: Likewise. * libio/ioftell.c: Likewise. * libio/iofopncook.c: Likewise. * libio/ioseekoff.c: Likewise. * libio/ioseekpos.c: Likewise. * libio/oldfileops.c: Likewise. * libio/iofgetpos.c: Store state of conversion if necessary. * libio/iofgetpos64.c: Likewise. * libio/iofsetpos.c: Restore conversion state if necessary. * libio/iofsetpos64.c: Likewise. * libio/iofdopen.c: Initialize so that stream can be wide oriented. * libio/iofopen.c: Likewise. * libio/iofopen64.c: Likewise. * libio/iopopen.c: Likewise. * libio/iovdprintf.c: Likewise. * libio/iovsprintf.c: Likewise. * libio/iovsscanf.c: Likewise. * libio/memstream.c: Likewise. * libio/obprintf.c: Likewise. * libio/iofputs.c: Orient stream if not already happened. * libio/iofputs_u.c: Likewise. * libio/iofwrite.c: Likewise. * libio/iofwrite_u.c: Likewise. * libio/ioputs.c: Likewise. * libio/iosetbuffer.c: Handle not yet oriented stream. * libio/iosetvbuf.c: Likewise. * libio/oldstdfiles.c: Adjust FILEBUF_LITERAL call. * libio/stdfiles.c: Likewise. * libio/strops.c (_IO_str_overflow): Correctly free buffer after failed allocation. (_IO_str_seekoff): Use _IO_off64_t. * libio/vasprintf.c: Pre-orient stream. * libio/vsnprintf.c: Likewise. * libio/fputwc.c: New file. * libio/fputwc_u.c: New file. * libio/fwprintf.c: New file. * libio/fwscanf.c: New file. * libio/getwc.c: New file. * libio/getwc_u.c: New file. * libio/getwchar.c: New file. * libio/getwchar_u.c: New file. * libio/iofgetws.c: New file. * libio/iofgetws_u.c: New file. * libio/iofputws.c: New file. * libio/iofputws_u.c: New file. * libio/iofwide.c: New file. * libio/iogetwline.c: New file. * libio/ioungetwc.c: New file. * libio/iovswscanf.c: New file. * libio/iowpadn.c: New file. * libio/oldiofgetpos.c: New file. * libio/oldiofgetpos64.c: New file. * libio/oldiofsetpos.c: New file. * libio/oldiofsetpos64.c: New file. * libio/putwc.c: New file. * libio/putwc_u.c: New file. * libio/putwchar.c: New file. * libio/putwchar_u.c: New file. * libio/swprintf.c: New file. * libio/swscanf.c: New file. * libio/tst_swprintf.c: New file. * libio/tst_swscanf.c: New file. * libio/tst_wprintf.c: New file. * libio/tst_wscanf.c: New file. * libio/tst_wscanf.input: New file. * libio/vswprintf.c: New file. * libio/vwprintf.c: New file. * libio/vwscanf.c: New file. * libio/wfiledoalloc.c: New file. * libio/wfileops.c: New file. * libio/wgenops.c: New file. * libio/wprintf.c: New file. * libio/wscanf.c: New file. * libio/wstrops.c: New file. * stdio-common/Makefile (routines): Add _itowa, itowa-digits, vfwprintf, and vfwscanf. * stdio-common/_itoa.c (base_table): Rename to _IO_base_table and make global. * stdio-common/_itowa.c: New file. * stdio-common/_itowa.h: New file. * stdio-common/itoa-digits.c: Minimal optimization. * stdio-common/itowa-digits.c: New file. * stdio-common/printf-parse.h: Allow use in wide character context. * stdio-common/printf-prs.c: Define ISASCII and MBRLEN. * stdio-common/printf.h (printf_info): Add wide bit. * stdio-common/printf_fp.c: Determine from wide bit whether stream is wide oriented or not. * stdio-common/printf_size.c: Likewise. * sysdeps/generic/printf_fphex.c: Likewise. * stdlib/strfmon.c: Call __printf_fp with wide bit cleared. * stdio-common/vfprintf.c: Rewrite to allow use in wide character context. * stdio-common/vfscand.c: Likewise. * stdio-common/vfwprintf.c: New file. * stdio-common/vfwscanf.c: New file. * time/Makefile (routines): Add wcsftime. (tests): Add tst_wcsftime. * time/Versions: Add wcsftime to GLIBC_2.2 for libc. * time/strftime.c: Make usable as wcsftime. * time/wcsftime.c: New file. * time/tst_wcsftime.c: New file. * wcsmbs/Makefile (routines): Add wmempcpy and wcschrnul. * wcsmbs/Versions: Add wmempcpy and wcschrnul to GLIBC_2.2 for libc. * wcsmbs/wcschrnul.c: New file. * wcsmbs/wmemcpy.c: New file. * wcsmbs/wmemcpy.c: Rename to __wmemcpy and make wmemcpy weak alias. * wcsmbs/wmemmove.c: Likewise for wmemmove. * manual/stdio.texi: Document is_char and wide element if printf_info. * manual/time.texi: Document wcsftime. * include/wchar.h: Add prototypes for __wmemcpy, __wmempcpy, __wmemmove, __wcschrnul, and __vfwscanf. * locale/langinfo.h: Add new LC_TIME entries for wchar_t data. * locale/C-time.c: Adapt for above change. * locale/categories.def: Likewise. * locale/localeinfo.h: Likewise. * localedata/Makefile: Don't run tests for now. --- libio/Makefile | 9 +- libio/Versions | 27 ++ libio/fileops.c | 60 ++-- libio/fputwc.c | 45 +++ libio/fputwc_u.c | 40 +++ libio/ftello.c | 14 +- libio/ftello64.c | 13 +- libio/fwprintf.c | 36 +++ libio/fwscanf.c | 35 +++ libio/genops.c | 53 +++- libio/getwc.c | 50 ++++ libio/getwc_u.c | 39 +++ libio/getwchar.c | 42 +++ libio/getwchar_u.c | 35 +++ libio/iofdopen.c | 5 +- libio/iofgetpos.c | 16 +- libio/iofgetpos64.c | 20 +- libio/iofgetws.c | 63 +++++ libio/iofgetws_u.c | 59 ++++ libio/iofopen.c | 3 +- libio/iofopen64.c | 3 +- libio/iofopncook.c | 6 +- libio/iofputs.c | 9 +- libio/iofputs_u.c | 8 +- libio/iofputws.c | 45 +++ libio/iofputws_u.c | 42 +++ libio/iofsetpos.c | 18 +- libio/iofsetpos64.c | 18 +- libio/ioftell.c | 14 +- libio/iofwide.c | 365 ++++++++++++++++++++++++ libio/iofwrite.c | 7 +- libio/iofwrite_u.c | 17 +- libio/iogetwline.c | 120 ++++++++ libio/iolibio.h | 4 +- libio/iopopen.c | 28 +- libio/ioputs.c | 11 +- libio/ioseekoff.c | 28 +- libio/ioseekpos.c | 8 +- libio/iosetbuffer.c | 5 +- libio/iosetvbuf.c | 6 +- libio/ioungetwc.c | 44 +++ libio/iovdprintf.c | 5 +- libio/iovsprintf.c | 4 +- libio/iovsscanf.c | 4 +- libio/iovswscanf.c | 48 ++++ libio/iowpadn.c | 76 +++++ libio/libio.h | 114 +++++++- libio/libioP.h | 157 ++++++++--- libio/memstream.c | 85 +++++- libio/obprintf.c | 8 +- libio/oldfileops.c | 10 +- libio/oldiofgetpos.c | 61 ++++ libio/oldiofgetpos64.c | 66 +++++ libio/oldiofsetpos.c | 59 ++++ libio/oldiofsetpos64.c | 64 +++++ libio/oldstdfiles.c | 7 +- libio/putwc.c | 35 +++ libio/putwc_u.c | 29 ++ libio/putwchar.c | 34 +++ libio/putwchar_u.c | 28 ++ libio/stdfiles.c | 12 +- libio/strops.c | 10 +- libio/swprintf.c | 38 +++ libio/swscanf.c | 37 +++ libio/tst_swprintf.c | 42 +++ libio/tst_swscanf.c | 38 +++ libio/tst_wprintf.c | 10 + libio/tst_wscanf.c | 28 ++ libio/tst_wscanf.input | 1 + libio/vasprintf.c | 4 +- libio/vsnprintf.c | 4 +- libio/vswprintf.c | 144 ++++++++++ libio/vwprintf.c | 31 ++ libio/vwscanf.c | 35 +++ libio/wfiledoalloc.c | 105 +++++++ libio/wfileops.c | 716 +++++++++++++++++++++++++++++++++++++++++++++++ libio/wgenops.c | 747 +++++++++++++++++++++++++++++++++++++++++++++++++ libio/wprintf.c | 35 +++ libio/wscanf.c | 36 +++ libio/wstrops.c | 330 ++++++++++++++++++++++ 80 files changed, 4568 insertions(+), 199 deletions(-) create mode 100644 libio/fputwc.c create mode 100644 libio/fputwc_u.c create mode 100644 libio/fwprintf.c create mode 100644 libio/fwscanf.c create mode 100644 libio/getwc.c create mode 100644 libio/getwc_u.c create mode 100644 libio/getwchar.c create mode 100644 libio/getwchar_u.c create mode 100644 libio/iofgetws.c create mode 100644 libio/iofgetws_u.c create mode 100644 libio/iofputws.c create mode 100644 libio/iofputws_u.c create mode 100644 libio/iofwide.c create mode 100644 libio/iogetwline.c create mode 100644 libio/ioungetwc.c create mode 100644 libio/iovswscanf.c create mode 100644 libio/iowpadn.c create mode 100644 libio/oldiofgetpos.c create mode 100644 libio/oldiofgetpos64.c create mode 100644 libio/oldiofsetpos.c create mode 100644 libio/oldiofsetpos64.c create mode 100644 libio/putwc.c create mode 100644 libio/putwc_u.c create mode 100644 libio/putwchar.c create mode 100644 libio/putwchar_u.c create mode 100644 libio/swprintf.c create mode 100644 libio/swscanf.c create mode 100644 libio/tst_swprintf.c create mode 100644 libio/tst_swscanf.c create mode 100644 libio/tst_wprintf.c create mode 100644 libio/tst_wscanf.c create mode 100644 libio/tst_wscanf.input create mode 100644 libio/vswprintf.c create mode 100644 libio/vwprintf.c create mode 100644 libio/vwscanf.c create mode 100644 libio/wfiledoalloc.c create mode 100644 libio/wfileops.c create mode 100644 libio/wgenops.c create mode 100644 libio/wprintf.c create mode 100644 libio/wscanf.c create mode 100644 libio/wstrops.c (limited to 'libio') diff --git a/libio/Makefile b/libio/Makefile index 948556e15c..6fcde40814 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -25,11 +25,16 @@ headers := stdio.h libio.h _G_config.h bits/stdio.h routines := \ filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \ - iofopncook iofputs iofread iofsetpos ioftell \ + iofopncook iofputs iofread iofsetpos ioftell wfiledoalloc \ iofwrite iogetdelim iogetline iogets iopadn iopopen ioputs \ ioseekoff ioseekpos iosetbuffer iosetvbuf iosprintf ioungetc \ iovsprintf iovsscanf \ iofgetpos64 iofopen64 iofsetpos64 \ + oldiofgetpos oldiofgetpos64 oldiofsetpos oldiofsetpos64 \ + fputwc fputwc_u getwc getwc_u getwchar getwchar_u iofgetws iofgetws_u \ + iofputws iofputws_u iogetwline iowpadn ioungetwc putwc putwc_u \ + putchar putchar_u swprintf vwprintf wprintf wscanf fwscanf vwscanf \ + vswprintf iovswscanf swscanf wgenops wstrops wfileops iofwide \ \ clearerr feof ferror fileno fputc freopen fseek getc getchar \ memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \ @@ -38,6 +43,8 @@ routines := \ \ libc_fatal +tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf + all: # Make this the default target; it will be defined in Rules. include ../Makeconfig diff --git a/libio/Versions b/libio/Versions index 61b767a2d3..c7a5f668a1 100644 --- a/libio/Versions +++ b/libio/Versions @@ -100,4 +100,31 @@ libc { # p* pclose; popen; } + GLIBC_2.2 { + # functions used in libstdc++ + _IO_fgetpos; _IO_fgetpos64; _IO_fsetpos; _IO_fsetpos64; + + # f* + fgetpos; fgetpos64; fgetwc; fgetwc_unlocked; fgetws; fgetws_unlocked; + fputwc; fputwc_unlocked; fputws; fputws_unlocked; fsetpos; fsetpos64; + fwide; fwprintf; fwscanf; + + # g* + getwc; getwc_unlocked; getwchar; getwchar_unlocked; + + # p* + putwc; putwc_unlocked; putwchar; putwchar_unlocked; + + # s* + swprintf; swscanf; + + # u* + ungetwc; + + # v* + vfwprintf; vswprintf; vwprintf; vfwscanf; vswscanf; vwscanf; + + # w* + wprintf; wscanf; + } } diff --git a/libio/fileops.c b/libio/fileops.c index f5ec0e2b9e..8d480ad08b 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. Written by Per Bothner . @@ -136,9 +136,18 @@ _IO_new_file_close_it (fp) close_status = _IO_SYSCLOSE (fp); /* Free buffer. */ - _IO_setb (fp, NULL, NULL, 0); - _IO_setg (fp, NULL, NULL, NULL); - _IO_setp (fp, NULL, NULL); + if (fp->_mode <= 0) + { + _IO_setb (fp, NULL, NULL, 0); + _IO_setg (fp, NULL, NULL, NULL); + _IO_setp (fp, NULL, NULL); + } + else + { + _IO_wsetb (fp, NULL, NULL, 0); + _IO_wsetg (fp, NULL, NULL, NULL); + _IO_wsetp (fp, NULL, NULL); + } _IO_un_link (fp); fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS; @@ -277,14 +286,14 @@ _IO_new_file_setbuf (fp, p, len) char *p; _IO_ssize_t len; { - if (_IO_default_setbuf (fp, p, len) == NULL) - return NULL; + if (_IO_default_setbuf (fp, p, len) == NULL) + return NULL; - fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end - = fp->_IO_buf_base; - _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); + fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end + = fp->_IO_buf_base; + _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); - return fp; + return fp; } static int new_do_write __P ((_IO_FILE *, const char *, _IO_size_t)); @@ -319,7 +328,7 @@ new_do_write (fp, data, to_do) fp->_offset = _IO_pos_BAD; else if (fp->_IO_read_end != fp->_IO_write_base) { - _IO_fpos64_t new_pos + _IO_off64_t new_pos = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1); if (new_pos == _IO_pos_BAD) return 0; @@ -330,7 +339,8 @@ new_do_write (fp, data, to_do) fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, count) + 1; _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base; - fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) + fp->_IO_write_end = (fp->_mode < 0 + && (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) ? fp->_IO_buf_base : fp->_IO_buf_end); return count; } @@ -410,7 +420,7 @@ _IO_new_file_overflow (f, ch) return EOF; } /* If currently reading or no buffer allocated. */ - if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0) + if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == 0) { /* Allocate a buffer if needed. */ if (f->_IO_write_base == 0) @@ -433,18 +443,20 @@ _IO_new_file_overflow (f, ch) f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end; f->_flags |= _IO_CURRENTLY_PUTTING; - if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) + if (f->_mode < 0 && f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) f->_IO_write_end = f->_IO_write_ptr; } if (ch == EOF) - return _IO_do_flush (f); + return _IO_new_do_write(f, f->_IO_write_base, + f->_IO_write_ptr - f->_IO_write_base); if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */ if (_IO_do_flush (f) == EOF) return EOF; *f->_IO_write_ptr++ = ch; if ((f->_flags & _IO_UNBUFFERED) || ((f->_flags & _IO_LINE_BUF) && ch == '\n')) - if (_IO_do_flush (f) == EOF) + if (_IO_new_do_write(f, f->_IO_write_base, + f->_IO_write_ptr - f->_IO_write_base) == EOF) return EOF; return (unsigned char) ch; } @@ -483,14 +495,14 @@ _IO_new_file_sync (fp) return retval; } -_IO_fpos64_t +_IO_off64_t _IO_new_file_seekoff (fp, offset, dir, mode) _IO_FILE *fp; _IO_off64_t offset; int dir; int mode; { - _IO_fpos64_t result; + _IO_off64_t result; _IO_off64_t delta, new_offset; long count; /* POSIX.1 8.2.3.7 says that after a call the fflush() the file @@ -534,7 +546,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode) if (fp->_offset == _IO_pos_BAD) goto dumb; /* Make offset absolute, assuming current pointer is file_ptr(). */ - offset += _IO_pos_as_off (fp->_offset); + offset += fp->_offset; dir = _IO_seek_set; break; @@ -563,8 +575,8 @@ _IO_new_file_seekoff (fp, offset, dir, mode) && !_IO_in_backup (fp)) { /* Offset relative to start of main get area. */ - _IO_fpos64_t rel_offset = (offset - fp->_offset - + (fp->_IO_read_end - fp->_IO_read_base)); + _IO_off64_t rel_offset = (offset - fp->_offset + + (fp->_IO_read_end - fp->_IO_read_base)); if (rel_offset >= 0) { #if 0 @@ -678,7 +690,7 @@ _IO_file_read (fp, buf, size) return read (fp->_fileno, buf, size); } -_IO_fpos64_t +_IO_off64_t _IO_file_seek (fp, offset, dir) _IO_FILE *fp; _IO_off64_t offset; @@ -720,7 +732,7 @@ _IO_new_file_write (f, data, n) while (to_do > 0) { _IO_ssize_t count = write (f->_fileno, data, to_do); - if (count == EOF) + if (count < 0) { f->_flags |= _IO_ERR_SEEN; break; @@ -740,7 +752,7 @@ _IO_new_file_xsputn (f, data, n) const void *data; _IO_size_t n; { - register const char *s = (char *) data; + register const char *s = (const char *) data; _IO_size_t to_do = n; int must_flush = 0; _IO_size_t count; diff --git a/libio/fputwc.c b/libio/fputwc.c new file mode 100644 index 0000000000..cc8451a98f --- /dev/null +++ b/libio/fputwc.c @@ -0,0 +1,45 @@ +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +wint_t +fputwc (wc, fp) + wint_t wc; + _IO_FILE *fp; +{ + int result; + CHECK_FILE (fp, EOF); + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); + _IO_flockfile (fp); + if (_IO_fwide (fp, 1) < 0) + result = WEOF; + else + result = _IO_putwc_unlocked (wc, fp); + _IO_funlockfile (fp); + _IO_cleanup_region_end (0); + return result; +} diff --git a/libio/fputwc_u.c b/libio/fputwc_u.c new file mode 100644 index 0000000000..343e34d90e --- /dev/null +++ b/libio/fputwc_u.c @@ -0,0 +1,40 @@ +/* Copyright (C) 1993, 1996, 1997, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +#undef fputwc_unlocked + +wint_t +fputwc_unlocked (wc, fp) + wint_t wc; + _IO_FILE *fp; +{ + CHECK_FILE (fp, EOF); + if (_IO_fwide (fp, 1) < 0) + return WEOF; + return _IO_putwc_unlocked (wc, fp); +} diff --git a/libio/ftello.c b/libio/ftello.c index 2d8a8a7167..ed4ef8b603 100644 --- a/libio/ftello.c +++ b/libio/ftello.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -32,13 +32,19 @@ off_t ftello (fp) _IO_FILE *fp; { - _IO_pos_t pos; + _IO_off_t pos; CHECK_FILE (fp, -1L); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0); if (_IO_in_backup (fp)) - pos -= fp->_IO_save_end - fp->_IO_save_base; + { + if (fp->_mode <= 0) + pos -= fp->_IO_save_end - fp->_IO_save_base; + else + /* XXX Not done yet. */ + abort (); + } _IO_funlockfile (fp); _IO_cleanup_region_end (0); if (pos == _IO_pos_BAD) @@ -49,5 +55,5 @@ ftello (fp) #endif return -1L; } - return _IO_pos_as_off (pos); + return pos; } diff --git a/libio/ftello64.c b/libio/ftello64.c index 621454974e..7cb75626cf 100644 --- a/libio/ftello64.c +++ b/libio/ftello64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -33,13 +33,18 @@ ftello64 (fp) _IO_FILE *fp; { #ifdef _G_LSEEK64 - _IO_pos_t pos; + _IO_off64_t pos; CHECK_FILE (fp, -1L); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0); if (_IO_in_backup (fp)) - pos -= fp->_IO_save_end - fp->_IO_save_base; + { + if (fp->_mode <= 0) + pos -= fp->_IO_save_end - fp->_IO_save_base; + else + abort (); + } _IO_funlockfile (fp); _IO_cleanup_region_end (0); if (pos == _IO_pos_BAD) @@ -50,7 +55,7 @@ ftello64 (fp) #endif return -1L; } - return _IO_pos_as_off (pos); + return pos; #else __set_errno (ENOSYS); return -1; diff --git a/libio/fwprintf.c b/libio/fwprintf.c new file mode 100644 index 0000000000..c26a2ffcd3 --- /dev/null +++ b/libio/fwprintf.c @@ -0,0 +1,36 @@ +/* Copyright (C) 1991, 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 + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include + + +/* Write formatted output to STREAM from the format string FORMAT. */ +/* VARARGS2 */ +int +fwprintf (FILE *stream, const wchar_t *format, ...) +{ + va_list arg; + int done; + + va_start (arg, format); + done = vfwprintf (stream, format, arg); + va_end (arg); + + return done; +} diff --git a/libio/fwscanf.c b/libio/fwscanf.c new file mode 100644 index 0000000000..4510fc5b5f --- /dev/null +++ b/libio/fwscanf.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 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 + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include + +/* Read formatted input from STREAM according to the format string FORMAT. */ +/* VARARGS2 */ +int +fwscanf (FILE *stream, const wchar_t *format, ...) +{ + va_list arg; + int done; + + va_start (arg, format); + done = __vfwscanf (stream, format, arg); + va_end (arg); + + return done; +} diff --git a/libio/genops.c b/libio/genops.c index 81752e3ccc..a8f34463ad 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -80,9 +80,9 @@ _IO_link_in (fp) /* Return minimum _pos markers Assumes the current get area is the main get area. */ -static _IO_ssize_t _IO_least_marker __P ((_IO_FILE *fp, char *end_p)); +_IO_ssize_t _IO_least_marker __P ((_IO_FILE *fp, char *end_p)); -static _IO_ssize_t +_IO_ssize_t _IO_least_marker (fp, end_p) _IO_FILE *fp; char *end_p; @@ -282,6 +282,9 @@ int __underflow (fp) _IO_FILE *fp; { + if (_IO_fwide (fp, -1) != -1) + return EOF; + if (_IO_in_put_mode (fp)) if (_IO_switch_to_get_mode (fp) == EOF) return EOF; @@ -307,6 +310,9 @@ int __uflow (fp) _IO_FILE *fp; { + if (_IO_fwide (fp, -1) != -1) + return EOF; + if (_IO_in_put_mode (fp)) if (_IO_switch_to_get_mode (fp) == EOF) return EOF; @@ -508,13 +514,13 @@ _IO_default_setbuf (fp, p, len) return fp; } -_IO_fpos64_t +_IO_off64_t _IO_default_seekpos (fp, pos, mode) _IO_FILE *fp; - _IO_fpos64_t pos; + _IO_off64_t pos; int mode; { - return _IO_SEEKOFF (fp, _IO_pos_as_off (pos), 0, mode); + return _IO_SEEKOFF (fp, pos, 0, mode); } int @@ -532,6 +538,17 @@ void _IO_init (fp, flags) _IO_FILE *fp; int flags; +{ + _IO_no_init (fp, flags, -1, NULL, NULL); +} + +void +_IO_no_init (fp, flags, orientation, wd, jmp) + _IO_FILE *fp; + int flags; + int orientation; + struct _IO_wide_data *wd; + struct _IO_jump_t *jmp; { fp->_flags = _IO_MAGIC|flags; fp->_IO_buf_base = NULL; @@ -555,6 +572,24 @@ _IO_init (fp, flags) #ifdef _IO_MTSAFE_IO _IO_lock_init (*fp->_lock); #endif + fp->_mode = orientation; + if (orientation >= 0) + { + fp->_wide_data = wd; + fp->_wide_data->_IO_buf_base = NULL; + fp->_wide_data->_IO_buf_end = NULL; + fp->_wide_data->_IO_read_base = NULL; + fp->_wide_data->_IO_read_ptr = NULL; + fp->_wide_data->_IO_read_end = NULL; + fp->_wide_data->_IO_write_base = NULL; + fp->_wide_data->_IO_write_ptr = NULL; + fp->_wide_data->_IO_write_end = NULL; + fp->_wide_data->_IO_save_base = NULL; + fp->_wide_data->_IO_backup_base = NULL; + fp->_wide_data->_IO_save_end = NULL; + + fp->_wide_data->_wide_vtable = jmp; + } } int @@ -595,7 +630,7 @@ _IO_default_finish (fp, dummy) _IO_un_link (fp); } -_IO_fpos64_t +_IO_off64_t _IO_default_seekoff (fp, offset, dir, mode) _IO_FILE *fp; _IO_off64_t offset; @@ -706,7 +741,9 @@ _IO_flush_all () int result = 0; _IO_FILE *fp; for (fp = _IO_list_all; fp != NULL; fp = fp->_chain) - if (fp->_IO_write_ptr > fp->_IO_write_base + if (((fp->_mode < 0 && fp->_IO_write_ptr > fp->_IO_write_base) + || (fp->_mode > 0 && (fp->_wide_data->_IO_write_ptr + > fp->_wide_data->_IO_write_base))) && _IO_OVERFLOW (fp, EOF) == EOF) result = EOF; return result; @@ -941,7 +978,7 @@ _IO_default_pbackfail (fp, c) return (unsigned char) c; } -_IO_fpos64_t +_IO_off64_t _IO_default_seek (fp, offset, dir) _IO_FILE *fp; _IO_off64_t offset; diff --git a/libio/getwc.c b/libio/getwc.c new file mode 100644 index 0000000000..0829ea0248 --- /dev/null +++ b/libio/getwc.c @@ -0,0 +1,50 @@ +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +#undef _IO_getwc + +wint_t +_IO_getwc (fp) + FILE *fp; +{ + wint_t result; + CHECK_FILE (fp, WEOF); + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); + _IO_flockfile (fp); + result = _IO_getwc_unlocked (fp); + _IO_funlockfile (fp); + _IO_cleanup_region_end (0); + return result; +} + +#undef getwc + +#ifdef weak_alias +weak_alias (_IO_getwc, getwc) +weak_alias (_IO_getwc, fgetwc) +#endif diff --git a/libio/getwc_u.c b/libio/getwc_u.c new file mode 100644 index 0000000000..606b4d24cc --- /dev/null +++ b/libio/getwc_u.c @@ -0,0 +1,39 @@ +/* Copyright (C) 1993, 1995, 1996, 1997, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include "stdio.h" + +#undef getwc_unlocked + +wint_t +__getwc_unlocked (FILE *fp) +{ + CHECK_FILE (fp, EOF); + return _IO_getwc_unlocked (fp); +} + +weak_alias (__getwc_unlocked, getwc_unlocked) +weak_alias (__getwc_unlocked, fgetwc_unlocked) diff --git a/libio/getwchar.c b/libio/getwchar.c new file mode 100644 index 0000000000..6ef1f9b552 --- /dev/null +++ b/libio/getwchar.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +#undef getwchar + +wint_t +getwchar () +{ + wint_t result; + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, + _IO_stdin); + _IO_flockfile (_IO_stdin); + result = _IO_getwc_unlocked (_IO_stdin); + _IO_funlockfile (_IO_stdin); + _IO_cleanup_region_end (0); + return result; +} diff --git a/libio/getwchar_u.c b/libio/getwchar_u.c new file mode 100644 index 0000000000..18dc2ca158 --- /dev/null +++ b/libio/getwchar_u.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1993, 1996, 1997, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +#undef getwchar_unlocked + +wint_t +getwchar_unlocked () +{ + return _IO_getwc_unlocked (_IO_stdin); +} diff --git a/libio/iofdopen.c b/libio/iofdopen.c index 40419bd267..3bfa40c7c6 100644 --- a/libio/iofdopen.c +++ b/libio/iofdopen.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1994, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1994, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -50,6 +50,7 @@ _IO_new_fdopen (fd, mode) #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif + struct _IO_wide_data wd; } *new_f; int fd_flags; @@ -112,7 +113,7 @@ _IO_new_fdopen (fd, mode) #ifdef _IO_MTSAFE_IO new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.file, 0); + _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &_IO_wfile_jumps); _IO_JUMPS (&new_f->fp) = &_IO_file_jumps; _IO_file_init (&new_f->fp.file); #if !_IO_UNIFIED_JUMPTABLES diff --git a/libio/iofgetpos.c b/libio/iofgetpos.c index 27f018d07f..5b8f6a4129 100644 --- a/libio/iofgetpos.c +++ b/libio/iofgetpos.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -27,11 +27,11 @@ #include int -_IO_fgetpos (fp, posp) +_IO_new_fgetpos (fp, posp) _IO_FILE *fp; _IO_fpos_t *posp; { - _IO_fpos_t pos; + _IO_off_t pos; CHECK_FILE (fp, EOF); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); @@ -50,10 +50,16 @@ _IO_fgetpos (fp, posp) #endif return EOF; } - *posp = pos; + posp->__pos = pos; + if (fp->_mode > 0 + && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0) + /* This is a stateful encoding, safe the state. */ + posp->__state = fp->_wide_data->_IO_state; return 0; } #ifdef weak_alias -weak_alias (_IO_fgetpos, fgetpos) +strong_alias (_IO_new_fgetpos, __new_fgetpos) +default_symbol_version (_IO_new_fgetpos, _IO_fgetpos, GLIBC_2.2); +default_symbol_version (__new_fgetpos, fgetpos, GLIBC_2.2); #endif diff --git a/libio/iofgetpos64.c b/libio/iofgetpos64.c index a705e9e91a..cc39a3a9e1 100644 --- a/libio/iofgetpos64.c +++ b/libio/iofgetpos64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -27,12 +27,12 @@ #include int -_IO_fgetpos64 (fp, posp) +_IO_new_fgetpos64 (fp, posp) _IO_FILE *fp; _IO_fpos64_t *posp; { #ifdef _G_LSEEK64 - _IO_fpos64_t pos; + _IO_off64_t pos; CHECK_FILE (fp, EOF); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); @@ -45,13 +45,17 @@ _IO_fgetpos64 (fp, posp) { /* ANSI explicitly requires setting errno to a positive value on failure. */ -#ifdef EIO +# ifdef EIO if (errno == 0) __set_errno (EIO); -#endif +# endif return EOF; } - *posp = pos; + posp->__pos = pos; + if (fp->_mode > 0 + && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0) + /* This is a stateful encoding, safe the state. */ + posp->__state = fp->_wide_data->_IO_state; return 0; #else __set_errno (ENOSYS); @@ -60,5 +64,7 @@ _IO_fgetpos64 (fp, posp) } #ifdef weak_alias -weak_alias (_IO_fgetpos64, fgetpos64) +default_symbol_version (_IO_new_fgetpos64, _IO_fgetpos64, GLIBC_2.2); +strong_alias (_IO_new_fgetpos64, __new_fgetpos64) +default_symbol_version (__new_fgetpos64, fgetpos64, GLIBC_2.2); #endif diff --git a/libio/iofgetws.c b/libio/iofgetws.c new file mode 100644 index 0000000000..25ed836560 --- /dev/null +++ b/libio/iofgetws.c @@ -0,0 +1,63 @@ +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +wchar_t * +fgetws (buf, n, fp) + wchar_t *buf; + int n; + _IO_FILE *fp; +{ + _IO_size_t count; + wchar_t *result; + int old_error; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); + _IO_flockfile (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 + case. We return an error only when there is a new error. */ + old_error = fp->_IO_file_flags & _IO_ERR_SEEN; + fp->_IO_file_flags &= ~_IO_ERR_SEEN; + count = _IO_getwline (fp, buf, n - 1, L'\n', 1); + /* If we read in some bytes and errno is EAGAIN, that error will + be reported for next read. */ + if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN) + && errno != EAGAIN)) + result = NULL; + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + _IO_funlockfile (fp); + _IO_cleanup_region_end (0); + return result; +} diff --git a/libio/iofgetws_u.c b/libio/iofgetws_u.c new file mode 100644 index 0000000000..951ab80d9d --- /dev/null +++ b/libio/iofgetws_u.c @@ -0,0 +1,59 @@ +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +wchar_t * +fgetws_unlocked (buf, n, fp) + wchar_t *buf; + int n; + _IO_FILE *fp; +{ + _IO_size_t count; + wchar_t *result; + int old_error; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + /* 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. */ + old_error = fp->_IO_file_flags & _IO_ERR_SEEN; + fp->_IO_file_flags &= ~_IO_ERR_SEEN; + count = _IO_getwline (fp, buf, n - 1, L'\n', 1); + /* If we read in some bytes and errno is EAGAIN, that error will + be reported for next read. */ + if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN) + && errno != EAGAIN)) + result = NULL; + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + return result; +} diff --git a/libio/iofopen.c b/libio/iofopen.c index 92d58bb133..60b15a00f8 100644 --- a/libio/iofopen.c +++ b/libio/iofopen.c @@ -39,6 +39,7 @@ _IO_new_fopen (filename, mode) #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif + struct _IO_wide_data wd; } *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); if (new_f == NULL) @@ -46,7 +47,7 @@ _IO_new_fopen (filename, mode) #ifdef _IO_MTSAFE_IO new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.file, 0); + _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &_IO_wfile_jumps); _IO_JUMPS (&new_f->fp) = &_IO_file_jumps; _IO_file_init (&new_f->fp.file); #if !_IO_UNIFIED_JUMPTABLES diff --git a/libio/iofopen64.c b/libio/iofopen64.c index b071a0e160..0dc19b2e1b 100644 --- a/libio/iofopen64.c +++ b/libio/iofopen64.c @@ -40,6 +40,7 @@ _IO_fopen64 (filename, mode) #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif + struct _IO_wide_data wd; } *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); if (new_f == NULL) @@ -47,7 +48,7 @@ _IO_fopen64 (filename, mode) #ifdef _IO_MTSAFE_IO new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.file, 0); + _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &_IO_wfile_jumps); _IO_JUMPS (&new_f->fp) = &_IO_file_jumps; _IO_file_init (&new_f->fp.file); #if !_IO_UNIFIED_JUMPTABLES diff --git a/libio/iofopncook.c b/libio/iofopncook.c index f26744f39d..85ea35c22e 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -33,8 +33,8 @@ static _IO_ssize_t _IO_cookie_read __P ((register _IO_FILE* fp, void* buf, _IO_ssize_t size)); static _IO_ssize_t _IO_cookie_write __P ((register _IO_FILE* fp, const void* buf, _IO_ssize_t size)); -static _IO_fpos64_t _IO_cookie_seek __P ((_IO_FILE *fp, _IO_off64_t offset, - int dir)); +static _IO_off64_t _IO_cookie_seek __P ((_IO_FILE *fp, _IO_off64_t offset, + int dir)); static int _IO_cookie_close __P ((_IO_FILE* fp)); @@ -66,7 +66,7 @@ _IO_cookie_write (fp, buf, size) return cfile->__io_functions.write (cfile->__cookie, buf, size); } -static _IO_fpos64_t +static _IO_off64_t _IO_cookie_seek (fp, offset, dir) _IO_FILE *fp; _IO_off64_t offset; diff --git a/libio/iofputs.c b/libio/iofputs.c index 1805387303..ed41d5a49c 100644 --- a/libio/iofputs.c +++ b/libio/iofputs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -32,13 +32,12 @@ _IO_fputs (str, fp) _IO_FILE *fp; { _IO_size_t len = strlen (str); - int result; + int result = EOF; CHECK_FILE (fp, EOF); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); - if (_IO_sputn (fp, str, len) != len) - result = EOF; - else + if (_IO_fwide (fp, -1) == -1 + && _IO_sputn (fp, str, len) == len) result = 1; _IO_funlockfile (fp); _IO_cleanup_region_end (0); diff --git a/libio/iofputs_u.c b/libio/iofputs_u.c index dfd91aba7e..556522bad1 100644 --- a/libio/iofputs_u.c +++ b/libio/iofputs_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -33,11 +33,9 @@ fputs_unlocked (str, fp) _IO_FILE *fp; { _IO_size_t len = strlen (str); - int result; + int result = EOF; CHECK_FILE (fp, EOF); - if (_IO_sputn (fp, str, len) != len) - result = EOF; - else + if (_IO_fwide (fp, -1) == -1 && _IO_sputn (fp, str, len) == len) result = 1; return result; } diff --git a/libio/iofputws.c b/libio/iofputws.c new file mode 100644 index 0000000000..daad1b9836 --- /dev/null +++ b/libio/iofputws.c @@ -0,0 +1,45 @@ +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include + +int +fputws (str, fp) + const wchar_t *str; + _IO_FILE *fp; +{ + _IO_size_t len = wcslen (str); + int result = EOF; + CHECK_FILE (fp, EOF); + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); + _IO_flockfile (fp); + if (_IO_fwide (fp, 1) == 1 + && _IO_sputn (fp, (char *) str, len) == len) + result = 1; + _IO_funlockfile (fp); + _IO_cleanup_region_end (0); + return result; +} diff --git a/libio/iofputws_u.c b/libio/iofputws_u.c new file mode 100644 index 0000000000..a5749cdbec --- /dev/null +++ b/libio/iofputws_u.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include "libioP.h" +#include +#include + +int +fputws_unlocked (str, fp) + const wchar_t *str; + _IO_FILE *fp; +{ + _IO_size_t len = wcslen (str); + int result = EOF; + CHECK_FILE (fp, EOF); + if (_IO_fwide (fp, 1) == 1 + && _IO_sputn (fp, (char *) str, len) == len) + result = 1; + return result; +} diff --git a/libio/iofsetpos.c b/libio/iofsetpos.c index cbf77347e7..bd49c13a83 100644 --- a/libio/iofsetpos.c +++ b/libio/iofsetpos.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -27,7 +27,7 @@ #include int -_IO_fsetpos (fp, posp) +_IO_new_fsetpos (fp, posp) _IO_FILE *fp; const _IO_fpos_t *posp; { @@ -35,7 +35,7 @@ _IO_fsetpos (fp, posp) CHECK_FILE (fp, EOF); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); - if (_IO_seekpos (fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD) + if (_IO_seekpos (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD) { /* ANSI explicitly requires setting errno to a positive value on failure. */ @@ -46,12 +46,20 @@ _IO_fsetpos (fp, posp) result = EOF; } else - result = 0; + { + result = 0; + if (fp->_mode > 0 + && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0) + /* This is a stateful encoding, restore the state. */ + fp->_wide_data->_IO_state = posp->__state; + } _IO_funlockfile (fp); _IO_cleanup_region_end (0); return result; } #ifdef weak_alias -weak_alias (_IO_fsetpos, fsetpos) +default_symbol_version (_IO_new_fsetpos, _IO_fsetpos, GLIBC_2.2); +strong_alias (_IO_new_fsetpos, __new_fsetpos) +default_symbol_version (__new_fsetpos, fsetpos, GLIBC_2.2); #endif diff --git a/libio/iofsetpos64.c b/libio/iofsetpos64.c index 13ce0fb3cb..a70d5e215a 100644 --- a/libio/iofsetpos64.c +++ b/libio/iofsetpos64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -27,7 +27,7 @@ #include int -_IO_fsetpos64 (fp, posp) +_IO_new_fsetpos64 (fp, posp) _IO_FILE *fp; const _IO_fpos64_t *posp; { @@ -36,7 +36,7 @@ _IO_fsetpos64 (fp, posp) CHECK_FILE (fp, EOF); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); - if (_IO_seekpos (fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD) + if (_IO_seekpos (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD) { /* ANSI explicitly requires setting errno to a positive value on failure. */ @@ -47,7 +47,13 @@ _IO_fsetpos64 (fp, posp) result = EOF; } else - result = 0; + { + result = 0; + if (fp->_mode > 0 + && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0) + /* This is a stateful encoding, safe the state. */ + fp->_wide_data->_IO_state = posp->__state; + } _IO_funlockfile (fp); _IO_cleanup_region_end (0); return result; @@ -58,5 +64,7 @@ _IO_fsetpos64 (fp, posp) } #ifdef weak_alias -weak_alias (_IO_fsetpos64, fsetpos64) +default_symbol_version (_IO_new_fsetpos64, _IO_fsetpos64, GLIBC_2.2); +strong_alias (_IO_new_fsetpos64, __new_fsetpos64) +default_symbol_version (__new_fsetpos64, fsetpos64, GLIBC_2.2); #endif diff --git a/libio/ioftell.c b/libio/ioftell.c index 3de1ee9c02..1f25b66c2b 100644 --- a/libio/ioftell.c +++ b/libio/ioftell.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -31,13 +31,19 @@ long int _IO_ftell (fp) _IO_FILE *fp; { - _IO_pos_t pos; + _IO_off_t pos; CHECK_FILE (fp, -1L); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0); if (_IO_in_backup (fp)) - pos -= fp->_IO_save_end - fp->_IO_save_base; + { + if (fp->_mode < 0) + pos -= fp->_IO_save_end - fp->_IO_save_base; + else + /* XXX For now. */ + abort (); + } _IO_funlockfile (fp); _IO_cleanup_region_end (0); if (pos == _IO_pos_BAD) @@ -48,7 +54,7 @@ _IO_ftell (fp) #endif return -1L; } - return _IO_pos_as_off (pos); + return pos; } #ifdef weak_alias diff --git a/libio/iofwide.c b/libio/iofwide.c new file mode 100644 index 0000000000..853920a001 --- /dev/null +++ b/libio/iofwide.c @@ -0,0 +1,365 @@ +/* Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU IO Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, if you link this library with files + compiled with a GNU compiler to produce an executable, this does + not cause the resulting executable to be covered by the GNU General + Public License. This exception does not however invalidate any + other reasons why the executable file might be covered by the GNU + General Public License. */ + +#include +#ifdef _LIBC +# include +#endif +#include +#include + +#ifdef _LIBC +# include +# include +# include +#endif + + +/* Prototypes of libio's codecvt functions. */ +static enum __codecvt_result do_out (struct _IO_codecvt *codecvt, + __mbstate_t *statep, + const wchar_t *from_start, + const wchar_t *from_end, + const wchar_t **from_stop, char *to_start, + char *to_end, char **to_stop); +static enum __codecvt_result do_unshift (struct _IO_codecvt *codecvt, + __mbstate_t *statep, char *to_start, + char *to_end, char **to_stop); +static enum __codecvt_result do_in (struct _IO_codecvt *codecvt, + __mbstate_t *statep, + const char *from_start, + const char *from_end, + const char **from_stop, wchar_t *to_start, + wchar_t *to_end, wchar_t **to_stop); +static int do_encoding (struct _IO_codecvt *codecvt); +static int do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep, + const char *from_start, + const char *from_end, _IO_size_t max); +static int do_max_length (struct _IO_codecvt *codecvt); +static int do_always_noconv (struct _IO_codecvt *codecvt); + + +/* The functions used in `codecvt' for libio are always the same. */ +static struct _IO_codecvt libio_codecvt = +{ + .__codecvt_destr = NULL, /* Destructor, never used. */ + .__codecvt_do_out = do_out, + .__codecvt_do_unshift = do_unshift, + .__codecvt_do_in = do_in, + .__codecvt_do_encoding = do_encoding, + .__codecvt_do_always_noconv = do_always_noconv, + .__codecvt_do_length = do_length, + .__codecvt_do_max_length = do_max_length +}; + + +/* Return orientation of stream. If mode is nonzero try to change + the orientation first. */ +#undef _IO_fwide +int +_IO_fwide (fp, mode) + _IO_FILE *fp; + int mode; +{ + /* Normalize the value. */ + mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1); + + if (mode == 0 || fp->_mode != 0) + /* The caller simply wants to know about the current orientation + or the orientation already has been determined. */ + return fp->_mode; + + _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); + _IO_flockfile (fp); + + /* Set the orientation appropriately. */ + if (mode > 0) + { + fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end; + fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base; + + /* 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)); + + /* Get the character conversion functions based on the currently + selected locale for LC_CTYPE. */ +#ifdef _LIBC + { + struct gconv_fcts fcts; + struct _IO_codecvt *cc = &fp->_wide_data->_codecvt; + + __wcsmbs_clone_conv (&fcts); + + /* The functions are always the same. */ + *cc = libio_codecvt; + + cc->__cd_in.__cd.__nsteps = 1; /* Only one step allowed. */ + cc->__cd_in.__cd.__steps = fcts.towc; + + cc->__cd_in.__cd.__data[0].__invocation_counter = 0; + cc->__cd_in.__cd.__data[0].__internal_use = 1; + cc->__cd_in.__cd.__data[0].__is_last = 1; + cc->__cd_in.__cd.__data[0].__statep = &fp->_wide_data->_IO_state; + + cc->__cd_out.__cd.__nsteps = 1; /* Only one step allowed. */ + cc->__cd_out.__cd.__steps = fcts.tomb; + + cc->__cd_out.__cd.__data[0].__invocation_counter = 0; + cc->__cd_out.__cd.__data[0].__internal_use = 1; + cc->__cd_out.__cd.__data[0].__is_last = 1; + cc->__cd_out.__cd.__data[0].__statep = &fp->_wide_data->_IO_state; + } +#else +# error "somehow determine this from LC_CTYPE" +#endif + + /* From n