| 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 |
|
| 31 |
// Author: [email protected] (Laszlo Csomor) |
| 32 |
// Based on original Protocol Buffers design by |
| 33 |
// Sanjay Ghemawat, Jeff Dean, and others. |
| 34 |
|
| 35 |
// This file contains the declarations for Windows implementations of |
| 36 |
// commonly used POSIX functions such as open(2) and access(2), as well |
| 37 |
// as macro definitions for flags of these functions. |
| 38 |
// |
| 39 |
// By including this file you'll redefine open/access/etc. to |
| 40 |
// ::google::protobuf::io::win32::{open/access/etc.}. |
| 41 |
// Make sure you don't include a header that attempts to redeclare or |
| 42 |
// redefine these functions, that'll lead to confusing compilation |
| 43 |
// errors. It's best to #include this file as the last one to ensure that. |
| 44 |
// |
| 45 |
// This file is only used on Windows, it's empty on other platforms. |
| 46 |
|
| 47 |
#ifndef GOOGLE_PROTOBUF_IO_IO_WIN32_H__ |
| 48 |
#define GOOGLE_PROTOBUF_IO_IO_WIN32_H__ |
| 49 |
|
| 50 |
#if defined(_WIN32) |
| 51 |
|
| 52 |
#include <functional> |
| 53 |
#include <string> |
| 54 |
|
| 55 |
#include <google/protobuf/port.h> |
| 56 |
#include <google/protobuf/port_def.inc> |
| 57 |
|
| 58 |
// Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the |
| 59 |
// following functions already, except for mkdir. |
| 60 |
namespace google { |
| 61 |
namespace protobuf { |
| 62 |
namespace io { |
| 63 |
namespace win32 { |
| 64 |
|
| 65 |
PROTOBUF_EXPORT FILE* fopen(const char* path, const char* mode); |
| 66 |
PROTOBUF_EXPORT int access(const char* path, int mode); |
| 67 |
PROTOBUF_EXPORT int chdir(const char* path); |
| 68 |
PROTOBUF_EXPORT int close(int fd); |
| 69 |
PROTOBUF_EXPORT int dup(int fd); |
| 70 |
PROTOBUF_EXPORT int dup2(int fd1, int fd2); |
| 71 |
PROTOBUF_EXPORT int mkdir(const char* path, int _mode); |
| 72 |
PROTOBUF_EXPORT int open(const char* path, int flags, int mode = 0); |
| 73 |
PROTOBUF_EXPORT int read(int fd, void* buffer, size_t size); |
| 74 |
PROTOBUF_EXPORT int setmode(int fd, int mode); |
| 75 |
PROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer); |
| 76 |
PROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size); |
| 77 |
PROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path); |
| 78 |
|
| 79 |
enum class ExpandWildcardsResult { |
| 80 |
kSuccess = 0, |
| 81 |
kErrorNoMatchingFile = 1, |
| 82 |
kErrorInputPathConversion = 2, |
| 83 |
kErrorOutputPathConversion = 3, |
| 84 |
}; |
| 85 |
|
| 86 |
// Expand wildcards in a path pattern, feed the result to a consumer function. |
| 87 |
// |
| 88 |
// `path` must be a valid, Windows-style path. It may be absolute, or relative |
| 89 |
// to the current working directory, and it may contain wildcards ("*" and "?") |
| 90 |
// in the last path segment. This function passes all matching file names to |
| 91 |
// `consume`. The resulting paths may not be absolute nor normalized. |
| 92 |
// |
| 93 |
// The function returns a value from `ExpandWildcardsResult`. |
| 94 |
PROTOBUF_EXPORT ExpandWildcardsResult ExpandWildcards( |
| 95 |
const std::string& path, std::function<void(const std::string&)> consume); |
| 96 |
|
| 97 |
namespace strings { |
| 98 |
|
| 99 |
// Convert from UTF-16 to Active-Code-Page-encoded or to UTF-8-encoded text. |
| 100 |
PROTOBUF_EXPORT bool wcs_to_mbs(const wchar_t* s, std::string* out, |
| 101 |
bool outUtf8); |
| 102 |
|
| 103 |
// Convert from Active-Code-Page-encoded or UTF-8-encoded text to UTF-16. |
| 104 |
PROTOBUF_EXPORT bool mbs_to_wcs(const char* s, std::wstring* out, bool inUtf8); |
| 105 |
|
| 106 |
// Convert from UTF-8-encoded text to UTF-16. |
| 107 |
PROTOBUF_EXPORT bool utf8_to_wcs(const char* input, std::wstring* out); |
| 108 |
|
| 109 |
// Convert from UTF-16-encoded text to UTF-8. |
| 110 |
PROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out); |
| 111 |
|
| 112 |
} // namespace strings |
| 113 |
|
| 114 |
} // namespace win32 |
| 115 |
} // namespace io |
| 116 |
} // namespace protobuf |
| 117 |
} // namespace google |
| 118 |
|
| 119 |
#ifndef W_OK |
| 120 |
#define W_OK 02 // not defined by MSVC for whatever reason |
| 121 |
#endif |
| 122 |
|
| 123 |
#ifndef F_OK |
| 124 |
#define F_OK 00 // not defined by MSVC for whatever reason |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifndef STDIN_FILENO |
| 128 |
#define STDIN_FILENO 0 |
| 129 |
#endif |
| 130 |
|
| 131 |
#ifndef STDOUT_FILENO |
| 132 |
#define STDOUT_FILENO 1 |
| 133 |
#endif |
| 134 |
|
| 135 |
#include <google/protobuf/port_undef.inc> |
| 136 |
|
| 137 |
#endif // defined(_WIN32) |
| 138 |
|
| 139 |
#endif // GOOGLE_PROTOBUF_IO_IO_WIN32_H__ |