Logo Search packages:      
Sourcecode: catdoc version File versions

size_t ole_read ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

Reads block from open ole stream interface-compatible with fread

Parameters:
ptr pointer to buffer for read to
size size of block
nmemb size in blocks
stream pointer to FILE* structure
Returns:
number of readed blocks

< Size of block

Definition at line 379 of file ole.c.

References calcFileBlockOffset().

                                                                    {
      oleEntry *e = (oleEntry*)stream;
      long int llen = size*nmemb, rread=0, i;
      long int blockNumber, modBlock, toReadBlocks, toReadBytes, bytesInBlock;
      long int ssize;                     /**< Size of block */
      long int newoffset;
      unsigned char *cptr = ptr;    
      if( e->readed+llen > e->length )
            llen= e->length - e->readed;
      
      ssize = (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE);
      blockNumber=e->readed/ssize;
/*    fprintf(stderr, "blockNumber=%ld e->numOfBlocks=%ld llen=%ld\n", */
/*                blockNumber, e->numOfBlocks, llen); */
      if ( blockNumber >= e->numOfBlocks || llen <=0 )
            return 0;
      
      modBlock=e->readed%ssize;
      bytesInBlock = ssize - modBlock;
      if(bytesInBlock < llen) {
            toReadBlocks = (llen-bytesInBlock)/ssize;
            toReadBytes = (llen-bytesInBlock)%ssize; 
      } else {
            toReadBlocks = toReadBytes = 0;
      }
/*    fprintf(stderr, "llen=%ld toReadBlocks=%ld toReadBytes=%ld bytesInBlock=%ld blockNumber=%ld modBlock=%ld\n", */
/*                llen, toReadBlocks, toReadBytes, bytesInBlock, blockNumber, modBlock); */
      newoffset = calcFileBlockOffset(e,blockNumber)+modBlock;
      if (e->offset != newoffset) {
            fseek(e->file, e->offset=newoffset, SEEK_SET);
      }
      rread=fread(ptr, 1, min(llen,bytesInBlock), e->file);
      e->offset += rread;
      for(i=0; i<toReadBlocks; i++) {
            int readbytes;
            blockNumber++;
            newoffset = calcFileBlockOffset(e,blockNumber);
            if (newoffset != e->offset);
            fseek(e->file, e->offset=newoffset , SEEK_SET);
            readbytes=fread(cptr+rread, 1, min(llen-rread, ssize), e->file);
            rread +=readbytes;
            e->offset +=readbytes;
      }
      if(toReadBytes > 0) {
            int readbytes;
            blockNumber++;
            newoffset = calcFileBlockOffset(e,blockNumber);
            fseek(e->file, e->offset=newoffset, SEEK_SET);
        readbytes=fread(cptr+rread, 1, toReadBytes,e ->file);
            rread +=readbytes;
            e->offset +=readbytes;
      }
/*    fprintf(stderr, "readed=%ld rread=%ld llen=%ld\n",
      e->readed, rread, llen);*/
      e->readed+=rread;
      return rread;
}     


Generated by  Doxygen 1.6.0   Back to index