2020-11-21 21:59:12 +03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2020-11-21 21:59:12 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-21 21:59:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-01-14 09:31:21 +01:00
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
|
#include <AK/StdLibExtras.h>
|
2025-12-04 09:59:18 -05:00
|
|
|
#include <LibCore/Forward.h>
|
2021-01-14 09:31:21 +01:00
|
|
|
|
2020-11-21 21:59:12 +03:00
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
|
class File {
|
2021-01-14 09:31:21 +01:00
|
|
|
AK_MAKE_NONCOPYABLE(File);
|
|
|
|
|
|
2020-11-21 21:59:12 +03:00
|
|
|
public:
|
2021-09-16 00:01:30 -07:00
|
|
|
File() = default;
|
2020-11-21 21:59:12 +03:00
|
|
|
|
2025-12-04 09:59:18 -05:00
|
|
|
static File adopt_file(NonnullOwnPtr<Core::File> file);
|
|
|
|
|
static File adopt_fd(int fd);
|
|
|
|
|
static ErrorOr<File> clone_fd(int fd);
|
2020-11-21 21:59:12 +03:00
|
|
|
|
2025-12-04 09:59:18 -05:00
|
|
|
File(File&& other);
|
|
|
|
|
File& operator=(File&& other);
|
2021-01-14 09:31:21 +01:00
|
|
|
|
2025-12-04 09:59:18 -05:00
|
|
|
~File();
|
2021-01-14 09:31:21 +01:00
|
|
|
|
2020-11-21 21:59:12 +03:00
|
|
|
int fd() const { return m_fd; }
|
|
|
|
|
|
2025-12-04 09:59:18 -05:00
|
|
|
// This is 'const' since generated IPC messages expose all parameters by const reference.
|
|
|
|
|
[[nodiscard]] int take_fd() const { return exchange(m_fd, -1); }
|
2021-01-14 09:31:21 +01:00
|
|
|
|
2025-12-04 09:59:18 -05:00
|
|
|
ErrorOr<void> clear_close_on_exec();
|
2024-06-25 14:57:16 -06:00
|
|
|
|
2020-11-21 21:59:12 +03:00
|
|
|
private:
|
2025-12-04 09:59:18 -05:00
|
|
|
explicit File(int fd);
|
2024-04-16 13:46:30 -06:00
|
|
|
|
2021-01-14 09:31:21 +01:00
|
|
|
mutable int m_fd { -1 };
|
2020-11-21 21:59:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|