• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // Author: laszlocsomor@google.com (Laszlo Csomor)
9 //  Based on original Protocol Buffers design by
10 //  Sanjay Ghemawat, Jeff Dean, and others.
11 
12 // This file contains the declarations for Windows implementations of
13 // commonly used POSIX functions such as open(2) and access(2), as well
14 // as macro definitions for flags of these functions.
15 //
16 // By including this file you'll redefine open/access/etc. to
17 // ::google::protobuf::io::win32::{open/access/etc.}.
18 // Make sure you don't include a header that attempts to redeclare or
19 // redefine these functions, that'll lead to confusing compilation
20 // errors. It's best to #include this file as the last one to ensure that.
21 //
22 // This file is only used on Windows, it's empty on other platforms.
23 
24 #ifndef GOOGLE_PROTOBUF_IO_IO_WIN32_H__
25 #define GOOGLE_PROTOBUF_IO_IO_WIN32_H__
26 
27 #if defined(_WIN32)
28 
29 #include <functional>
30 #include <string>
31 
32 #include "google/protobuf/port.h"
33 
34 // Must be included last.
35 #include "google/protobuf/port_def.inc"
36 
37 // Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the
38 // following functions already, except for mkdir.
39 namespace google {
40 namespace protobuf {
41 namespace io {
42 namespace win32 {
43 
44 PROTOBUF_EXPORT FILE* fopen(const char* path, const char* mode);
45 PROTOBUF_EXPORT int access(const char* path, int mode);
46 PROTOBUF_EXPORT int chdir(const char* path);
47 PROTOBUF_EXPORT int close(int fd);
48 PROTOBUF_EXPORT int dup(int fd);
49 PROTOBUF_EXPORT int dup2(int fd1, int fd2);
50 PROTOBUF_EXPORT int mkdir(const char* path, int _mode);
51 PROTOBUF_EXPORT int open(const char* path, int flags, int mode = 0);
52 PROTOBUF_EXPORT int read(int fd, void* buffer, size_t size);
53 PROTOBUF_EXPORT int setmode(int fd, int mode);
54 PROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer);
55 PROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size);
56 PROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path);
57 
58 enum class ExpandWildcardsResult {
59   kSuccess = 0,
60   kErrorNoMatchingFile = 1,
61   kErrorInputPathConversion = 2,
62   kErrorOutputPathConversion = 3,
63 };
64 
65 // Expand wildcards in a path pattern, feed the result to a consumer function.
66 //
67 // `path` must be a valid, Windows-style path. It may be absolute, or relative
68 // to the current working directory, and it may contain wildcards ("*" and "?")
69 // in the last path segment. This function passes all matching file names to
70 // `consume`. The resulting paths may not be absolute nor normalized.
71 //
72 // The function returns a value from `ExpandWildcardsResult`.
73 PROTOBUF_EXPORT ExpandWildcardsResult ExpandWildcards(
74     const std::string& path, std::function<void(const std::string&)> consume);
75 
76 namespace strings {
77 
78 // Convert from UTF-16 to Active-Code-Page-encoded or to UTF-8-encoded text.
79 PROTOBUF_EXPORT bool wcs_to_mbs(const wchar_t* s, std::string* out,
80                                 bool outUtf8);
81 
82 // Convert from Active-Code-Page-encoded or UTF-8-encoded text to UTF-16.
83 PROTOBUF_EXPORT bool mbs_to_wcs(const char* s, std::wstring* out, bool inUtf8);
84 
85 // Convert from UTF-8-encoded text to UTF-16.
86 PROTOBUF_EXPORT bool utf8_to_wcs(const char* input, std::wstring* out);
87 
88 // Convert from UTF-16-encoded text to UTF-8.
89 PROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out);
90 
91 }  // namespace strings
92 
93 }  // namespace win32
94 }  // namespace io
95 }  // namespace protobuf
96 }  // namespace google
97 
98 #ifndef W_OK
99 #define W_OK 02  // not defined by MSVC for whatever reason
100 #endif
101 
102 #ifndef F_OK
103 #define F_OK 00  // not defined by MSVC for whatever reason
104 #endif
105 
106 #ifndef STDIN_FILENO
107 #define STDIN_FILENO 0
108 #endif
109 
110 #ifndef STDOUT_FILENO
111 #define STDOUT_FILENO 1
112 #endif
113 
114 #include "google/protobuf/port_undef.inc"
115 
116 #endif  // defined(_WIN32)
117 
118 #endif  // GOOGLE_PROTOBUF_IO_IO_WIN32_H__
119