Browse Source

[BUG FIX]: freopen doesn't work on windows

Former-commit-id: 5ff09e1647b2cad3c76546f2db3646c659465b4e
Alec Jacobson 7 năm trước cách đây
mục cha
commit
2370f45420
3 tập tin đã thay đổi với 9 bổ sung6 xóa
  1. 3 2
      include/igl/is_stl.cpp
  2. 5 3
      include/igl/readSTL.cpp
  3. 1 1
      include/igl/read_triangle_mesh.cpp

+ 3 - 2
include/igl/is_stl.cpp

@@ -12,7 +12,7 @@ IGL_INLINE bool igl::is_stl(FILE * stl_file, bool & is_ascii)
   //
   const auto perfect_size = [](FILE * stl_file)->bool
   {
-    stl_file = freopen(NULL,"rb",stl_file);
+    //stl_file = freopen(NULL,"rb",stl_file);
     // Read 80 header
     char header[80];
     if(fread(header,sizeof(char),80,stl_file)!=80)
@@ -27,7 +27,8 @@ IGL_INLINE bool igl::is_stl(FILE * stl_file, bool & is_ascii)
     }
     fseek(stl_file,0,SEEK_END);
     int file_size = ftell(stl_file);
-    stl_file = freopen(NULL,"r",stl_file);
+    fseek(stl_file,0,SEEK_SET);
+    //stl_file = freopen(NULL,"r",stl_file);
     return (file_size == 80 + 4 + (4*12 + 2) * num_tri);
   };
   // Specifically 80 character header

+ 5 - 3
include/igl/readSTL.cpp

@@ -71,7 +71,7 @@ IGL_INLINE bool igl::readSTL(
   std::vector<std::vector<TypeN> > & N)
 {
   using namespace std;
-  stl_file = freopen(NULL,"rb",stl_file);
+  //stl_file = freopen(NULL,"rb",stl_file);
   if(NULL==stl_file)
   {
     fprintf(stderr,"IOError: stl file could not be reopened as binary (1) ...\n");
@@ -122,7 +122,8 @@ IGL_INLINE bool igl::readSTL(
   {
     // Rewind to end of header
     //stl_file = fopen(filename.c_str(),"r");
-    stl_file = freopen(NULL,"r",stl_file);
+    //stl_file = freopen(NULL,"r",stl_file);
+    fseek(stl_file, 0, SEEK_SET);
     if(NULL==stl_file)
     {
       fprintf(stderr,"IOError: stl file could not be reopened as ascii ...\n");
@@ -213,7 +214,8 @@ IGL_INLINE bool igl::readSTL(
   }else
   {
     // Binary
-    stl_file = freopen(NULL,"rb",stl_file);
+    //stl_file = freopen(NULL,"rb",stl_file);
+    fseek(stl_file, 0, SEEK_SET);
     // Read 80 header
     char header[80];
     if(fread(header,sizeof(char),80,stl_file)!=80)

+ 1 - 1
include/igl/read_triangle_mesh.cpp

@@ -84,7 +84,7 @@ IGL_INLINE bool igl::read_triangle_mesh(
   pathinfo(filename,dir,base,ext,name);
   // Convert extension to lower case
   transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
-  FILE * fp = fopen(filename.c_str(),"r");
+  FILE * fp = fopen(filename.c_str(),"rb");
   return read_triangle_mesh(ext,fp,V,F);
 }