From 1c079e554bdb021ccdab2e47c8cbb05064c973db Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 14 Oct 2020 20:37:29 +0200
Subject: [PATCH] io/UniqueFileDescriptor: add method Release()

---
 src/io/UniqueFileDescriptor.hxx | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/io/UniqueFileDescriptor.hxx b/src/io/UniqueFileDescriptor.hxx
index 0a6c03c8e..a8bbbea3f 100644
--- a/src/io/UniqueFileDescriptor.hxx
+++ b/src/io/UniqueFileDescriptor.hxx
@@ -64,6 +64,14 @@ public:
 		return *this;
 	}
 
+	/**
+	 * Release ownership and return the descriptor as an unmanaged
+	 * #FileDescriptor instance.
+	 */
+	FileDescriptor Release() noexcept {
+		return std::exchange(*(FileDescriptor *)this, Undefined());
+	}
+
 protected:
 	void Set(int _fd) noexcept {
 		assert(!IsDefined());