@@ -74,6 +74,66 @@ class BasicMemoryStreamBuf: public std::basic_streambuf<ch, tr>
7474 return char_traits::eof ();
7575 }
7676
77+ virtual pos_type seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
78+ {
79+ const pos_type fail = off_type (-1 );
80+ off_type newoff = off_type (-1 );
81+
82+ if ((which & std::ios_base::in) != 0 )
83+ {
84+ if (this ->gptr () == 0 )
85+ return fail;
86+
87+ switch (way)
88+ {
89+ case std::ios_base::beg:
90+ newoff = 0 ;
91+ break ;
92+ case std::ios_base::cur:
93+ // cur is not valid if both in and out are specified (Condition 3)
94+ if ((which & std::ios_base::out) != 0 )
95+ return fail;
96+ newoff = this ->gptr () - this ->eback ();
97+ break ;
98+ case std::ios_base::end:
99+ newoff = this ->egptr () - this ->eback ();
100+ break ;
101+ }
102+
103+ if ((newoff + off) < 0 || (this ->egptr () - this ->eback ()) < (newoff + off))
104+ return fail;
105+ this ->setg (this ->eback (), this ->eback () + newoff + off, this ->egptr ());
106+ }
107+
108+ if ((which & std::ios_base::out) != 0 )
109+ {
110+ if (this ->pptr () == 0 )
111+ return fail;
112+
113+ switch (way)
114+ {
115+ case std::ios_base::beg:
116+ newoff = 0 ;
117+ break ;
118+ case std::ios_base::cur:
119+ // cur is not valid if both in and out are specified (Condition 3)
120+ if ((which & std::ios_base::in) != 0 )
121+ return fail;
122+ newoff = this ->pptr () - this ->pbase ();
123+ break ;
124+ case std::ios_base::end:
125+ newoff = this ->epptr () - this ->pbase ();
126+ break ;
127+ }
128+
129+ if (newoff + off < 0 || (this ->epptr () - this ->pbase ()) < newoff + off)
130+ return fail;
131+ this ->pbump ((int )(newoff + off - (this ->pptr () - this ->pbase ())));
132+ }
133+
134+ return newoff;
135+ }
136+
77137 virtual int sync ()
78138 {
79139 return 0 ;
0 commit comments