Skip to content

Commit

Permalink
Merge pull request #1005 from ros/fix_open_mode_on_windows
Browse files Browse the repository at this point in the history
fix open mode on Windows
  • Loading branch information
dirk-thomas authored Feb 28, 2017
2 parents 1246727 + 774b0b4 commit e014400
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/rosbag_storage/src/chunked_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,24 @@ void ChunkedFile::open(string const& filename, string const& mode) {

// Open the file
if (mode == "r+b") {
// Read + write requires file to exists. Create a new file if it doesn't exist.
// check if file already exists
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
fopen_s( &file_, filename.c_str(), "r" );
#else
file_ = fopen(filename.c_str(), "r");
#endif
if (file_ == NULL)
// create an empty file and open it for update
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
fopen_s( &file_, filename.c_str(), "w+b" );
#else
file_ = fopen(filename.c_str(), "w+b");
#endif
else {
fclose(file_);
// open existing file for update
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
fopen_s( &file_, filename.c_str(), "w+b" );
fopen_s( &file_, filename.c_str(), "r+b" );
#else
file_ = fopen(filename.c_str(), "r+b");
#endif
Expand Down

0 comments on commit e014400

Please sign in to comment.