2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
9 * \author Andrey Semashev
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
16 #ifndef BOOST_LOG_DETAIL_SNPRINTF_HPP_INCLUDED_
17 #define BOOST_LOG_DETAIL_SNPRINTF_HPP_INCLUDED_
22 #include <boost/log/detail/config.hpp>
23 #ifdef BOOST_LOG_USE_WCHAR_T
25 #endif // BOOST_LOG_USE_WCHAR_T
26 #include <boost/log/detail/header.hpp>
28 #ifdef BOOST_HAS_PRAGMA_ONCE
34 BOOST_LOG_OPEN_NAMESPACE
38 #if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR))
40 // MSVC snprintfs are not conforming but they are good enough for our cases.
41 // MinGW32, at least the older versions up until gcc 4.7, also provide the non-conforming interface.
42 inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args)
44 int n = _vsnprintf(buf, size, format, args);
45 if (static_cast< unsigned int >(n) >= size)
47 n = static_cast< int >(size);
53 # ifdef BOOST_LOG_USE_WCHAR_T
54 inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args)
56 int n = _vsnwprintf(buf, size, format, args);
57 if (static_cast< unsigned int >(n) >= size)
59 n = static_cast< int >(size);
60 buf[size - 1] = L'\0';
64 # endif // BOOST_LOG_USE_WCHAR_T
66 inline int snprintf(char* buf, std::size_t size, const char* format, ...)
69 va_start(args, format);
70 int n = vsnprintf(buf, size, format, args);
75 # ifdef BOOST_LOG_USE_WCHAR_T
76 inline int swprintf(wchar_t* buf, std::size_t size, const wchar_t* format, ...)
79 va_start(args, format);
80 int n = vswprintf(buf, size, format, args);
84 # endif // BOOST_LOG_USE_WCHAR_T
88 // Standard-conforming compilers already have the correct snprintfs
92 # ifdef BOOST_LOG_USE_WCHAR_T
95 # endif // BOOST_LOG_USE_WCHAR_T
101 BOOST_LOG_CLOSE_NAMESPACE // namespace log
105 #include <boost/log/detail/footer.hpp>
107 #endif // BOOST_LOG_DETAIL_SNPRINTF_HPP_INCLUDED_