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

int tar_input_filename::read_data ( void *  buffer,
int  buffer_length 
) [virtual]

The read_data method is used to read a block of data from the input. The `buffer_length' argument specifies the maximum number of bytes in the `buffer'. Returns the number of bytes read, or 0 at end of file.

Implements tar_input.

Definition at line 52 of file filename.cc.

References length, file_input::read(), source, and tar_input::warning().

{
      //
      // If we have had enough, stop now, even if the file has grown
      // in the mean time.
      //
      if (length <= 0)
            return 0;

      //
      // If there is no input (because we have already complained
      // about it shrinking) fake a bunch of zeros.
      //
      if (!source)
      {
            // This should never happen
            int nbytes = length;
            if (nbytes > buffer_length)
                  nbytes = buffer_length;
            memset(buffer, 0, nbytes);
            length -= nbytes;
            return nbytes;
      }

      //
      // Read data from the input.  As much as possible, up to the
      // maximum buffer length.
      //
      int maxbytes = length;
      if (maxbytes > buffer_length)
            maxbytes = buffer_length;
      int nbytes = source->read(buffer, maxbytes);
      if (nbytes == 0)
      {
            warning("file shortened unexpectedly");
            delete source;
            source = 0;
            memset(buffer, 0, maxbytes);
            length -= maxbytes;
            return maxbytes;
      }
      length -= nbytes;
      return nbytes;
}


Generated by  Doxygen 1.6.0   Back to index