diff --git a/include/fmt/os.h b/include/fmt/os.h index 2b517cd4..462ac44d 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -48,6 +48,7 @@ // Calls to system functions are wrapped in FMT_SYSTEM for testability. #ifdef FMT_SYSTEM +# define FMT_HAS_SYSTEM # define FMT_POSIX_CALL(call) FMT_SYSTEM(call) #else # define FMT_SYSTEM(call) ::call diff --git a/src/os.cc b/src/os.cc index bca410e9..a639e78c 100644 --- a/src/os.cc +++ b/src/os.cc @@ -18,8 +18,8 @@ # include # include -# ifdef _WRS_KERNEL // VxWorks7 kernel -# include // getpagesize +# ifdef _WRS_KERNEL // VxWorks7 kernel +# include // getpagesize # endif # ifndef _WIN32 @@ -182,10 +182,14 @@ void buffered_file::close() { } int buffered_file::descriptor() const { -#ifdef fileno // fileno is a macro on OpenBSD so we cannot use FMT_POSIX_CALL. - int fd = fileno(file_); -#else +#if !defined(fileno) int fd = FMT_POSIX_CALL(fileno(file_)); +#elif defined(FMT_HAS_SYSTEM) + // fileno is a macro on OpenBSD so we cannot use FMT_POSIX_CALL. +# define FMT_DISABLE_MACRO + int fd = FMT_SYSTEM(fileno FMT_DISABLE_MACRO(file_)); +#else + int fd = fileno(file_); #endif if (fd == -1) FMT_THROW(system_error(errno, FMT_STRING("cannot get file descriptor")));