This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: filebuf.in_avail


on Wed, Jun 07, 2000 at 07:28:51PM -0700, Dietmar Kuehl typed aloud:
| Hi,
| 
| --- brent verner <brent@rcfile.org> wrote:
| > my reading of this is that in_avail() should return -1 when EOF ...
| 
| Correct.
| 
| > I can't see where it _could_ return 0;
| 
| It will often return '0': The intentation of 'in_avail()' is to
| determine how many characters can be read without running the risk of
| blocking. Once a file is exhausted and the position sits at the
| [current] end of the file, 'in_avail()' will return '0' but not EOF!
| The file, even a non-special file might grow. Thus, if a user read
| right to the end but not beyond, EOF is not reached and 'in_avail()'
| returns '0'. Actually, 'in_avail()' might even return '0' in the middle
| of a file, namely when hitting the boundary of a buffer: It is QoI
| issue whether 'showmanyc()' tries to be clever and determine a better
| approximation than what is known to the stream buffer any.
|
| It is important to note that there is a difference between EOF and
| sitting at the end of a file: After EOF is reached, no character will
| be available from the stream. If a stream sits currently at the end of
| the file, there may be characters available in the future.

ACK

I have much to learn... Originally, I interpreted the wording as 
roughly: (noting the failure to consider non-blocking I/O)

in_avail(){
  return ( egptr() - gptr() || showmanyc() );
}

showmanyc(){
  if( underflow() == traits::eof() ){ return -1; }
  return egptr() - gptr();
}

underflow(){
  ssize_t r;
  if( (r = read(FILE, _M_buf, _M_buf_size)) == 0 ){
    return traits::eof();
  }
  /*
  else if( r == -1 ){
    // read() error, possibly from O_NONBLOCK :)
    // no data available, but not EOF
    // set get pointers .. egptr() == gptr()
    // Q: what should be returned here ???
    return traits::to_int_type(???); //
  }
  */
  // set get pointers ... egptr() > gptr()
  return traits::to_int_type(_M_buf[0]);
}

coffeetime.
  Brent

| =====
| <mailto:dietmar_kuehl@yahoo.com>
| <http://www.dietmar-kuehl.de/>
| 
| __________________________________________________
| Do You Yahoo!?
| Yahoo! Photos -- now, 100 FREE prints!
| http://photos.yahoo.com

-- 
Damon Brent Verner
Cracker JackŪ Certified Professional
brent@rcfile.org, brent@linux1.org

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]