Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: truncate output files #2203

Closed
BenjiHansell opened this issue Mar 31, 2021 · 1 comment
Closed

Feature request: truncate output files #2203

BenjiHansell opened this issue Mar 31, 2021 · 1 comment

Comments

@BenjiHansell
Copy link

It seems that when I write to an output file which already exists, it is not truncated:

#include <fmt/os.h>

int main() {
  fmt::output_file("/path/to/file").print("AAAAA");
  // file contents is "AAAAA"
  fmt::output_file("/path/to/file").print("BBB");
  // file contents is "BBBAA", but it would be nice if it was "BBB"
}

output_file accepts some config flags, so I can hack around with undocumented FMT macros and get it to work how I want like this:

#include <fmt/os.h>

int main() {
  fmt::output_file("/path/to/file").print("AAAAA");
  // file contents is "AAAAA"
  fmt::output_file("/path/to/file").print("BBB", fmt::file::WRONLY | fmt::file::CREATE | FMT_POSIX(O_TRUNC));
  // file contents is "BBB"
}

Would it be possible to add an fmt::file::TRUNC option?

It might also be worth making that the default. I see no reason why someone would want fmt::file::WRONLY | fmt::file::CREATE (the current default) but be unhappy with fmt::file::WRONLY | fmt::file::CREATE | fmt::file::TRUNC. Although that would be a breaking change.

@vitaut
Copy link
Contributor

vitaut commented Mar 31, 2021

Same as #2018. There is fmt::file::TRUNC already and it is the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants