@@ -265,9 +265,10 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
265265 return offset;
266266#else
267267
268- #if defined(sun) || defined(__sun) || defined(_AIX) || \
269- (defined (__NEWLIB__) && !defined (__TM_GMTOFF)) || \
270- (!defined (_BSD_SOURCE) && !defined (_GNU_SOURCE))
268+ #if defined(sun) || defined(__sun) || defined(_AIX) || \
269+ (defined (__NEWLIB__) && !defined (__TM_GMTOFF)) || \
270+ (!defined (__APPLE__) && !defined (_BSD_SOURCE) && !defined (_GNU_SOURCE) && \
271+ (!defined (_POSIX_VERSION) || (_POSIX_VERSION < 202405L )))
271272 // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
272273 struct helper {
273274 static long int calculate_gmt_offset (const std::tm &localtm = details::os::localtime(),
@@ -482,13 +483,12 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
482483 }
483484
484485 // find the size to allocate for the result buffer
485- int result_size =
486- ::MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
486+ int result_size = ::MultiByteToWideChar (CP_UTF8, 0 , str.data (), str_size, NULL , 0 );
487487
488488 if (result_size > 0 ) {
489489 target.resize (result_size);
490- result_size = :: MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, str. data (), str_size,
491- target.data (), result_size);
490+ result_size =
491+ ::MultiByteToWideChar (CP_UTF8, 0 , str.data(), str_size, target.data(), result_size);
492492 if (result_size > 0 ) {
493493 assert (result_size == target.size ());
494494 return ;
@@ -589,6 +589,18 @@ SPDLOG_INLINE bool fsync(FILE *fp) {
589589#endif
590590}
591591
592+ // Do non-locking fwrite if possible by the os or use the regular locking fwrite
593+ // Return true on success.
594+ SPDLOG_INLINE bool fwrite_bytes (const void *ptr, const size_t n_bytes, FILE *fp) {
595+ #if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED)
596+ return _fwrite_nolock (ptr, 1 , n_bytes, fp) == n_bytes;
597+ #elif defined(SPDLOG_FWRITE_UNLOCKED)
598+ return ::fwrite_unlocked (ptr, 1 , n_bytes, fp) == n_bytes;
599+ #else
600+ return std::fwrite (ptr, 1 , n_bytes, fp) == n_bytes;
601+ #endif
602+ }
603+
592604} // namespace os
593605} // namespace details
594606} // namespace spdlog
0 commit comments