• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "mojo/core/test/test_utils.h"
6 
7 #include <fcntl.h>
8 #include <stddef.h>
9 #include <unistd.h>
10 
11 #include "base/posix/eintr_wrapper.h"
12 
13 namespace mojo {
14 namespace core {
15 namespace test {
16 
PlatformHandleFromFILE(base::ScopedFILE fp)17 PlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) {
18   CHECK(fp);
19   int rv = HANDLE_EINTR(dup(fileno(fp.get())));
20   PCHECK(rv != -1) << "dup";
21   return PlatformHandle(base::ScopedFD(rv));
22 }
23 
FILEFromPlatformHandle(PlatformHandle h,const char * mode)24 base::ScopedFILE FILEFromPlatformHandle(PlatformHandle h, const char* mode) {
25   CHECK(h.is_valid());
26   base::ScopedFILE rv(fdopen(h.ReleaseFD(), mode));
27   PCHECK(rv) << "fdopen";
28   return rv;
29 }
30 
31 }  // namespace test
32 }  // namespace core
33 }  // namespace mojo
34