1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef BASE_STRINGS_STRING_UTIL_POSIX_H_ 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define BASE_STRINGS_STRING_UTIL_POSIX_H_ 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <stdarg.h> 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <stdio.h> 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string.h> 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <wchar.h> 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/logging.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace base { 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Chromium code style is to not use malloc'd strings; this is only for use 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// for interaction with APIs that require it. 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline char* strdup(const char* str) { 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::strdup(str); 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline int strcasecmp(const char* string1, const char* string2) { 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::strcasecmp(string1, string2); 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline int strncasecmp(const char* string1, const char* string2, size_t count) { 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::strncasecmp(string1, string2, count); 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline int vsnprintf(char* buffer, size_t size, 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* format, va_list arguments) { 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::vsnprintf(buffer, size, format, arguments); 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline int strncmp16(const char16* s1, const char16* s2, size_t count) { 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(WCHAR_T_IS_UTF16) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::wcsncmp(s1, s2, count); 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#elif defined(WCHAR_T_IS_UTF32) 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return c16memcmp(s1, s2, count); 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline int vswprintf(wchar_t* buffer, size_t size, 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const wchar_t* format, va_list arguments) { 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(IsWprintfFormatPortable(format)); 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ::vswprintf(buffer, size, format, arguments); 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace base 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif // BASE_STRINGS_STRING_UTIL_POSIX_H_ 54