[email protected] | 8ad97ad | 2013-06-08 06:05:47 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_STRINGS_STRING_UTIL_WIN_H_ |
| 6 | #define BASE_STRINGS_STRING_UTIL_WIN_H_ |
| 7 | |
| 8 | #include <stdarg.h> |
avi | 84f37e1 | 2015-12-25 09:31:42 | [diff] [blame] | 9 | #include <stddef.h> |
[email protected] | 8ad97ad | 2013-06-08 06:05:47 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <wchar.h> |
| 13 | |
| 14 | #include "base/logging.h" |
| 15 | |
| 16 | namespace base { |
| 17 | |
| 18 | // Chromium code style is to not use malloc'd strings; this is only for use |
| 19 | // for interaction with APIs that require it. |
| 20 | inline char* strdup(const char* str) { |
| 21 | return _strdup(str); |
| 22 | } |
| 23 | |
[email protected] | 8ad97ad | 2013-06-08 06:05:47 | [diff] [blame] | 24 | inline int vsnprintf(char* buffer, size_t size, |
| 25 | const char* format, va_list arguments) { |
thakis | c0107ee | 2015-02-06 03:42:14 | [diff] [blame] | 26 | int length = vsnprintf_s(buffer, size, size - 1, format, arguments); |
| 27 | if (length < 0) |
| 28 | return _vscprintf(format, arguments); |
[email protected] | 8ad97ad | 2013-06-08 06:05:47 | [diff] [blame] | 29 | return length; |
| 30 | } |
| 31 | |
| 32 | inline int vswprintf(wchar_t* buffer, size_t size, |
| 33 | const wchar_t* format, va_list arguments) { |
| 34 | DCHECK(IsWprintfFormatPortable(format)); |
| 35 | |
thakis | c0107ee | 2015-02-06 03:42:14 | [diff] [blame] | 36 | int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments); |
| 37 | if (length < 0) |
| 38 | return _vscwprintf(format, arguments); |
[email protected] | 8ad97ad | 2013-06-08 06:05:47 | [diff] [blame] | 39 | return length; |
| 40 | } |
| 41 | |
| 42 | } // namespace base |
| 43 | |
| 44 | #endif // BASE_STRINGS_STRING_UTIL_WIN_H_ |