blob: 0367ec4adf02a9b2e851f6f5d78eb2b6e0425ca6 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commitd7cae122008-07-26 21:49:384
[email protected]44cd16f2008-08-14 01:25:325#ifndef BASE_STRING_UTIL_WIN_H_
6#define BASE_STRING_UTIL_WIN_H_
initial.commitd7cae122008-07-26 21:49:387
8#include <stdarg.h>
9#include <stdio.h>
10#include <string.h>
11#include <wchar.h>
12
[email protected]44cd16f2008-08-14 01:25:3213#include "base/logging.h"
14
[email protected]a191e012008-08-07 19:26:3715namespace base {
initial.commitd7cae122008-07-26 21:49:3816
[email protected]157e5d22009-04-23 18:43:3517// Chromium code style is to not use malloc'd strings; this is only for use
18// for interaction with APIs that require it.
19inline char* strdup(const char* str) {
20 return _strdup(str);
21}
22
[email protected]e6142622008-09-24 00:11:2523inline int strcasecmp(const char* s1, const char* s2) {
24 return _stricmp(s1, s2);
25}
26
[email protected]a191e012008-08-07 19:26:3727inline int strncasecmp(const char* s1, const char* s2, size_t count) {
initial.commitd7cae122008-07-26 21:49:3828 return _strnicmp(s1, s2, count);
29}
30
[email protected]a191e012008-08-07 19:26:3731inline int vsnprintf(char* buffer, size_t size,
32 const char* format, va_list arguments) {
initial.commitd7cae122008-07-26 21:49:3833 int length = vsnprintf_s(buffer, size, size - 1, format, arguments);
34 if (length < 0)
35 return _vscprintf(format, arguments);
36 return length;
37}
38
[email protected]a191e012008-08-07 19:26:3739inline int vswprintf(wchar_t* buffer, size_t size,
initial.commitd7cae122008-07-26 21:49:3840 const wchar_t* format, va_list arguments) {
[email protected]44cd16f2008-08-14 01:25:3241 DCHECK(IsWprintfFormatPortable(format));
42
initial.commitd7cae122008-07-26 21:49:3843 int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments);
44 if (length < 0)
45 return _vscwprintf(format, arguments);
46 return length;
47}
48
[email protected]a191e012008-08-07 19:26:3749} // namespace base
50
[email protected]44cd16f2008-08-14 01:25:3251#endif // BASE_STRING_UTIL_WIN_H_