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

BDBuffer * File::read (  )  const throw (YAPETException) [protected]

Reads from the current offset in the file.

Reads from the current position in the file. The method expects the file pointer to point a record length indicator. In other words, it first reads four bytes from the current file position, which will give it a clue about the length of the encrypted record to read.

It then reads as many bytes as indicated from the file and returns the data read in a BDBuffer. The memory allocated by the BDBuffer has to be freed by the caller.

The record length indicator needs to be stored in big-endian order.

Returns:
a pointer to a BDBuffer holding the encrypted password record. The memory occupied by the buffer has to be freed by the caller of the method. It returns NULL when the end of file has been reached.

Definition at line 354 of file file.cc.

References fd, filename, and uint32_from_disk().

Referenced by read(), readHeader(), seekDataSection(), and setNewKey().

                                       {
    uint32_t len;
    int retval = ::read(fd, &len, sizeof(uint32_t));
    if (retval == -1)
      throw YAPETException(strerror(errno));

    if (retval == 0)
      return NULL;

    if ( ((size_t)retval) < sizeof(uint32_t) )
      throw YAPETException(_("Short read on file: ") + filename);

    // Convert len to the endianess of the architecture
    len = uint32_from_disk(len);

    BDBuffer* buf = new BDBuffer(len);
    retval = ::read(fd, *buf, len);
    if (retval == -1)
      throw YAPETException(strerror(errno));

    if (retval == 0) {
      delete buf;
      return NULL;
    }

    if (((uint32_t)retval) < len) {
      delete buf;
      throw YAPETException(_("Short read on file: ") + filename);
    }

    return buf;
}


Generated by  Doxygen 1.6.0   Back to index