Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

size_t ByteStream::Stdio::read ( void *  buffer,
size_t  size 
) [virtual]

Reads data from a ByteStream. This function {must} be implemented by each subclass of ByteStream#. At most size# bytes are read from the ByteStream and stored in the memory area pointed to by buffer#. Function read# returns immediately if size# is zero. The actual number of bytes read is returned. Function read# returns a number of bytes smaller than size# if the end-of-file mark is reached before filling the buffer. Subsequent invocations will always return value #0#. Function read# may also return a value greater than zero but smaller than size# for internal reasons. Programs must be ready to handle these cases or use function {readall}. Exception {GException} is thrown with a plain text error message whenever an error occurs.

Reimplemented from ByteStream.

Definition at line 699 of file ByteStream.cpp.

{
  if (!can_read)
    G_THROW( ERR_MSG("ByteStream.no_read") ); //  Stdio not opened for reading
  size_t nitems;
  do
  {
    clearerr(fp);
    nitems = fread(buffer, 1, size, fp); 
    if (nitems<=0 && ferror(fp))
    {
#ifdef EINTR
      if (errno!=EINTR)
#endif
        G_THROW(strerror(errno)); //  (No error in the DjVuMessageFile)
    }
    else
      break;
  } while(true);
  pos += nitems;
  return nitems;
}

Generated by  Doxygen 1.6.0   Back to index