diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index c1653bb4..a887483b 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1443,17 +1443,24 @@ template struct span { size_t size; }; -#ifdef _WIN32 -inline void flockfile(FILE* f) { _lock_file(f); } -inline void funlockfile(FILE* f) { _unlock_file(f); } -inline int getc_unlocked(FILE* f) { return _fgetc_nolock(f); } +template auto flockfile(F* f) -> decltype(_lock_file(f)) { + _lock_file(f); +} +template auto funlockfile(F* f) -> decltype(_unlock_file(f)) { + _unlock_file(f); +} + +#ifndef getc_unlocked +template auto getc_unlocked(F* f) -> decltype(_fgetc_nolock(f)) { + return _fgetc_nolock(f); +} #endif template struct has_flockfile : std::false_type {}; template -struct has_flockfile(nullptr)))>> +struct has_flockfile()))>> : std::true_type {}; // A FILE wrapper. F is FILE defined as a template parameter to make system API @@ -1658,7 +1665,8 @@ class file_print_buffer::value>> ~file_print_buffer() { file_.advance_write_buffer(size()); bool flush = file_.needs_flush(); - funlockfile(file_); + F* f = file_; // Make funlockfile depend on the template parameter F + funlockfile(f); // for the system API detection to work. if (flush) fflush(file_); } }; diff --git a/test/scan.h b/test/scan.h index 1f1cda74..baa932bc 100644 --- a/test/scan.h +++ b/test/scan.h @@ -192,7 +192,10 @@ class file_scan_buffer final : public scan_buffer { flockfile(f); fill(); } - ~file_scan_buffer() { funlockfile(file_); } + ~file_scan_buffer() { + FILE* f = file_; + funlockfile(f); + } }; } // namespace detail