LLVM 24.0.0git
File.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file declares llvm::sys::fs::file_t type.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_FILE_H
15#define LLVM_SUPPORT_FILE_H
16
17namespace llvm::sys::fs {
18
19/// This class wraps the platform specific file handle/descriptor type to
20/// provide an unified representation.
21struct file_t {
22#if defined(_WIN32)
23 /// A Win32 HANDLE is a typedef of void*
24 using value_type = void *;
25 /// Value for an invalid file handle INVALID_FILE_HANDLE.
26 LLVM_ABI static const value_type Invalid;
27#else
28 /// A file descriptor on UNIX.
29 using value_type = int;
30 /// Value for an invalid file descriptor.
31 static constexpr value_type Invalid = -1;
32#endif
34
35 /// Default constructor to invalid file.
37
38 /// Implicit constructor from underlying value.
39 // TODO: Make this explicit to flush out type mismatches.
41
42 /// Is a valid file.
43 bool isValid() const { return Value != Invalid; }
44
45 /// Get the underlying value and return a platform specific value.
46 value_type get() const { return Value; }
47};
48
50 return LHS.get() == RHS.get();
51}
52
53inline bool operator!=(file_t LHS, file_t RHS) { return !(LHS == RHS); }
54
55} // namespace llvm::sys::fs
56
57#endif
#define LLVM_ABI
Definition Compiler.h:215
Value * RHS
Value * LHS
bool operator==(file_t LHS, file_t RHS)
Definition File.h:49
bool operator!=(file_t LHS, file_t RHS)
Definition File.h:53
int value_type
A file descriptor on UNIX.
Definition File.h:29
static constexpr value_type Invalid
Value for an invalid file descriptor.
Definition File.h:31
file_t()
Default constructor to invalid file.
Definition File.h:36
This class wraps the platform specific file handle/descriptor type to provide an unified representati...
Definition File.h:21
int value_type
A file descriptor on UNIX.
Definition File.h:29
bool isValid() const
Is a valid file.
Definition File.h:43
static constexpr value_type Invalid
Value for an invalid file descriptor.
Definition File.h:31
value_type Value
Definition File.h:33
value_type get() const
Get the underlying value and return a platform specific value.
Definition File.h:46
file_t(value_type Value)
Implicit constructor from underlying value.
Definition File.h:40
file_t()
Default constructor to invalid file.
Definition File.h:36