diff options
author | Brendan Kehoe <brendan@gcc.gnu.org> | 1997-09-06 03:44:38 -0400 |
---|---|---|
committer | Brendan Kehoe <brendan@gcc.gnu.org> | 1997-09-06 03:44:38 -0400 |
commit | dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56 (patch) | |
tree | 82e1a9aef1a37d3e21b8f1d0fe3a9435ad5a2f53 /libio/strops.c | |
parent | 1496c1bb0be5c2981f056fa169cf1c199f50a38a (diff) | |
download | gcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.zip gcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.tar.gz gcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.tar.bz2 |
Insert libio rewrite and its various changes from devo.
From-SVN: r15129
Diffstat (limited to 'libio/strops.c')
-rw-r--r-- | libio/strops.c | 133 |
1 files changed, 73 insertions, 60 deletions
diff --git a/libio/strops.c b/libio/strops.c index 3162cd9..a9f812e 100644 --- a/libio/strops.c +++ b/libio/strops.c @@ -1,26 +1,27 @@ -/* -Copyright (C) 1993 Free Software Foundation +/* Copyright (C) 1993, 1997 Free Software Foundation, Inc. + This file is part of the GNU IO Library. -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 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. + 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. + 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. */ + 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 "strfile.h" #include "libioP.h" @@ -28,7 +29,7 @@ the executable file might be covered by the GNU General Public License. */ #if 0 /* The following definitions are for exposition only. - They map the terminlogy used in the ANSI/ISO C++ draft standard + 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 @@ -59,16 +60,19 @@ the executable file might be covered by the GNU General Public License. */ #endif void -DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), - _IO_FILE *fp AND char *ptr AND int size AND char *pstart) +_IO_str_init_static (fp, ptr, size, pstart) + _IO_FILE *fp; + char *ptr; + int size; + char *pstart; { if (size == 0) - size = strlen(ptr); + size = strlen (ptr); else if (size < 0) { /* If size is negative 'the characters are assumed to continue indefinitely.' This is kind of messy ... */ - _G_int32_t s; + int s; size = 512; /* Try increasing powers of 2, as long as we don't wrap around. */ for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; ) @@ -80,7 +84,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), size += s; } } - _IO_setb(fp, ptr, ptr+size, 0); + _IO_setb (fp, ptr, ptr + size, 0); fp->_IO_write_base = ptr; fp->_IO_read_base = ptr; @@ -88,7 +92,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), if (pstart) { fp->_IO_write_ptr = pstart; - fp->_IO_write_end = ptr+size; + fp->_IO_write_end = ptr + size; fp->_IO_read_end = pstart; } else @@ -98,20 +102,23 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), fp->_IO_read_end = ptr+size; } /* 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; } void -DEFUN(_IO_str_init_readonly, (fp, ptr, size), - _IO_FILE *fp AND const char *ptr AND int size) +_IO_str_init_readonly (fp, ptr, size) + _IO_FILE *fp; + const char *ptr; + int size; { - _IO_str_init_static (fp, (char*)ptr, size, NULL); + _IO_str_init_static (fp, (char *) ptr, size, NULL); fp->_IO_file_flags |= _IO_NO_WRITES; } int -DEFUN(_IO_str_overflow, (fp, c), - register _IO_FILE* fp AND int c) +_IO_str_overflow (fp, c) + _IO_FILE *fp; + int c; { int flush_only = c == EOF; _IO_size_t pos; @@ -124,7 +131,7 @@ DEFUN(_IO_str_overflow, (fp, c), fp->_IO_read_ptr = fp->_IO_read_end; } pos = fp->_IO_write_ptr - fp->_IO_write_base; - if (pos >= _IO_blen(fp) + flush_only) + if (pos >= (_IO_size_t) (_IO_blen (fp) + flush_only)) { if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */ return EOF; @@ -132,9 +139,9 @@ DEFUN(_IO_str_overflow, (fp, c), { char *new_buf; char *old_buf = fp->_IO_buf_base; - _IO_size_t new_size = 2 * _IO_blen(fp) + 100; + _IO_size_t new_size = 2 * _IO_blen (fp) + 100; new_buf - = (char*)(*((_IO_strfile*)fp)->_s._allocate_buffer)(new_size); + = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size); if (new_buf == NULL) { /* __ferror(fp) = 1; */ @@ -142,16 +149,16 @@ DEFUN(_IO_str_overflow, (fp, c), } if (fp->_IO_buf_base) { - memcpy(new_buf, old_buf, _IO_blen(fp)); - (*((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base); + memcpy (new_buf, old_buf, _IO_blen (fp)); + (*((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base); /* Make sure _IO_setb won't try to delete _IO_buf_base. */ fp->_IO_buf_base = NULL; } #if 0 if (lenp == &LEN(fp)) /* use '\0'-filling */ - memset(new_buf + pos, 0, blen() - pos); + memset (new_buf + pos, 0, blen() - pos); #endif - _IO_setb(fp, new_buf, new_buf + new_size, 1); + _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); fp->_IO_read_end = new_buf + (fp->_IO_read_end - old_buf); @@ -170,8 +177,8 @@ DEFUN(_IO_str_overflow, (fp, c), } int -DEFUN(_IO_str_underflow, (fp), - register _IO_FILE* fp) +_IO_str_underflow (fp) + _IO_FILE *fp; { if (fp->_IO_write_ptr > fp->_IO_read_end) fp->_IO_read_end = fp->_IO_write_ptr; @@ -190,19 +197,22 @@ DEFUN(_IO_str_underflow, (fp), /* The size of the valid part of the buffer. */ _IO_ssize_t -DEFUN(_IO_str_count, (fp), - register _IO_FILE *fp) +_IO_str_count (fp) + _IO_FILE *fp; { - return (fp->_IO_write_ptr > fp->_IO_read_end ? fp->_IO_write_ptr - : fp->_IO_read_end) - - fp->_IO_read_base; -} + return ((fp->_IO_write_ptr > fp->_IO_read_end + ? fp->_IO_write_ptr : fp->_IO_read_end) + - fp->_IO_read_base); +} _IO_pos_t -DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), - register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode) +_IO_str_seekoff (fp, offset, dir, mode) + _IO_FILE *fp; + _IO_off_t offset; + int dir; + int mode; { - _IO_ssize_t cur_size = _IO_str_count(fp); + _IO_ssize_t cur_size = _IO_str_count (fp); _IO_pos_t new_pos = EOF; /* Move the get pointer, if requested. */ @@ -219,7 +229,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), default: /* case _IO_seek_set: */ break; } - if (offset < 0 || (_IO_size_t)offset > cur_size) + 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; @@ -240,7 +250,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), default: /* case _IO_seek_set: */ break; } - if (offset < 0 || (_IO_size_t)offset > cur_size) + if (offset < 0 || (_IO_ssize_t) offset > cur_size) return EOF; fp->_IO_write_ptr = fp->_IO_write_base + offset; new_pos = offset; @@ -249,26 +259,29 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), } int -DEFUN(_IO_str_pbackfail, (fp, c), - register _IO_FILE *fp AND int c) +_IO_str_pbackfail (fp, c) + _IO_FILE *fp; + int c; { if ((fp->_flags & _IO_NO_WRITES) && c != EOF) return EOF; - return _IO_default_pbackfail(fp, c); + return _IO_default_pbackfail (fp, c); } void -DEFUN (_IO_str_finish, (fp), - register _IO_FILE* fp) +_IO_str_finish (fp, dummy) + _IO_FILE *fp; + int dummy; { if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF)) - (((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base); + (((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base); fp->_IO_buf_base = NULL; - _IO_default_finish(fp); + _IO_default_finish (fp, 0); } -struct _IO_jump_t _IO_str_jumps = { +struct _IO_jump_t _IO_str_jumps = +{ JUMP_INIT_DUMMY, JUMP_INIT(finish, _IO_str_finish), JUMP_INIT(overflow, _IO_str_overflow), |