io_win32.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: laszlocsomor@google.com (Laszlo Csomor)
  31. //
  32. // This file contains the declarations for Windows implementations of
  33. // commonly used POSIX functions such as open(2) and access(2), as well
  34. // as macro definitions for flags of these functions.
  35. //
  36. // By including this file you'll redefine open/access/etc. to
  37. // ::google::protobuf::internal::win32::{open/access/etc.}.
  38. // Make sure you don't include a header that attempts to redeclare or
  39. // redefine these functions, that'll lead to confusing compilation
  40. // errors. It's best to #include this file as the last one to ensure that.
  41. //
  42. // This file is only used on Windows, it's empty on other platforms.
  43. #ifndef GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
  44. #define GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
  45. #if defined(_WIN32)
  46. #include <string>
  47. #include <google/protobuf/stubs/port.h>
  48. // Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the
  49. // following functions already, except for mkdir.
  50. namespace google {
  51. namespace protobuf {
  52. namespace internal {
  53. namespace win32 {
  54. LIBPROTOBUF_EXPORT FILE* fopen(const char* path, const char* mode);
  55. LIBPROTOBUF_EXPORT int access(const char* path, int mode);
  56. LIBPROTOBUF_EXPORT int chdir(const char* path);
  57. LIBPROTOBUF_EXPORT int close(int fd);
  58. LIBPROTOBUF_EXPORT int dup(int fd);
  59. LIBPROTOBUF_EXPORT int dup2(int fd1, int fd2);
  60. LIBPROTOBUF_EXPORT int mkdir(const char* path, int _mode);
  61. LIBPROTOBUF_EXPORT int open(const char* path, int flags, int mode = 0);
  62. LIBPROTOBUF_EXPORT int read(int fd, void* buffer, size_t size);
  63. LIBPROTOBUF_EXPORT int setmode(int fd, int mode);
  64. LIBPROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer);
  65. LIBPROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size);
  66. LIBPROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path);
  67. namespace strings {
  68. // Convert from UTF-16 to Active-Code-Page-encoded or to UTF-8-encoded text.
  69. LIBPROTOBUF_EXPORT bool wcs_to_mbs(
  70. const wchar_t* s, std::string* out, bool outUtf8);
  71. // Convert from Active-Code-Page-encoded or UTF-8-encoded text to UTF-16.
  72. LIBPROTOBUF_EXPORT bool mbs_to_wcs(
  73. const char* s, std::wstring* out, bool inUtf8);
  74. // Convert from UTF-8-encoded text to UTF-16.
  75. LIBPROTOBUF_EXPORT bool utf8_to_wcs(const char* input, std::wstring* out);
  76. // Convert from UTF-16-encoded text to UTF-8.
  77. LIBPROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out);
  78. } // namespace strings
  79. } // namespace win32
  80. } // namespace internal
  81. } // namespace protobuf
  82. } // namespace google
  83. #ifndef W_OK
  84. #define W_OK 02 // not defined by MSVC for whatever reason
  85. #endif
  86. #ifndef F_OK
  87. #define F_OK 00 // not defined by MSVC for whatever reason
  88. #endif
  89. #ifndef STDIN_FILENO
  90. #define STDIN_FILENO 0
  91. #endif
  92. #ifndef STDOUT_FILENO
  93. #define STDOUT_FILENO 1
  94. #endif
  95. #endif // defined(_WIN32)
  96. #endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__