Daily bump.
[official-gcc.git] / libio / strstream.cc
bloba32e811c9d94b0df17e539db2fb4c14929dc9b9c
1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
25 /* Written by Per Bothner (bothner@cygnus.com). */
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30 #include "iostreamP.h"
31 #include "strstream.h"
32 #include <string.h>
34 static void* default_alloc(_IO_size_t size)
36 return (void*)new char[size];
39 static void default_free(void* ptr)
41 delete [] (char*)ptr;
44 istrstream::istrstream(const char *cp, int n)
46 __my_sb.init_readonly (cp, n);
49 strstreambase::strstreambase(char *cp, int n, int mode)
50 : __my_sb (cp, n,
51 (mode == ios::app || mode == ios::ate) ? cp + strlen(cp) : cp)
53 init (&__my_sb);
56 char *strstreambuf::str()
58 freeze(1);
59 return base();
62 _IO_ssize_t strstreambuf::pcount () { return _IO_write_ptr - _IO_write_base; }
64 int strstreambuf::overflow(int c /* = EOF */)
66 return _IO_str_overflow (this, c);
69 int strstreambuf::underflow()
71 return _IO_str_underflow(this);
75 void strstreambuf::init_dynamic(_IO_alloc_type alloc, _IO_free_type free,
76 int initial_size)
79 _s._allocate_buffer = alloc ? alloc : default_alloc;
80 _s._free_buffer = free ? free : default_free;
81 if (initial_size > 0)
83 char * buf = (char*)(*_s._allocate_buffer)(initial_size);
84 setb(buf, buf + initial_size, 1);
85 setp(buf, buf + initial_size);
86 setg(buf, buf, buf);
90 void strstreambuf::init_static(char *ptr, int size, char *pstart)
92 _IO_str_init_static (this, ptr, size, pstart);
95 void strstreambuf::init_readonly (const char *ptr, int size)
97 _IO_str_init_readonly (this, ptr, size);
100 strstreambuf::~strstreambuf()
102 if (_IO_buf_base && !(_flags & _IO_USER_BUF))
103 (_s._free_buffer)(_IO_buf_base);
104 _IO_buf_base = NULL;
107 streampos strstreambuf::seekoff(streamoff off, _seek_dir dir,
108 int mode /*=ios::in|ios::out*/)
110 return _IO_str_seekoff (this, off, dir, mode);
113 int strstreambuf::pbackfail(int c)
115 return _IO_str_pbackfail (this, c);