Logo Search packages:      
Sourcecode: catdoc version File versions

FILE* ole_readdir ( FILE *  f  ) 

Reads next directory entry from file

Parameters:
name buffer for name converted to us-ascii should be at least 33 chars long
size size of file
Returns:
0 if everything is ok -1 on error

Definition at line 245 of file ole.c.

References getOleType(), and rightOleType().

Referenced by ole_init().

                           {
      int i, nLen;
      unsigned char *oleBuf;
      oleEntry *e=NULL;
      long int chainMaxLen, chainCurrent;
      
      if ( properties == NULL || propCurNumber >= propNumber || f == NULL )
            return NULL;
      oleBuf=properties + propCurNumber*PROP_BLOCK_SIZE;
      if( !rightOleType(oleBuf))
            return NULL;
      if ((e = (oleEntry*)malloc(sizeof(oleEntry))) == NULL) {
            perror("Can\'t allocate memory");
            return NULL;
      }
      e->dirPos=oleBuf;
      e->type=getOleType(oleBuf);
      e->file=f;
      e->startBlock=getlong(oleBuf,0x74);
      e->blocks=NULL;
      
      nLen=getshort(oleBuf,0x40);
      for (i=0 ; i < nLen /2; i++)
            e->name[i]=(char)oleBuf[i*2];
      e->name[i]='\0';
      propCurNumber++;
      e->length=getulong(oleBuf,0x78);
/* Read sector chain for object */
      chainMaxLen = 25;
      e->numOfBlocks = 0;
      chainCurrent = e->startBlock;
      e->isBigBlock = (e->length >= 0x1000) || !strcmp(e->name, "Root Entry");
/*    fprintf(stderr, "e->name=%s e->length=%ld\n", e->name, e->length); */
/*    fprintf(stderr, "e->startBlock=%ld BBD=%p\n", e->startBlock, BBD); */
      if (e->startBlock >= 0 &&
            e->length > 0 &&
            (e->startBlock <=
             fileLength/(e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE))) {
            if((e->blocks=malloc(chainMaxLen*sizeof(long int))) == NULL ) {
                  return NULL;
            }
            while(1) {
/*                fprintf(stderr, "chainCurrent=%ld\n", chainCurrent); */
                  e->blocks[e->numOfBlocks++] = chainCurrent;
                  if (e->numOfBlocks >= chainMaxLen) {
                        long int *newChain;
                        chainMaxLen+=25;
                        if ((newChain=realloc(e->blocks,
                                                        chainMaxLen*sizeof(long int))) != NULL)
                              e->blocks=newChain;
                        else {
                              perror("Properties realloc error");
                              free(e->blocks);
                              e->blocks=NULL;
                              return NULL;
                        }
                  }
                  if ( e->isBigBlock ) {
                        chainCurrent = getlong(BBD, chainCurrent*4);
                  } else if ( SBD != NULL ) {
                        chainCurrent = getlong(SBD, chainCurrent*4);
                  } else {
                        chainCurrent=-1;
                  }
                  if(chainCurrent <= 0 ||
                     chainCurrent >= ( e->isBigBlock ?
                                                 ((bbdNumBlocks*BBD_BLOCK_SIZE)/4)
                                                 : ((sbdNumber*SBD_BLOCK_SIZE)/4) ) ||
                     (e->numOfBlocks >
                        e->length/(e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE))) {
/*                      fprintf(stderr, "chain End=%ld\n", chainCurrent);   */
                        break;
                  }
                  
            }
      }
      if(e->length > (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE)*e->numOfBlocks)
            e->length = (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE)*e->numOfBlocks;
/*    fprintf(stderr, "READDIR: e->name=%s e->numOfBlocks=%ld length=%ld\n",
      e->name, e->numOfBlocks, e->length);*/
      
      return (FILE*)e;
}


Generated by  Doxygen 1.6.0   Back to index