RFC: basic_filebuf supporting non-modal I/O without seekpos

Paolo Carlini paolo.carlini@oracle.com
Mon Sep 20 19:22:00 GMT 2010


On 09/18/2010 08:36 AM, David Krauss wrote:
> @@ -410,8 +426,16 @@
>        int_type __ret = traits_type::eof();
>        const bool __testeof = traits_type::eq_int_type(__c, __ret);
>        const bool __testout = _M_mode & ios_base::out;
> -      if (__testout && !_M_reading)
> +      if (__testout)
>         {
> +         if (_M_reading)
> +           {
> +             _M_destroy_pback();
> +             const int __gptr_off = _M_get_ext_pos(_M_state_last);
> +             if (_M_seek(__gptr_off, ios_base::cur, _M_state_last)
> +                 == pos_type(off_type(-1)))
> +               return __ret;
> +           }
>   
By the way, as far as I'm concerned, this is the key idea I was missing,
not having seriously looked at these mechanisms for many years: a
sort-of lazy seek, which we are able to delay to when it's really
necessary, when we switch from reading to writing without an explicit
seek in the middle, and we cannot avoid adjusting the file position.
Thanks David for working out this stuff.

Paolo.



More information about the Libstdc++ mailing list