blob: 2a4d3fd1e5a5b3c92973f6aea1842d36b197d0f4 [file] [log] [blame]
[email protected]b9913e72012-03-20 21:22:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// 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]0bedb8a2010-01-14 19:36:3231inline int strncmp16(const char16* s1, const char16* s2, size_t count) {
32 return ::wcsncmp(s1, s2, count);
33}
34
[email protected]a191e012008-08-07 19:26:3735inline int vsnprintf(char* buffer, size_t size,
36 const char* format, va_list arguments) {
[email protected]b9913e72012-03-20 21:22:2337 int length = _vsprintf_p(buffer, size, format, arguments);
38 if (length < 0) {
39 if (size > 0)
40 buffer[0] = 0;
41 return _vscprintf_p(format, arguments);
42 }
initial.commitd7cae122008-07-26 21:49:3843 return length;
44}
45
[email protected]a191e012008-08-07 19:26:3746inline int vswprintf(wchar_t* buffer, size_t size,
initial.commitd7cae122008-07-26 21:49:3847 const wchar_t* format, va_list arguments) {
[email protected]44cd16f2008-08-14 01:25:3248 DCHECK(IsWprintfFormatPortable(format));
49
[email protected]b9913e72012-03-20 21:22:2350 int length = _vswprintf_p(buffer, size, format, arguments);
51 if (length < 0) {
52 if (size > 0)
53 buffer[0] = 0;
54 return _vscwprintf_p(format, arguments);
55 }
initial.commitd7cae122008-07-26 21:49:3856 return length;
57}
58
[email protected]a191e012008-08-07 19:26:3759} // namespace base
60
[email protected]44cd16f2008-08-14 01:25:3261#endif // BASE_STRING_UTIL_WIN_H_