blob: 95b66b7a18d35747db68b44fcbfffc752fd5bfac [file] [log] [blame]
jcivelli@chromium.org3bab1032011-06-15 04:35:10 +09001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
estade@chromium.org3ac32062009-11-17 07:55:17 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef IPC_IPC_PLATFORM_FILE_H_
6#define IPC_IPC_PLATFORM_FILE_H_
7
8#include "base/basictypes.h"
rvargas@chromium.org9e469f62014-01-28 06:36:00 +09009#include "base/files/file.h"
estade@chromium.org3ac32062009-11-17 07:55:17 +090010#include "base/platform_file.h"
rsesek@chromium.org19319712013-07-24 14:15:24 +090011#include "base/process/process.h"
darin@chromium.org80e4c5e2011-08-16 05:41:46 +090012#include "ipc/ipc_export.h"
estade@chromium.org3ac32062009-11-17 07:55:17 +090013
14#if defined(OS_POSIX)
15#include "base/file_descriptor_posix.h"
16#endif
17
18namespace IPC {
19
20#if defined(OS_WIN)
21typedef base::PlatformFile PlatformFileForTransit;
22#elif defined(OS_POSIX)
23typedef base::FileDescriptor PlatformFileForTransit;
24#endif
25
estade@chromium.orgd9963452009-12-18 09:23:05 +090026inline PlatformFileForTransit InvalidPlatformFileForTransit() {
27#if defined(OS_WIN)
28 return base::kInvalidPlatformFileValue;
29#elif defined(OS_POSIX)
30 return base::FileDescriptor();
31#endif
32}
33
estade@chromium.org3ac32062009-11-17 07:55:17 +090034inline base::PlatformFile PlatformFileForTransitToPlatformFile(
35 const PlatformFileForTransit& transit) {
36#if defined(OS_WIN)
37 return transit;
38#elif defined(OS_POSIX)
39 return transit.fd;
40#endif
41}
42
rvargas@chromium.org5e1b33d2014-03-25 15:01:48 +090043inline base::File PlatformFileForTransitToFile(
44 const PlatformFileForTransit& transit) {
45#if defined(OS_WIN)
46 return base::File(transit);
47#elif defined(OS_POSIX)
48 return base::File(transit.fd);
49#endif
50}
51
jcivelli@chromium.org3bab1032011-06-15 04:35:10 +090052// Returns a file handle equivalent to |file| that can be used in |process|.
darin@chromium.org80e4c5e2011-08-16 05:41:46 +090053IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess(
54 base::PlatformFile file,
55 base::ProcessHandle process,
56 bool close_source_handle);
jcivelli@chromium.org3bab1032011-06-15 04:35:10 +090057
rvargas@chromium.orgf40fe382014-03-06 05:13:49 +090058// Returns a file handle equivalent to |file| that can be used in |process|.
59// Note that this function takes ownership of |file|.
60IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess(
61 base::File file,
62 base::ProcessHandle process);
63
estade@chromium.org3ac32062009-11-17 07:55:17 +090064} // namespace IPC
65
66#endif // IPC_IPC_PLATFORM_FILE_H_