string_util_posix.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef BASE_STRINGS_STRING_UTIL_POSIX_H_
  5. #define BASE_STRINGS_STRING_UTIL_POSIX_H_
  6. #include <stdarg.h>
  7. #include <stddef.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <wchar.h>
  11. #include "base/check.h"
  12. #include "base/strings/string_piece.h"
  13. namespace base {
  14. // Chromium code style is to not use malloc'd strings; this is only for use
  15. // for interaction with APIs that require it.
  16. inline char* strdup(const char* str) {
  17. return ::strdup(str);
  18. }
  19. inline int vsnprintf(char* buffer, size_t size,
  20. const char* format, va_list arguments) {
  21. return ::vsnprintf(buffer, size, format, arguments);
  22. }
  23. inline int vswprintf(wchar_t* buffer, size_t size,
  24. const wchar_t* format, va_list arguments) {
  25. DCHECK(IsWprintfFormatPortable(format));
  26. return ::vswprintf(buffer, size, format, arguments);
  27. }
  28. // These mirror the APIs in string_util_win.h. Since base::StringPiece is
  29. // already the native string type on POSIX platforms these APIs are simple
  30. // no-ops.
  31. inline StringPiece AsCrossPlatformPiece(StringPiece str) {
  32. return str;
  33. }
  34. inline StringPiece AsNativeStringPiece(StringPiece str) {
  35. return str;
  36. }
  37. } // namespace base
  38. #endif // BASE_STRINGS_STRING_UTIL_POSIX_H_