xref: /aosp_15_r20/external/cronet/base/files/platform_file.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2017 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_FILES_PLATFORM_FILE_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_FILES_PLATFORM_FILE_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include "base/files/scoped_file.h"
9*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h"
10*6777b538SAndroid Build Coastguard Worker 
11*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN)
12*6777b538SAndroid Build Coastguard Worker #include "base/win/scoped_handle.h"
13*6777b538SAndroid Build Coastguard Worker #include "base/win/windows_types.h"
14*6777b538SAndroid Build Coastguard Worker #endif
15*6777b538SAndroid Build Coastguard Worker 
16*6777b538SAndroid Build Coastguard Worker // This file defines platform-independent types for dealing with
17*6777b538SAndroid Build Coastguard Worker // platform-dependent files. If possible, use the higher-level base::File class
18*6777b538SAndroid Build Coastguard Worker // rather than these primitives.
19*6777b538SAndroid Build Coastguard Worker 
20*6777b538SAndroid Build Coastguard Worker namespace base {
21*6777b538SAndroid Build Coastguard Worker 
22*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN)
23*6777b538SAndroid Build Coastguard Worker 
24*6777b538SAndroid Build Coastguard Worker using PlatformFile = HANDLE;
25*6777b538SAndroid Build Coastguard Worker using ScopedPlatformFile = ::base::win::ScopedHandle;
26*6777b538SAndroid Build Coastguard Worker 
27*6777b538SAndroid Build Coastguard Worker // It would be nice to make this constexpr but INVALID_HANDLE_VALUE is a
28*6777b538SAndroid Build Coastguard Worker // ((void*)(-1)) which Clang rejects since reinterpret_cast is technically
29*6777b538SAndroid Build Coastguard Worker // disallowed in constexpr. Visual Studio accepts this, however.
30*6777b538SAndroid Build Coastguard Worker const PlatformFile kInvalidPlatformFile = INVALID_HANDLE_VALUE;
31*6777b538SAndroid Build Coastguard Worker 
32*6777b538SAndroid Build Coastguard Worker #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
33*6777b538SAndroid Build Coastguard Worker 
34*6777b538SAndroid Build Coastguard Worker using PlatformFile = int;
35*6777b538SAndroid Build Coastguard Worker using ScopedPlatformFile = ::base::ScopedFD;
36*6777b538SAndroid Build Coastguard Worker 
37*6777b538SAndroid Build Coastguard Worker constexpr PlatformFile kInvalidPlatformFile = -1;
38*6777b538SAndroid Build Coastguard Worker 
39*6777b538SAndroid Build Coastguard Worker #endif
40*6777b538SAndroid Build Coastguard Worker 
41*6777b538SAndroid Build Coastguard Worker }  // namespace base
42*6777b538SAndroid Build Coastguard Worker 
43*6777b538SAndroid Build Coastguard Worker #endif  // BASE_FILES_PLATFORM_FILE_H_
44