Ian Romanick pisze:
>> +     }
>> +}
>> +
>> +void
>> +testFile_parse()
>> +{
>> +     FILE* filePointer;
>> +     int i=0, secLength=0, fileLength=0, state=0, currentTest=0;
>> +     char c;
>> +     char word[32];
>> +     char *cP;
>> +
>> +     filePointer = fopen(filename, "rt");
>> +     if(!filePointer)
>> +             piglit_report_result(PIGLIT_FAILURE);
>> +
>> +
>> +     while(fgetc(filePointer)!=EOF)
>> +             fileLength++;
>> +
>> +     if(fileLength <1)
>> +             piglit_report_result(PIGLIT_FAILURE);
>> +
>> +     fclose(filePointer);
>> +
>> +     filePointer = fopen(filename, "rt");
>> +     buffer = (char*) malloc(fileLength+1);
>> +
>> +     c = fgetc(filePointer);
>> +     while(c != EOF)
>> +     {
>> +             buffer[i] = c;
>> +             ++i;
>> +             c = fgetc(filePointer);
>> +     }
>> +
>> +     buffer[i] = '\0';
>> +     fclose(filePointer);
>>     
>
> The code above made my eyes bleed.
>
>         fp = fopen(filename, "r");
>         if (fp == NULL)
>                 /* error */ ;
>
>         fseek(fp, 0, SEEK_END);
>         fileLength = ftell(fp);
>         fseek(fp, 0, SEEK_SET);
>
>         buffer = malloc(fileLength + 1);
>         fread(buffer, fileLength, 1, fp);
>         fclose(fp);
>
>         buffer[fileLength] = '\0';
>
>   
This won't always work on Windows due to newline conversion taking place 
on fread(), but not being taken into account when calculating file size 
using fseek()/ftell() pair.

> Or just use piglit_load_text_file.
>
>         buffer = pitlit_load_text_file(filename, & fileLength);
>
>   
Yes, use that one or open the file in binary mode.



------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to