fix import_stl for windows build

This commit is contained in:
alemuntoni 2021-03-02 15:32:35 +01:00
parent a7c1893b8d
commit b54ca75043
1 changed files with 5 additions and 5 deletions

View File

@ -153,13 +153,13 @@ static bool IsSTLBinary(const char * filename, bool &binaryFlag)
FILE *fp = fopen(filename, "rb");
/* Find size of file */
fseek(fp, 0, SEEK_END);
unsigned long file_size = ftell(fp);
std::size_t file_size = ftell(fp);
unsigned int facenum;
/* Check for binary or ASCII file */
fseek(fp, STL_LABEL_SIZE, SEEK_SET);
fread(&facenum, sizeof(unsigned int), 1, fp);
unsigned long expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ;
std::size_t expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ;
if(file_size == expected_file_size)
{
binaryFlag = true;
@ -169,15 +169,15 @@ static bool IsSTLBinary(const char * filename, bool &binaryFlag)
// second check, sometimes the size is a bit wrong,
// lets'make a test to check that we find only ascii stuff before assuming it is ascii
unsigned char tmpbuf[1000];
unsigned long byte_to_read = std::min(sizeof(tmpbuf), file_size - 80);
std::size_t byte_to_read = std::min(sizeof(tmpbuf), (size_t)file_size - 80);
fread(tmpbuf, byte_to_read,1,fp);
fclose(fp);
for(unsigned long i = 0; i < byte_to_read; i++)
for(std::size_t i = 0; i < byte_to_read; i++)
{
if(tmpbuf[i] > 127)
{
binaryFlag=true;
unsigned long diff = (file_size > expected_file_size) ? file_size-expected_file_size : expected_file_size-file_size;
std::size_t diff = (file_size > expected_file_size) ? file_size-expected_file_size : expected_file_size-file_size;
if(diff > file_size/20 )
return false; //
break;