string_util_win.h (1294B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #ifndef BASE_STRING_UTIL_WIN_H_ 8 #define BASE_STRING_UTIL_WIN_H_ 9 10 #include <stdarg.h> 11 #include <stdio.h> 12 #include <string.h> 13 #include <wchar.h> 14 15 #include "base/logging.h" 16 17 namespace base { 18 19 // Chromium code style is to not use malloc'd strings; this is only for use 20 // for interaction with APIs that require it. 21 inline char* strdup(const char* str) { return _strdup(str); } 22 23 inline int vsnprintf(char* buffer, size_t size, const char* format, 24 va_list arguments) { 25 int length = vsnprintf_s(buffer, size, size - 1, format, arguments); 26 if (length < 0) return _vscprintf(format, arguments); 27 return length; 28 } 29 30 inline int vswprintf(wchar_t* buffer, size_t size, const wchar_t* format, 31 va_list arguments) { 32 DCHECK(IsWprintfFormatPortable(format)); 33 34 int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments); 35 if (length < 0) return _vscwprintf(format, arguments); 36 return length; 37 } 38 39 } // namespace base 40 41 #endif // BASE_STRING_UTIL_WIN_H_