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