Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/log/detail/snprintf.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
1 /* | 1 /* |
2 * Copyright Andrey Semashev 2007 - 2013. | 2 * Copyright Andrey Semashev 2007 - 2015. |
3 * Distributed under the Boost Software License, Version 1.0. | 3 * Distributed under the Boost Software License, Version 1.0. |
4 * (See accompanying file LICENSE_1_0.txt or copy at | 4 * (See accompanying file LICENSE_1_0.txt or copy at |
5 * http://www.boost.org/LICENSE_1_0.txt) | 5 * http://www.boost.org/LICENSE_1_0.txt) |
6 */ | 6 */ |
7 /*! | 7 /*! |
46 using ::vswprintf; | 46 using ::vswprintf; |
47 # endif // BOOST_LOG_USE_WCHAR_T | 47 # endif // BOOST_LOG_USE_WCHAR_T |
48 | 48 |
49 #else // !defined(_MSC_VER) | 49 #else // !defined(_MSC_VER) |
50 | 50 |
51 # if _MSC_VER >= 1400 | 51 // MSVC snprintfs are not conforming but they are good enough for our cases |
52 | |
53 // MSVC 2005 and later provide the safe-CRT implementation of the conforming snprintf | |
54 inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args) | 52 inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args) |
55 { | 53 { |
56 return ::vsprintf_s(buf, size, format, args); | 54 int n = _vsnprintf(buf, size, format, args); |
57 } | 55 if (static_cast< unsigned int >(n) >= size) |
58 | 56 { |
59 # ifdef BOOST_LOG_USE_WCHAR_T | 57 n = static_cast< int >(size); |
60 inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args) | 58 buf[size - 1] = '\0'; |
61 { | 59 } |
62 return ::vswprintf_s(buf, size, format, args); | |
63 } | |
64 # endif // BOOST_LOG_USE_WCHAR_T | |
65 | |
66 # else // _MSC_VER >= 1400 | |
67 | |
68 // MSVC prior to 2005 had a non-conforming extension _vsnprintf, that sometimes did not put a terminating '\0' | |
69 inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args) | |
70 { | |
71 register int n = _vsnprintf(buf, size - 1, format, args); | |
72 buf[size - 1] = '\0'; | |
73 return n; | 60 return n; |
74 } | 61 } |
75 | 62 |
76 # ifdef BOOST_LOG_USE_WCHAR_T | 63 # ifdef BOOST_LOG_USE_WCHAR_T |
77 inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args) | 64 inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args) |
78 { | 65 { |
79 register int n = _vsnwprintf(buf, size - 1, format, args); | 66 int n = _vsnwprintf(buf, size, format, args); |
80 buf[size - 1] = L'\0'; | 67 if (static_cast< unsigned int >(n) >= size) |
68 { | |
69 n = static_cast< int >(size); | |
70 buf[size - 1] = L'\0'; | |
71 } | |
81 return n; | 72 return n; |
82 } | 73 } |
83 # endif // BOOST_LOG_USE_WCHAR_T | 74 # endif // BOOST_LOG_USE_WCHAR_T |
84 | |
85 # endif // _MSC_VER >= 1400 | |
86 | 75 |
87 inline int snprintf(char* buf, std::size_t size, const char* format, ...) | 76 inline int snprintf(char* buf, std::size_t size, const char* format, ...) |
88 { | 77 { |
89 std::va_list args; | 78 std::va_list args; |
90 va_start(args, format); | 79 va_start(args, format); |
91 register int n = vsnprintf(buf, size, format, args); | 80 int n = vsnprintf(buf, size, format, args); |
92 va_end(args); | 81 va_end(args); |
93 return n; | 82 return n; |
94 } | 83 } |
95 | 84 |
96 # ifdef BOOST_LOG_USE_WCHAR_T | 85 # ifdef BOOST_LOG_USE_WCHAR_T |
97 inline int swprintf(wchar_t* buf, std::size_t size, const wchar_t* format, ...) | 86 inline int swprintf(wchar_t* buf, std::size_t size, const wchar_t* format, ...) |
98 { | 87 { |
99 std::va_list args; | 88 std::va_list args; |
100 va_start(args, format); | 89 va_start(args, format); |
101 register int n = vswprintf(buf, size, format, args); | 90 int n = vswprintf(buf, size, format, args); |
102 va_end(args); | 91 va_end(args); |
103 return n; | 92 return n; |
104 } | 93 } |
105 # endif // BOOST_LOG_USE_WCHAR_T | 94 # endif // BOOST_LOG_USE_WCHAR_T |
106 | 95 |