2025-05-17 18:18:57 +05:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2025, the Ladybird developers.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
|
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
|
|
|
|
public:
|
2025-12-04 09:59:18 -05:00
|
|
|
explicit AutoCloseFileDescriptor(int fd);
|
|
|
|
|
~AutoCloseFileDescriptor();
|
2025-05-17 18:18:57 +05:00
|
|
|
|
|
|
|
|
int value() const { return m_fd; }
|
2025-12-04 09:59:18 -05:00
|
|
|
int take_fd() { return exchange(m_fd, -1); }
|
2025-05-17 18:18:57 +05:00
|
|
|
|
|
|
|
|
private:
|
2025-12-04 09:59:18 -05:00
|
|
|
int m_fd { -1 };
|
2025-05-17 18:18:57 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|