diff options
author | H.J. Lu <hjl@gnu.org> | 1998-02-17 20:50:52 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 1998-02-17 13:50:52 -0700 |
commit | 52af7fac0490633a3a14327367f6507c460bf069 (patch) | |
tree | caabd96f62bd0be119a3f52e7edeb0d1f38cd0aa | |
parent | 1822f8a606439eaece94b874d37283483e9d9213 (diff) | |
download | gcc-52af7fac0490633a3a14327367f6507c460bf069.tar.gz |
[multiple changes]
Sat Dec 6 14:58:17 1997 H.J. Lu (hjl@gnu.org)
* filebuf.cc (filebuf::open): Call _IO_file_open if
_G_HAVE_IO_FILE_OPEN is 1.
* libio.h (_IO_fpos64_t, _IO_off64_t): Defined if
_G_IO_IO_FILE_VERSION == 0x20001.
* libioP.h (_IO_file_open): New declaration.
* libio.h (_IO_FILE, _IO_stdin_, _IO_stdout_, _IO_stderr_,
_IO_seekoff, _IO_seekpos): Add support for libio in egcs 2.1.
* libioP.h (_IO_seekoff_t, _IO_seekpos_t, _IO_seek_t,
_IO_seekoff, _IO_seekpos, _IO_default_seekoff,
_IO_default_seekpos, _IO_default_seek, _IO_file_seekoff,
_IO_file_seek, _IO_str_seekoff, _IO_pos_BAD, _IO_pos_as_off,
_IO_pos_0): Ditto.
* streambuf.h (streamoff, streampos): Ditto.
Mon Nov 17 07:36:58 1997 H.J. Lu (hjl@gnu.org)
* gen-params (__extension__): Use only if gcc version >= 2.8.
From-SVN: r18040
-rw-r--r-- | libio/ChangeLog | 21 | ||||
-rw-r--r-- | libio/filebuf.cc | 209 | ||||
-rwxr-xr-x | libio/gen-params | 2 | ||||
-rw-r--r-- | libio/libio.h | 23 | ||||
-rw-r--r-- | libio/libioP.h | 60 | ||||
-rw-r--r-- | libio/streambuf.h | 5 |
6 files changed, 111 insertions, 209 deletions
diff --git a/libio/ChangeLog b/libio/ChangeLog index 474bdf7548d..e5da502862a 100644 --- a/libio/ChangeLog +++ b/libio/ChangeLog @@ -1,3 +1,24 @@ +Tue Feb 17 21:52:44 1998 H.J. Lu (hjl@gnu.org) + + * filebuf.cc (filebuf::open): Call _IO_file_open if + _G_HAVE_IO_FILE_OPEN is 1. + + * libio.h (_IO_fpos64_t, _IO_off64_t): Defined if + _G_IO_IO_FILE_VERSION == 0x20001. + + * libioP.h (_IO_file_open): New declaration. + + * libio.h (_IO_FILE, _IO_stdin_, _IO_stdout_, _IO_stderr_, + _IO_seekoff, _IO_seekpos): Add support for libio in egcs 2.1. + * libioP.h (_IO_seekoff_t, _IO_seekpos_t, _IO_seek_t, + _IO_seekoff, _IO_seekpos, _IO_default_seekoff, + _IO_default_seekpos, _IO_default_seek, _IO_file_seekoff, + _IO_file_seek, _IO_str_seekoff, _IO_pos_BAD, _IO_pos_as_off, + _IO_pos_0): Ditto. + * streambuf.h (streamoff, streampos): Ditto. + + * gen-params (__extension__): Use only if gcc version >= 2.8. + Sun Feb 15 21:11:25 1998 Krister Walfridsson (cato@df.lth.se) * fileops.c: #include <unistd.h>. diff --git a/libio/filebuf.cc b/libio/filebuf.cc index 1e2682fbce9..d4af4985d50 100644 --- a/libio/filebuf.cc +++ b/libio/filebuf.cc @@ -1,206 +1,5 @@ -/* This is part of libio/iostream, providing -*- C++ -*- input/output. -Copyright (C) 1993, 1995 Free Software Foundation - -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. - -Written by Per Bothner (bothner@cygnus.com). */ - -#include "iostreamP.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include "builtinbuf.h" - -void filebuf::init() -{ - _IO_file_init(this); -} - -filebuf::filebuf() -{ - _IO_file_init(this); -} - -#if !_IO_UNIFIED_JUMPTABLES -/* This is like "new filebuf()", but it uses the _IO_file_jump jumptable, - for eficiency. */ - -filebuf* filebuf::__new() -{ - filebuf *fb = new filebuf; - _IO_JUMPS(fb) = &_IO_file_jumps; - fb->_vtable() = builtinbuf_vtable; - return fb; -} +#if _G_HAVE_IO_FILE_OPEN + return (filebuf*)_IO_file_open (this, filename, posix_mode, prot, + read_write, 0); +#else #endif - -filebuf::filebuf(int fd) -{ - _IO_file_init(this); - _IO_file_attach(this, fd); -} - -filebuf::filebuf(int fd, char* p, int len) -{ - _IO_file_init(this); - _IO_file_attach(this, fd); - setbuf(p, len); -} - -filebuf::~filebuf() -{ - if (_IO_file_is_open(this)) - { - _IO_do_flush (this); - if (!(xflags() & _IO_DELETE_DONT_CLOSE)) - _IO_SYSCLOSE (this); - } -} - -filebuf* filebuf::open(const char *filename, ios::openmode mode, int prot) -{ - if (_IO_file_is_open (this)) - return NULL; - int posix_mode; - int read_write; - if (mode & ios::app) - mode |= ios::out; - if ((mode & (ios::in|ios::out)) == (ios::in|ios::out)) { - posix_mode = O_RDWR; - read_write = 0; - } - else if (mode & ios::out) - posix_mode = O_WRONLY, read_write = _IO_NO_READS; - else if (mode & (int)ios::in) - posix_mode = O_RDONLY, read_write = _IO_NO_WRITES; - else - posix_mode = 0, read_write = _IO_NO_READS+_IO_NO_WRITES; - if (mode & ios::binary) - { - mode &= ~ios::binary; -#ifdef O_BINARY - /* This is a (mis-)feature of DOS/Windows C libraries. */ - posix_mode |= O_BINARY; -#endif - } - if ((mode & (int)ios::trunc) || mode == (int)ios::out) - posix_mode |= O_TRUNC; - if (mode & ios::app) - posix_mode |= O_APPEND, read_write |= _IO_IS_APPENDING; - if (!(mode & (int)ios::nocreate) && mode != ios::in) - posix_mode |= O_CREAT; - if (mode & (int)ios::noreplace) - posix_mode |= O_EXCL; - int fd = ::open(filename, posix_mode, prot); - if (fd < 0) - return NULL; - _fileno = fd; - xsetflags(read_write, _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); - if (mode & (ios::ate|ios::app)) { - if (pubseekoff(0, ios::end) == EOF) - return NULL; - } - _IO_link_in(this); - return this; -} - -filebuf* filebuf::open(const char *filename, const char *mode) -{ - return (filebuf*)_IO_file_fopen(this, filename, mode); -} - -filebuf* filebuf::attach(int fd) -{ - return (filebuf*)_IO_file_attach(this, fd); -} - -streambuf* filebuf::setbuf(char* p, int len) -{ - return (streambuf*)_IO_file_setbuf (this, p, len); -} - -int filebuf::doallocate() { return _IO_file_doallocate(this); } - -int filebuf::overflow(int c) -{ - return _IO_file_overflow(this, c); -} - -int filebuf::underflow() -{ - return _IO_file_underflow(this); -} - -int filebuf::sync() -{ - return _IO_file_sync(this); -} - -streampos filebuf::seekoff(streamoff offset, _seek_dir dir, int mode) -{ - return _IO_file_seekoff (this, offset, dir, mode); -} - -filebuf* filebuf::close() -{ - return (_IO_file_close_it(this) ? (filebuf*)NULL : this); -} - -streamsize filebuf::sys_read(char* buf, streamsize size) -{ - return _IO_file_read(this, buf, size); -} - -streampos filebuf::sys_seek(streamoff offset, _seek_dir dir) -{ - return _IO_file_seek(this, offset, dir); -} - -streamsize filebuf::sys_write(const char *buf, streamsize n) -{ - return _IO_file_write (this, buf, n); -} - -int filebuf::sys_stat(void* st) -{ - return _IO_file_stat (this, st); -} - -int filebuf::sys_close() -{ - return _IO_file_close (this); -} - -streamsize filebuf::xsputn(const char *s, streamsize n) -{ - return _IO_file_xsputn(this, s, n); -} - -streamsize filebuf::xsgetn(char *s, streamsize n) -{ - // FIXME: OPTIMIZE THIS (specifically, when unbuffered()). - return streambuf::xsgetn(s, n); -} - -// Non-ANSI AT&T-ism: Default open protection. -const int filebuf::openprot = 0644; diff --git a/libio/gen-params b/libio/gen-params index f23dfbf4532..bd652b68da5 100755 --- a/libio/gen-params +++ b/libio/gen-params @@ -382,8 +382,10 @@ typedef int ${macro_prefix}int32_t __attribute__((__mode__(__SI__))); typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__))); typedef int ${macro_prefix}int64_t __attribute__((__mode__(__DI__))); typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__))); +#if __GNUC__ > 2 || __GNUC_MINOR__ >= 8 __extension__ typedef long long ${macro_prefix}llong; __extension__ typedef unsigned long long ${macro_prefix}ullong; +#endif #else typedef $int16_t ${macro_prefix}int16_t; typedef $uint16_t ${macro_prefix}uint16_t; diff --git a/libio/libio.h b/libio/libio.h index b7f8af7c791..e652b46ca16 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -39,6 +39,10 @@ #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE #define _IO_BUFSIZ _G_BUFSIZ #define _IO_va_list _G_va_list +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +#define _IO_fpos64_t _G_fpos64_t +#define _IO_off64_t _G_off64_t +#endif #ifdef _G_NEED_STDARG_H /* This define avoids name pollution if we're using GNU stdarg.h */ @@ -220,7 +224,11 @@ struct _IO_FILE { int _fileno; int _blksize; +#ifdef _G_IO_IO_FILE_VERSION + _IO_off_t _old_offset; +#else _IO_off_t _offset; +#endif #define __HAVE_COLUMN /* temporary */ /* 1+column number of pbase(); 0 is unknown. */ @@ -233,12 +241,22 @@ struct _IO_FILE { #ifdef _IO_LOCK_T _IO_LOCK_T _lock; #endif +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 + _IO_off64_t _offset; + int _unused2[16]; /* Make sure we don't get into trouble again. */ +#endif }; #ifndef __cplusplus typedef struct _IO_FILE _IO_FILE; #endif +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +#define _IO_stdin_ _IO_2_1_stdin_ +#define _IO_stdout_ _IO_2_1_stdout_ +#define _IO_stderr_ _IO_2_1_stderr_ +#endif + struct _IO_FILE_plus; extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_; #define _IO_stdin ((_IO_FILE*)(&_IO_stdin_)) @@ -321,8 +339,13 @@ extern int _IO_vfprintf __P ((_IO_FILE *, const char *, _IO_va_list)); extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t)); extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t)); +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); +extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int)); +#else extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int)); +#endif extern void _IO_free_backup_area __P ((_IO_FILE *)); diff --git a/libio/libioP.h b/libio/libioP.h index bbe92a4cf16..7a5ca9044e8 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -138,8 +138,13 @@ typedef _IO_size_t (*_IO_xsgetn_t) __P ((_IO_FILE *FP, void *DATA, (MODE==1), or the end of the file (MODE==2). It matches the streambuf::seekoff virtual function. It is also used for the ANSI fseek function. */ +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +typedef _IO_fpos64_t (*_IO_seekoff_t) __P ((_IO_FILE *FP, _IO_off64_t OFF, + int DIR, int MODE)); +#else typedef _IO_fpos_t (*_IO_seekoff_t) __P ((_IO_FILE *FP, _IO_off_t OFF, int DIR, int MODE)); +#endif #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE) /* The 'seekpos' hook also moves the stream position, @@ -147,7 +152,11 @@ typedef _IO_fpos_t (*_IO_seekoff_t) __P ((_IO_FILE *FP, _IO_off_t OFF, It matches the streambuf::seekpos virtual function. It is also used for the ANSI fgetpos and fsetpos functions. */ /* The _IO_seek_cur and _IO_seek_end options are not allowed. */ +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +typedef _IO_fpos64_t (*_IO_seekpos_t) __P ((_IO_FILE *, _IO_fpos64_t, int)); +#else typedef _IO_fpos_t (*_IO_seekpos_t) __P ((_IO_FILE *, _IO_fpos_t, int)); +#endif #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS) /* The 'setbuf' hook gives a buffer to the file. @@ -196,7 +205,11 @@ typedef _IO_ssize_t (*_IO_write_t) __P ((_IO_FILE *,const void *,_IO_ssize_t)); It generalizes the Unix lseek(2) function. It matches the streambuf::sys_seek virtual function, which is specific to this implementation. */ +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +typedef _IO_fpos64_t (*_IO_seek_t) __P ((_IO_FILE *, _IO_off64_t, int)); +#else typedef _IO_fpos_t (*_IO_seek_t) __P ((_IO_FILE *, _IO_off_t, int)); +#endif #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE) /* The 'sysclose' hook is used to finalize (close, finish up) an @@ -260,8 +273,13 @@ struct _IO_FILE_plus /* Generic functions */ +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); +extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int)); +#else extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int)); +#endif extern void _IO_switch_to_main_get_area __P ((_IO_FILE *)); extern void _IO_switch_to_backup_area __P ((_IO_FILE *)); @@ -297,13 +315,24 @@ extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t)); extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *, _IO_size_t)); extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t)); +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_default_seekoff __P ((_IO_FILE *, + _IO_off64_t, int, int)); +extern _IO_fpos64_t _IO_default_seekpos __P ((_IO_FILE *, + _IO_fpos64_t, int)); +#else extern _IO_fpos_t _IO_default_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); extern _IO_fpos_t _IO_default_seekpos __P ((_IO_FILE *, _IO_fpos_t, int)); +#endif extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *, _IO_ssize_t)); extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t)); extern int _IO_default_stat __P ((_IO_FILE *, void *)); +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int)); +#else extern _IO_fpos_t _IO_default_seek __P ((_IO_FILE *, _IO_off_t, int)); +#endif extern int _IO_default_sync __P ((_IO_FILE *)); #define _IO_default_close ((_IO_close_t) _IO_default_sync) @@ -335,7 +364,13 @@ extern void _IO_flush_all_linebuffered __P ((void)); extern int _IO_file_doallocate __P ((_IO_FILE *)); extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t)); +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); +extern _IO_fpos64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int)); +#else extern _IO_fpos_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); +extern _IO_fpos_t _IO_file_seek __P ((_IO_FILE *, _IO_off_t, int)); +#endif extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t)); extern int _IO_file_stat __P ((_IO_FILE *, void *)); extern int _IO_file_close __P ((_IO_FILE *)); @@ -344,13 +379,14 @@ extern int _IO_file_overflow __P ((_IO_FILE *, int)); #define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0) extern void _IO_file_init __P ((_IO_FILE *)); extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int)); +extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int, + int, int)); extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *)); extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *, _IO_ssize_t)); extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t)); extern int _IO_file_sync __P ((_IO_FILE *)); extern int _IO_file_close_it __P ((_IO_FILE *)); -extern _IO_fpos_t _IO_file_seek __P ((_IO_FILE *, _IO_off_t, int)); extern void _IO_file_finish __P ((_IO_FILE *, int)); /* Jumptable functions for proc_files. */ @@ -361,7 +397,11 @@ extern int _IO_proc_close __P ((_IO_FILE *)); extern int _IO_str_underflow __P ((_IO_FILE *)); extern int _IO_str_overflow __P ((_IO_FILE *, int)); extern int _IO_str_pbackfail __P ((_IO_FILE *, int)); +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +extern _IO_fpos64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); +#else extern _IO_fpos_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); +#endif extern void _IO_str_finish __P ((_IO_FILE *, int)); /* Other strfile functions */ @@ -475,11 +515,19 @@ extern int _IO_vscanf __P ((const char *, _IO_va_list)); /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */ #ifndef _IO_pos_BAD -# define _IO_pos_BAD ((_IO_fpos_t) -1) +# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +# define _IO_pos_BAD ((_IO_fpos64_t) -1) +# else +# define _IO_pos_BAD ((_IO_fpos_t) -1) +# endif #endif /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */ #ifndef _IO_pos_as_off -# define _IO_pos_as_off(__pos) ((_IO_off_t) (__pos)) +# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +# define _IO_pos_as_off(__pos) ((_IO_off64_t) (__pos)) +# else +# define _IO_pos_as_off(__pos) ((_IO_off_t) (__pos)) +# endif #endif /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */ #ifndef _IO_pos_adjust @@ -487,7 +535,11 @@ extern int _IO_vscanf __P ((const char *, _IO_va_list)); #endif /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */ #ifndef _IO_pos_0 -# define _IO_pos_0 ((_IO_fpos_t) 0) +# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +# define _IO_pos_0 ((_IO_fpos64_t) 0) +# else +# define _IO_pos_0 ((_IO_fpos_t) 0) +# endif #endif #ifdef __cplusplus diff --git a/libio/streambuf.h b/libio/streambuf.h index dfee0984a64..9ef47243be6 100644 --- a/libio/streambuf.h +++ b/libio/streambuf.h @@ -66,8 +66,13 @@ class ostream; class streambuf; #undef open #undef close +#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 +typedef _IO_off64_t streamoff; +typedef _IO_fpos64_t streampos; +#else typedef _IO_off_t streamoff; typedef _IO_fpos_t streampos; +#endif typedef _IO_ssize_t streamsize; typedef unsigned long __fmtflags; |