Skip to content

Instantly share code, notes, and snippets.

@zachhilman
Created July 20, 2018 20:57
Show Gist options
  • Save zachhilman/5fc076ef4559aab4c7398455877e94c7 to your computer and use it in GitHub Desktop.
Save zachhilman/5fc076ef4559aab4c7398455877e94c7 to your computer and use it in GitHub Desktop.
std::string mode_str;
u32 mode_flags = static_cast<u32>(mode);
// Calculate the correct open mode for the file.
if ((mode_flags & static_cast<u32>(Mode::Read)) &&
(mode_flags & static_cast<u32>(Mode::Write))) {
if (mode_flags & static_cast<u32>(Mode::Append))
mode_str = "a+";
else
mode_str = "r+";
} else {
if (mode_flags & static_cast<u32>(Mode::Read))
mode_str = "r";
else if (mode_flags & static_cast<u32>(Mode::Append))
mode_str = "a";
else if (mode_flags & static_cast<u32>(Mode::Write))
mode_str = "w";
}
mode_str += "b";
return mode_str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment