Skip to content
Snippets Groups Projects
Commit 31cd7d71 authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

[!353] open gmsh file in binary mode

Merge branch 'gmsh_reader_fix' into 'master'

ref:core/dune-grid

-   otherwise on windows it is opened in text mode
    -   ftell/fseek on windows only work correctly on binary files
    -   see e.g.
        [https://stackoverflow.com/questions/47256223/why-does-fseek-0-seek-cur-fail-on-windows]
    -   this makes no difference on posix systems

also: use ftello/fseeko with type off_t instead of ftell/fseek with type long

-   [https://www.gnu.org/software/libc/manual/html_node/File-Positioning.html]
-   "using ftello is preferable whenever it is available"

See merge request [!353]

  [https://stackoverflow.com/questions/47256223/why-does-fseek-0-seek-cur-fail-on-windows]:
    https://stackoverflow.com/questions/47256223/why-does-fseek-0-seek-cur-fail-on-windows
  [https://www.gnu.org/software/libc/manual/html_node/File-Positioning.html]: https://www.gnu.org/software/libc/manual/html_node/File-Positioning.html
  [!353]: gitlab.dune-project.org/core/dune-grid/merge_requests/353
parents 37ada19c 2918f236
No related branches found
No related tags found
1 merge request!353open gmsh file in binary mode
Pipeline #21456 passed
......@@ -366,7 +366,7 @@ namespace Dune
// open file name, we use C I/O
fileName = f;
FILE* file = fopen(fileName.c_str(),"r");
FILE* file = fopen(fileName.c_str(),"rb");
if (file==0)
DUNE_THROW(Dune::IOError, "Could not open " << fileName);
......@@ -441,7 +441,7 @@ namespace Dune
// actually occur as corners of an element.
//=========================================
long section_element_offset = ftell(file);
off_t section_element_offset = ftello(file);
std::map<int,unsigned int> renumber;
for (int i=1; i<=number_of_elements; i++)
{
......@@ -474,7 +474,7 @@ namespace Dune
// Pass 2: Insert boundary segments and elements
//==============================================
fseek(file, section_element_offset, SEEK_SET);
fseeko(file, section_element_offset, SEEK_SET);
boundary_element_count = 0;
element_count = 0;
for (int i=1; i<=number_of_elements; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment