1*58b9f456SAndroid Build Coastguard Worker //===------------------------ strstream.cpp -------------------------------===//
2*58b9f456SAndroid Build Coastguard Worker //
3*58b9f456SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*58b9f456SAndroid Build Coastguard Worker //
5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*58b9f456SAndroid Build Coastguard Worker //
8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*58b9f456SAndroid Build Coastguard Worker
10*58b9f456SAndroid Build Coastguard Worker #include "strstream"
11*58b9f456SAndroid Build Coastguard Worker #include "algorithm"
12*58b9f456SAndroid Build Coastguard Worker #include "climits"
13*58b9f456SAndroid Build Coastguard Worker #include "cstring"
14*58b9f456SAndroid Build Coastguard Worker #include "cstdlib"
15*58b9f456SAndroid Build Coastguard Worker #include "__debug"
16*58b9f456SAndroid Build Coastguard Worker #include "__undef_macros"
17*58b9f456SAndroid Build Coastguard Worker
18*58b9f456SAndroid Build Coastguard Worker _LIBCPP_BEGIN_NAMESPACE_STD
19*58b9f456SAndroid Build Coastguard Worker
strstreambuf(streamsize __alsize)20*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(streamsize __alsize)
21*58b9f456SAndroid Build Coastguard Worker : __strmode_(__dynamic),
22*58b9f456SAndroid Build Coastguard Worker __alsize_(__alsize),
23*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
24*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
25*58b9f456SAndroid Build Coastguard Worker {
26*58b9f456SAndroid Build Coastguard Worker }
27*58b9f456SAndroid Build Coastguard Worker
strstreambuf(void * (* __palloc)(size_t),void (* __pfree)(void *))28*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*))
29*58b9f456SAndroid Build Coastguard Worker : __strmode_(__dynamic),
30*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
31*58b9f456SAndroid Build Coastguard Worker __palloc_(__palloc),
32*58b9f456SAndroid Build Coastguard Worker __pfree_(__pfree)
33*58b9f456SAndroid Build Coastguard Worker {
34*58b9f456SAndroid Build Coastguard Worker }
35*58b9f456SAndroid Build Coastguard Worker
36*58b9f456SAndroid Build Coastguard Worker void
__init(char * __gnext,streamsize __n,char * __pbeg)37*58b9f456SAndroid Build Coastguard Worker strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg)
38*58b9f456SAndroid Build Coastguard Worker {
39*58b9f456SAndroid Build Coastguard Worker if (__n == 0)
40*58b9f456SAndroid Build Coastguard Worker __n = static_cast<streamsize>(strlen(__gnext));
41*58b9f456SAndroid Build Coastguard Worker else if (__n < 0)
42*58b9f456SAndroid Build Coastguard Worker __n = INT_MAX;
43*58b9f456SAndroid Build Coastguard Worker if (__pbeg == nullptr)
44*58b9f456SAndroid Build Coastguard Worker setg(__gnext, __gnext, __gnext + __n);
45*58b9f456SAndroid Build Coastguard Worker else
46*58b9f456SAndroid Build Coastguard Worker {
47*58b9f456SAndroid Build Coastguard Worker setg(__gnext, __gnext, __pbeg);
48*58b9f456SAndroid Build Coastguard Worker setp(__pbeg, __pbeg + __n);
49*58b9f456SAndroid Build Coastguard Worker }
50*58b9f456SAndroid Build Coastguard Worker }
51*58b9f456SAndroid Build Coastguard Worker
strstreambuf(char * __gnext,streamsize __n,char * __pbeg)52*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(char* __gnext, streamsize __n, char* __pbeg)
53*58b9f456SAndroid Build Coastguard Worker : __strmode_(),
54*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
55*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
56*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
57*58b9f456SAndroid Build Coastguard Worker {
58*58b9f456SAndroid Build Coastguard Worker __init(__gnext, __n, __pbeg);
59*58b9f456SAndroid Build Coastguard Worker }
60*58b9f456SAndroid Build Coastguard Worker
strstreambuf(const char * __gnext,streamsize __n)61*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(const char* __gnext, streamsize __n)
62*58b9f456SAndroid Build Coastguard Worker : __strmode_(__constant),
63*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
64*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
65*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
66*58b9f456SAndroid Build Coastguard Worker {
67*58b9f456SAndroid Build Coastguard Worker __init(const_cast<char *>(__gnext), __n, nullptr);
68*58b9f456SAndroid Build Coastguard Worker }
69*58b9f456SAndroid Build Coastguard Worker
strstreambuf(signed char * __gnext,streamsize __n,signed char * __pbeg)70*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg)
71*58b9f456SAndroid Build Coastguard Worker : __strmode_(),
72*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
73*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
74*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
75*58b9f456SAndroid Build Coastguard Worker {
76*58b9f456SAndroid Build Coastguard Worker __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
77*58b9f456SAndroid Build Coastguard Worker }
78*58b9f456SAndroid Build Coastguard Worker
strstreambuf(const signed char * __gnext,streamsize __n)79*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
80*58b9f456SAndroid Build Coastguard Worker : __strmode_(__constant),
81*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
82*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
83*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
84*58b9f456SAndroid Build Coastguard Worker {
85*58b9f456SAndroid Build Coastguard Worker __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
86*58b9f456SAndroid Build Coastguard Worker }
87*58b9f456SAndroid Build Coastguard Worker
strstreambuf(unsigned char * __gnext,streamsize __n,unsigned char * __pbeg)88*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg)
89*58b9f456SAndroid Build Coastguard Worker : __strmode_(),
90*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
91*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
92*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
93*58b9f456SAndroid Build Coastguard Worker {
94*58b9f456SAndroid Build Coastguard Worker __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
95*58b9f456SAndroid Build Coastguard Worker }
96*58b9f456SAndroid Build Coastguard Worker
strstreambuf(const unsigned char * __gnext,streamsize __n)97*58b9f456SAndroid Build Coastguard Worker strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
98*58b9f456SAndroid Build Coastguard Worker : __strmode_(__constant),
99*58b9f456SAndroid Build Coastguard Worker __alsize_(__default_alsize),
100*58b9f456SAndroid Build Coastguard Worker __palloc_(nullptr),
101*58b9f456SAndroid Build Coastguard Worker __pfree_(nullptr)
102*58b9f456SAndroid Build Coastguard Worker {
103*58b9f456SAndroid Build Coastguard Worker __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
104*58b9f456SAndroid Build Coastguard Worker }
105*58b9f456SAndroid Build Coastguard Worker
~strstreambuf()106*58b9f456SAndroid Build Coastguard Worker strstreambuf::~strstreambuf()
107*58b9f456SAndroid Build Coastguard Worker {
108*58b9f456SAndroid Build Coastguard Worker if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
109*58b9f456SAndroid Build Coastguard Worker {
110*58b9f456SAndroid Build Coastguard Worker if (__pfree_)
111*58b9f456SAndroid Build Coastguard Worker __pfree_(eback());
112*58b9f456SAndroid Build Coastguard Worker else
113*58b9f456SAndroid Build Coastguard Worker delete [] eback();
114*58b9f456SAndroid Build Coastguard Worker }
115*58b9f456SAndroid Build Coastguard Worker }
116*58b9f456SAndroid Build Coastguard Worker
117*58b9f456SAndroid Build Coastguard Worker void
swap(strstreambuf & __rhs)118*58b9f456SAndroid Build Coastguard Worker strstreambuf::swap(strstreambuf& __rhs)
119*58b9f456SAndroid Build Coastguard Worker {
120*58b9f456SAndroid Build Coastguard Worker streambuf::swap(__rhs);
121*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__strmode_, __rhs.__strmode_);
122*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__alsize_, __rhs.__alsize_);
123*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__palloc_, __rhs.__palloc_);
124*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__pfree_, __rhs.__pfree_);
125*58b9f456SAndroid Build Coastguard Worker }
126*58b9f456SAndroid Build Coastguard Worker
127*58b9f456SAndroid Build Coastguard Worker void
freeze(bool __freezefl)128*58b9f456SAndroid Build Coastguard Worker strstreambuf::freeze(bool __freezefl)
129*58b9f456SAndroid Build Coastguard Worker {
130*58b9f456SAndroid Build Coastguard Worker if (__strmode_ & __dynamic)
131*58b9f456SAndroid Build Coastguard Worker {
132*58b9f456SAndroid Build Coastguard Worker if (__freezefl)
133*58b9f456SAndroid Build Coastguard Worker __strmode_ |= __frozen;
134*58b9f456SAndroid Build Coastguard Worker else
135*58b9f456SAndroid Build Coastguard Worker __strmode_ &= ~__frozen;
136*58b9f456SAndroid Build Coastguard Worker }
137*58b9f456SAndroid Build Coastguard Worker }
138*58b9f456SAndroid Build Coastguard Worker
139*58b9f456SAndroid Build Coastguard Worker char*
str()140*58b9f456SAndroid Build Coastguard Worker strstreambuf::str()
141*58b9f456SAndroid Build Coastguard Worker {
142*58b9f456SAndroid Build Coastguard Worker if (__strmode_ & __dynamic)
143*58b9f456SAndroid Build Coastguard Worker __strmode_ |= __frozen;
144*58b9f456SAndroid Build Coastguard Worker return eback();
145*58b9f456SAndroid Build Coastguard Worker }
146*58b9f456SAndroid Build Coastguard Worker
147*58b9f456SAndroid Build Coastguard Worker int
pcount() const148*58b9f456SAndroid Build Coastguard Worker strstreambuf::pcount() const
149*58b9f456SAndroid Build Coastguard Worker {
150*58b9f456SAndroid Build Coastguard Worker return static_cast<int>(pptr() - pbase());
151*58b9f456SAndroid Build Coastguard Worker }
152*58b9f456SAndroid Build Coastguard Worker
153*58b9f456SAndroid Build Coastguard Worker strstreambuf::int_type
overflow(int_type __c)154*58b9f456SAndroid Build Coastguard Worker strstreambuf::overflow(int_type __c)
155*58b9f456SAndroid Build Coastguard Worker {
156*58b9f456SAndroid Build Coastguard Worker if (__c == EOF)
157*58b9f456SAndroid Build Coastguard Worker return int_type(0);
158*58b9f456SAndroid Build Coastguard Worker if (pptr() == epptr())
159*58b9f456SAndroid Build Coastguard Worker {
160*58b9f456SAndroid Build Coastguard Worker if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0)
161*58b9f456SAndroid Build Coastguard Worker return int_type(EOF);
162*58b9f456SAndroid Build Coastguard Worker size_t old_size = static_cast<size_t> ((epptr() ? epptr() : egptr()) - eback());
163*58b9f456SAndroid Build Coastguard Worker size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2*old_size);
164*58b9f456SAndroid Build Coastguard Worker if (new_size == 0)
165*58b9f456SAndroid Build Coastguard Worker new_size = __default_alsize;
166*58b9f456SAndroid Build Coastguard Worker char* buf = nullptr;
167*58b9f456SAndroid Build Coastguard Worker if (__palloc_)
168*58b9f456SAndroid Build Coastguard Worker buf = static_cast<char*>(__palloc_(new_size));
169*58b9f456SAndroid Build Coastguard Worker else
170*58b9f456SAndroid Build Coastguard Worker buf = new char[new_size];
171*58b9f456SAndroid Build Coastguard Worker if (buf == nullptr)
172*58b9f456SAndroid Build Coastguard Worker return int_type(EOF);
173*58b9f456SAndroid Build Coastguard Worker if (old_size != 0) {
174*58b9f456SAndroid Build Coastguard Worker _LIBCPP_ASSERT(eback(), "overflow copying from NULL");
175*58b9f456SAndroid Build Coastguard Worker memcpy(buf, eback(), static_cast<size_t>(old_size));
176*58b9f456SAndroid Build Coastguard Worker }
177*58b9f456SAndroid Build Coastguard Worker ptrdiff_t ninp = gptr() - eback();
178*58b9f456SAndroid Build Coastguard Worker ptrdiff_t einp = egptr() - eback();
179*58b9f456SAndroid Build Coastguard Worker ptrdiff_t nout = pptr() - pbase();
180*58b9f456SAndroid Build Coastguard Worker if (__strmode_ & __allocated)
181*58b9f456SAndroid Build Coastguard Worker {
182*58b9f456SAndroid Build Coastguard Worker if (__pfree_)
183*58b9f456SAndroid Build Coastguard Worker __pfree_(eback());
184*58b9f456SAndroid Build Coastguard Worker else
185*58b9f456SAndroid Build Coastguard Worker delete [] eback();
186*58b9f456SAndroid Build Coastguard Worker }
187*58b9f456SAndroid Build Coastguard Worker setg(buf, buf + ninp, buf + einp);
188*58b9f456SAndroid Build Coastguard Worker setp(buf + einp, buf + new_size);
189*58b9f456SAndroid Build Coastguard Worker __pbump(nout);
190*58b9f456SAndroid Build Coastguard Worker __strmode_ |= __allocated;
191*58b9f456SAndroid Build Coastguard Worker }
192*58b9f456SAndroid Build Coastguard Worker *pptr() = static_cast<char>(__c);
193*58b9f456SAndroid Build Coastguard Worker pbump(1);
194*58b9f456SAndroid Build Coastguard Worker return int_type(static_cast<unsigned char>(__c));
195*58b9f456SAndroid Build Coastguard Worker }
196*58b9f456SAndroid Build Coastguard Worker
197*58b9f456SAndroid Build Coastguard Worker strstreambuf::int_type
pbackfail(int_type __c)198*58b9f456SAndroid Build Coastguard Worker strstreambuf::pbackfail(int_type __c)
199*58b9f456SAndroid Build Coastguard Worker {
200*58b9f456SAndroid Build Coastguard Worker if (eback() == gptr())
201*58b9f456SAndroid Build Coastguard Worker return EOF;
202*58b9f456SAndroid Build Coastguard Worker if (__c == EOF)
203*58b9f456SAndroid Build Coastguard Worker {
204*58b9f456SAndroid Build Coastguard Worker gbump(-1);
205*58b9f456SAndroid Build Coastguard Worker return int_type(0);
206*58b9f456SAndroid Build Coastguard Worker }
207*58b9f456SAndroid Build Coastguard Worker if (__strmode_ & __constant)
208*58b9f456SAndroid Build Coastguard Worker {
209*58b9f456SAndroid Build Coastguard Worker if (gptr()[-1] == static_cast<char>(__c))
210*58b9f456SAndroid Build Coastguard Worker {
211*58b9f456SAndroid Build Coastguard Worker gbump(-1);
212*58b9f456SAndroid Build Coastguard Worker return __c;
213*58b9f456SAndroid Build Coastguard Worker }
214*58b9f456SAndroid Build Coastguard Worker return EOF;
215*58b9f456SAndroid Build Coastguard Worker }
216*58b9f456SAndroid Build Coastguard Worker gbump(-1);
217*58b9f456SAndroid Build Coastguard Worker *gptr() = static_cast<char>(__c);
218*58b9f456SAndroid Build Coastguard Worker return __c;
219*58b9f456SAndroid Build Coastguard Worker }
220*58b9f456SAndroid Build Coastguard Worker
221*58b9f456SAndroid Build Coastguard Worker strstreambuf::int_type
underflow()222*58b9f456SAndroid Build Coastguard Worker strstreambuf::underflow()
223*58b9f456SAndroid Build Coastguard Worker {
224*58b9f456SAndroid Build Coastguard Worker if (gptr() == egptr())
225*58b9f456SAndroid Build Coastguard Worker {
226*58b9f456SAndroid Build Coastguard Worker if (egptr() >= pptr())
227*58b9f456SAndroid Build Coastguard Worker return EOF;
228*58b9f456SAndroid Build Coastguard Worker setg(eback(), gptr(), pptr());
229*58b9f456SAndroid Build Coastguard Worker }
230*58b9f456SAndroid Build Coastguard Worker return int_type(static_cast<unsigned char>(*gptr()));
231*58b9f456SAndroid Build Coastguard Worker }
232*58b9f456SAndroid Build Coastguard Worker
233*58b9f456SAndroid Build Coastguard Worker strstreambuf::pos_type
seekoff(off_type __off,ios_base::seekdir __way,ios_base::openmode __which)234*58b9f456SAndroid Build Coastguard Worker strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which)
235*58b9f456SAndroid Build Coastguard Worker {
236*58b9f456SAndroid Build Coastguard Worker off_type __p(-1);
237*58b9f456SAndroid Build Coastguard Worker bool pos_in = (__which & ios::in) != 0;
238*58b9f456SAndroid Build Coastguard Worker bool pos_out = (__which & ios::out) != 0;
239*58b9f456SAndroid Build Coastguard Worker bool legal = false;
240*58b9f456SAndroid Build Coastguard Worker switch (__way)
241*58b9f456SAndroid Build Coastguard Worker {
242*58b9f456SAndroid Build Coastguard Worker case ios::beg:
243*58b9f456SAndroid Build Coastguard Worker case ios::end:
244*58b9f456SAndroid Build Coastguard Worker if (pos_in || pos_out)
245*58b9f456SAndroid Build Coastguard Worker legal = true;
246*58b9f456SAndroid Build Coastguard Worker break;
247*58b9f456SAndroid Build Coastguard Worker case ios::cur:
248*58b9f456SAndroid Build Coastguard Worker if (pos_in != pos_out)
249*58b9f456SAndroid Build Coastguard Worker legal = true;
250*58b9f456SAndroid Build Coastguard Worker break;
251*58b9f456SAndroid Build Coastguard Worker }
252*58b9f456SAndroid Build Coastguard Worker if (pos_in && gptr() == nullptr)
253*58b9f456SAndroid Build Coastguard Worker legal = false;
254*58b9f456SAndroid Build Coastguard Worker if (pos_out && pptr() == nullptr)
255*58b9f456SAndroid Build Coastguard Worker legal = false;
256*58b9f456SAndroid Build Coastguard Worker if (legal)
257*58b9f456SAndroid Build Coastguard Worker {
258*58b9f456SAndroid Build Coastguard Worker off_type newoff;
259*58b9f456SAndroid Build Coastguard Worker char* seekhigh = epptr() ? epptr() : egptr();
260*58b9f456SAndroid Build Coastguard Worker switch (__way)
261*58b9f456SAndroid Build Coastguard Worker {
262*58b9f456SAndroid Build Coastguard Worker case ios::beg:
263*58b9f456SAndroid Build Coastguard Worker newoff = 0;
264*58b9f456SAndroid Build Coastguard Worker break;
265*58b9f456SAndroid Build Coastguard Worker case ios::cur:
266*58b9f456SAndroid Build Coastguard Worker newoff = (pos_in ? gptr() : pptr()) - eback();
267*58b9f456SAndroid Build Coastguard Worker break;
268*58b9f456SAndroid Build Coastguard Worker case ios::end:
269*58b9f456SAndroid Build Coastguard Worker newoff = seekhigh - eback();
270*58b9f456SAndroid Build Coastguard Worker break;
271*58b9f456SAndroid Build Coastguard Worker default:
272*58b9f456SAndroid Build Coastguard Worker _LIBCPP_UNREACHABLE();
273*58b9f456SAndroid Build Coastguard Worker }
274*58b9f456SAndroid Build Coastguard Worker newoff += __off;
275*58b9f456SAndroid Build Coastguard Worker if (0 <= newoff && newoff <= seekhigh - eback())
276*58b9f456SAndroid Build Coastguard Worker {
277*58b9f456SAndroid Build Coastguard Worker char* newpos = eback() + newoff;
278*58b9f456SAndroid Build Coastguard Worker if (pos_in)
279*58b9f456SAndroid Build Coastguard Worker setg(eback(), newpos, _VSTD::max(newpos, egptr()));
280*58b9f456SAndroid Build Coastguard Worker if (pos_out)
281*58b9f456SAndroid Build Coastguard Worker {
282*58b9f456SAndroid Build Coastguard Worker // min(pbase, newpos), newpos, epptr()
283*58b9f456SAndroid Build Coastguard Worker __off = epptr() - newpos;
284*58b9f456SAndroid Build Coastguard Worker setp(min(pbase(), newpos), epptr());
285*58b9f456SAndroid Build Coastguard Worker __pbump((epptr() - pbase()) - __off);
286*58b9f456SAndroid Build Coastguard Worker }
287*58b9f456SAndroid Build Coastguard Worker __p = newoff;
288*58b9f456SAndroid Build Coastguard Worker }
289*58b9f456SAndroid Build Coastguard Worker }
290*58b9f456SAndroid Build Coastguard Worker return pos_type(__p);
291*58b9f456SAndroid Build Coastguard Worker }
292*58b9f456SAndroid Build Coastguard Worker
293*58b9f456SAndroid Build Coastguard Worker strstreambuf::pos_type
seekpos(pos_type __sp,ios_base::openmode __which)294*58b9f456SAndroid Build Coastguard Worker strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which)
295*58b9f456SAndroid Build Coastguard Worker {
296*58b9f456SAndroid Build Coastguard Worker off_type __p(-1);
297*58b9f456SAndroid Build Coastguard Worker bool pos_in = (__which & ios::in) != 0;
298*58b9f456SAndroid Build Coastguard Worker bool pos_out = (__which & ios::out) != 0;
299*58b9f456SAndroid Build Coastguard Worker if (pos_in || pos_out)
300*58b9f456SAndroid Build Coastguard Worker {
301*58b9f456SAndroid Build Coastguard Worker if (!((pos_in && gptr() == nullptr) || (pos_out && pptr() == nullptr)))
302*58b9f456SAndroid Build Coastguard Worker {
303*58b9f456SAndroid Build Coastguard Worker off_type newoff = __sp;
304*58b9f456SAndroid Build Coastguard Worker char* seekhigh = epptr() ? epptr() : egptr();
305*58b9f456SAndroid Build Coastguard Worker if (0 <= newoff && newoff <= seekhigh - eback())
306*58b9f456SAndroid Build Coastguard Worker {
307*58b9f456SAndroid Build Coastguard Worker char* newpos = eback() + newoff;
308*58b9f456SAndroid Build Coastguard Worker if (pos_in)
309*58b9f456SAndroid Build Coastguard Worker setg(eback(), newpos, _VSTD::max(newpos, egptr()));
310*58b9f456SAndroid Build Coastguard Worker if (pos_out)
311*58b9f456SAndroid Build Coastguard Worker {
312*58b9f456SAndroid Build Coastguard Worker // min(pbase, newpos), newpos, epptr()
313*58b9f456SAndroid Build Coastguard Worker off_type temp = epptr() - newpos;
314*58b9f456SAndroid Build Coastguard Worker setp(min(pbase(), newpos), epptr());
315*58b9f456SAndroid Build Coastguard Worker __pbump((epptr() - pbase()) - temp);
316*58b9f456SAndroid Build Coastguard Worker }
317*58b9f456SAndroid Build Coastguard Worker __p = newoff;
318*58b9f456SAndroid Build Coastguard Worker }
319*58b9f456SAndroid Build Coastguard Worker }
320*58b9f456SAndroid Build Coastguard Worker }
321*58b9f456SAndroid Build Coastguard Worker return pos_type(__p);
322*58b9f456SAndroid Build Coastguard Worker }
323*58b9f456SAndroid Build Coastguard Worker
~istrstream()324*58b9f456SAndroid Build Coastguard Worker istrstream::~istrstream()
325*58b9f456SAndroid Build Coastguard Worker {
326*58b9f456SAndroid Build Coastguard Worker }
327*58b9f456SAndroid Build Coastguard Worker
~ostrstream()328*58b9f456SAndroid Build Coastguard Worker ostrstream::~ostrstream()
329*58b9f456SAndroid Build Coastguard Worker {
330*58b9f456SAndroid Build Coastguard Worker }
331*58b9f456SAndroid Build Coastguard Worker
~strstream()332*58b9f456SAndroid Build Coastguard Worker strstream::~strstream()
333*58b9f456SAndroid Build Coastguard Worker {
334*58b9f456SAndroid Build Coastguard Worker }
335*58b9f456SAndroid Build Coastguard Worker
336*58b9f456SAndroid Build Coastguard Worker _LIBCPP_END_NAMESPACE_STD
337