Changeset 46


Ignore:
Timestamp:
Feb 13, 2008, 1:26:55 PM (11 years ago)
Author:
ksherdy
Message:

Replace stat(filename) with fstat(fileno(infile)).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/xmlbuffer.c

    r42 r46  
    259259XML_Buffer_Interface * XML_Buffer_Interface::BufferFactory(char* filename) {
    260260        int chars_read;
    261         struct stat fileinfo;
    262         stat(filename, &fileinfo);
    263         int buffer_packs = (fileinfo.st_size + BUFFER_PADDING + PACKSIZE - 1)/PACKSIZE;
    264         BytePack * src_data = simd_new(buffer_packs);
    265         unsigned char * bytedata = (unsigned char *) src_data;
    266261        FILE *infile;
    267262        infile = fopen(filename, "rb");
     
    270265                exit(-1);
    271266        }
    272         chars_read = fread(bytedata, 1, fileinfo.st_size, infile);
     267       
     268        struct stat fileinfo;
     269        if(fstat(fileno(infile), &fileinfo)!=0) {
     270                fprintf(stderr, "Error: cannot fstat %s for file size.\n", filename);
     271                exit(-1);
     272        }
     273       
     274        int buffer_packs = (fileinfo.st_size + BUFFER_PADDING + PACKSIZE - 1)/PACKSIZE;
     275        BytePack * src_data = simd_new(buffer_packs);
     276        unsigned char * bytedata = (unsigned char *) src_data; 
     277       
     278        chars_read = fread(bytedata, 1, fileinfo.st_size, infile);
    273279        if (chars_read != fileinfo.st_size) {
    274280                fprintf(stderr, "Error: fread returned %i characters, expecting %i.\n",
     
    276282                exit(-1);
    277283        }
     284       
    278285        // Install null sentinels.
    279286        memset(&bytedata[chars_read], 0, BUFFER_PADDING);
Note: See TracChangeset for help on using the changeset viewer.