| 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 <stddef.h> | 10 #include <stddef.h> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 *bytes_read = bytes_read_dword; | 78 *bytes_read = bytes_read_dword; |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) { | 82 ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) { |
| 83 CHECK(fp); | 83 CHECK(fp); |
| 84 | 84 |
| 85 HANDLE rv = INVALID_HANDLE_VALUE; | 85 HANDLE rv = INVALID_HANDLE_VALUE; |
| 86 PCHECK(DuplicateHandle( | 86 // DuplicateHandle |
| 87 CHECK(DuplicateHandle( |
| 87 GetCurrentProcess(), | 88 GetCurrentProcess(), |
| 88 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), | 89 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), |
| 89 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS)) | 90 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS)); |
| 90 << "DuplicateHandle"; | |
| 91 return ScopedPlatformHandle(PlatformHandle(rv)); | 91 return ScopedPlatformHandle(PlatformHandle(rv)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 base::ScopedFILE FILEFromPlatformHandle(ScopedPlatformHandle h, | 94 base::ScopedFILE FILEFromPlatformHandle(ScopedPlatformHandle h, |
| 95 const char* mode) { | 95 const char* mode) { |
| 96 CHECK(h.is_valid()); | 96 CHECK(h.is_valid()); |
| 97 // Microsoft's documentation for |_open_osfhandle()| only discusses these | 97 // Microsoft's documentation for |_open_osfhandle()| only discusses these |
| 98 // flags (and |_O_WTEXT|). Hmmm. | 98 // flags (and |_O_WTEXT|). Hmmm. |
| 99 int flags = 0; | 99 int flags = 0; |
| 100 if (strchr(mode, 'a')) | 100 if (strchr(mode, 'a')) |
| 101 flags |= _O_APPEND; | 101 flags |= _O_APPEND; |
| 102 if (strchr(mode, 'r')) | 102 if (strchr(mode, 'r')) |
| 103 flags |= _O_RDONLY; | 103 flags |= _O_RDONLY; |
| 104 if (strchr(mode, 't')) | 104 if (strchr(mode, 't')) |
| 105 flags |= _O_TEXT; | 105 flags |= _O_TEXT; |
| 106 base::ScopedFILE rv(_fdopen( | 106 base::ScopedFILE rv(_fdopen( |
| 107 _open_osfhandle(reinterpret_cast<intptr_t>(h.release().handle), flags), | 107 _open_osfhandle(reinterpret_cast<intptr_t>(h.release().handle), flags), |
| 108 mode)); | 108 mode)); |
| 109 PCHECK(rv) << "_fdopen"; | 109 // _fdopen |
| 110 CHECK(rv); |
| 110 return rv; | 111 return rv; |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace test | 114 } // namespace test |
| 114 } // namespace edk | 115 } // namespace edk |
| 115 } // namespace mojo | 116 } // namespace mojo |
| OLD | NEW |