[llvm] [llvm][Support] Make sys::fs::file_t into a seperate type (PR #160588)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 20 06:27:04 PST 2025
================
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// This file declares llvm::sys::fs::file_t type.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_FILE_H
+#define LLVM_SUPPORT_FILE_H
+
+#include "llvm/Support/Compiler.h"
+
+namespace llvm::sys::fs {
+
+/// This class wraps the platform specific file handle/descriptor type to
+/// provide an unified representation.
+struct file_t {
+#if defined(_WIN32)
+ // A Win32 HANDLE is a typedef of void*
+ using value_type = void *;
+#else
+ // A file descriptor on UNIX.
+ using value_type = int;
+#endif
+ value_type Value;
+
+ LLVM_ABI static const value_type Invalid;
+
+ /// Default constructor to invalid file.
+ file_t() : Value(Invalid) {}
+
+ /// Implicit constructor from underlying value.
+ // TODO: Make this explicit to flush out type mismatches.
+ file_t(value_type Value) : Value(Value) {}
+
+ /// Is a valid file.
+ bool isValid() const { return Value != Invalid; }
+
+ /// Get the underlying value and return a platform specific value.
+ value_type get() const { return Value; }
----------------
aganea wrote:
I know "get" is short, but when doing a textual search there's so many other "get"s; if we made it `get_native` or `native_handle` like `std::thread` it would much easier to pinpoint usages when searching through files.
https://github.com/llvm/llvm-project/pull/160588
More information about the llvm-commits
mailing list