OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/test/test_utils.h" | 5 #include "mojo/edk/test/test_utils.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <io.h> | 9 #include <io.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 TRUE)) { | 70 TRUE)) { |
71 *bytes_read = 0; | 71 *bytes_read = 0; |
72 return true; | 72 return true; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 *bytes_read = bytes_read_dword; | 76 *bytes_read = bytes_read_dword; |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) { | 80 embedder::ScopedPlatformHandle PlatformHandleFromFILE(util::ScopedFILE fp) { |
81 CHECK(fp); | 81 CHECK(fp); |
82 | 82 |
83 HANDLE rv = INVALID_HANDLE_VALUE; | 83 HANDLE rv = INVALID_HANDLE_VALUE; |
84 PCHECK(DuplicateHandle( | 84 PCHECK(DuplicateHandle( |
85 GetCurrentProcess(), | 85 GetCurrentProcess(), |
86 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), | 86 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), |
87 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS)) | 87 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS)) |
88 << "DuplicateHandle"; | 88 << "DuplicateHandle"; |
89 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv)); | 89 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv)); |
90 } | 90 } |
91 | 91 |
92 base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, | 92 util::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, |
93 const char* mode) { | 93 const char* mode) { |
94 CHECK(h.is_valid()); | 94 CHECK(h.is_valid()); |
95 // Microsoft's documentation for |_open_osfhandle()| only discusses these | 95 // Microsoft's documentation for |_open_osfhandle()| only discusses these |
96 // flags (and |_O_WTEXT|). Hmmm. | 96 // flags (and |_O_WTEXT|). Hmmm. |
97 int flags = 0; | 97 int flags = 0; |
98 if (strchr(mode, 'a')) | 98 if (strchr(mode, 'a')) |
99 flags |= _O_APPEND; | 99 flags |= _O_APPEND; |
100 if (strchr(mode, 'r')) | 100 if (strchr(mode, 'r')) |
101 flags |= _O_RDONLY; | 101 flags |= _O_RDONLY; |
102 if (strchr(mode, 't')) | 102 if (strchr(mode, 't')) |
103 flags |= _O_TEXT; | 103 flags |= _O_TEXT; |
104 base::ScopedFILE rv(_fdopen( | 104 util::ScopedFILE rv(_fdopen( |
105 _open_osfhandle(reinterpret_cast<intptr_t>(h.release().handle), flags), | 105 _open_osfhandle(reinterpret_cast<intptr_t>(h.release().handle), flags), |
106 mode)); | 106 mode)); |
107 PCHECK(rv) << "_fdopen"; | 107 PCHECK(rv) << "_fdopen"; |
108 return rv.Pass(); | 108 return rv.Pass(); |
109 } | 109 } |
110 | 110 |
111 } // namespace test | 111 } // namespace test |
112 } // namespace mojo | 112 } // namespace mojo |
OLD | NEW |