| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QUNIQUEHANDLE_TYPES_P_H |
| 5 | #define QUNIQUEHANDLE_TYPES_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qnamespace.h> |
| 19 | #include <QtCore/private/quniquehandle_p.h> |
| 20 | |
| 21 | #include <cstdio> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | namespace QtUniqueHandleTraits { |
| 26 | |
| 27 | #ifdef Q_OS_WIN |
| 28 | |
| 29 | struct InvalidHandleTraits |
| 30 | { |
| 31 | using Type = Qt::HANDLE; |
| 32 | static Type invalidValue() noexcept |
| 33 | { |
| 34 | return Qt::HANDLE(-1); // AKA INVALID_HANDLE_VALUE |
| 35 | } |
| 36 | Q_CORE_EXPORT static bool close(Type handle) noexcept; |
| 37 | }; |
| 38 | |
| 39 | struct NullHandleTraits |
| 40 | { |
| 41 | using Type = Qt::HANDLE; |
| 42 | static Type invalidValue() noexcept { return nullptr; } |
| 43 | Q_CORE_EXPORT static bool close(Type handle) noexcept; |
| 44 | }; |
| 45 | |
| 46 | #endif |
| 47 | |
| 48 | struct FileDescriptorHandleTraits |
| 49 | { |
| 50 | using Type = int; |
| 51 | static constexpr Type invalidValue() noexcept { return -1; } |
| 52 | Q_CORE_EXPORT static bool close(Type handle); |
| 53 | }; |
| 54 | |
| 55 | struct FILEHandleTraits |
| 56 | { |
| 57 | using Type = FILE *; |
| 58 | static constexpr Type invalidValue() noexcept { return nullptr; } |
| 59 | Q_CORE_EXPORT static bool close(Type handle); |
| 60 | }; |
| 61 | |
| 62 | } // namespace QtUniqueHandleTraits |
| 63 | |
| 64 | #ifdef Q_OS_WIN |
| 65 | |
| 66 | using QUniqueWin32Handle = QUniqueHandle<QtUniqueHandleTraits::InvalidHandleTraits>; |
| 67 | using QUniqueWin32NullHandle = QUniqueHandle<QtUniqueHandleTraits::NullHandleTraits>; |
| 68 | |
| 69 | #endif |
| 70 | |
| 71 | #ifdef Q_OS_UNIX |
| 72 | |
| 73 | using QUniqueFileDescriptorHandle = QUniqueHandle<QtUniqueHandleTraits::FileDescriptorHandleTraits>; |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | using QUniqueFILEHandle = QUniqueHandle<QtUniqueHandleTraits::FILEHandleTraits>; |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 | |
| 81 | #endif |
| 82 | |