From c6c8f47b432616b1469c6fc7b03246f3f3c08fa2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 11 May 2026 11:37:14 +1000 Subject: [PATCH] util: add a steal_fd() helper function We can't use steal for fds because of the -1 requirement. Assisted-by: Claude:claude-opus-4-6 Part-of: --- src/util-mem.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util-mem.h b/src/util-mem.h index bacc708..7271f6f 100644 --- a/src/util-mem.h +++ b/src/util-mem.h @@ -96,6 +96,21 @@ _steal(void *ptr) #define steal(ptr_) \ (typeof(*ptr_))_steal(ptr_) +/** + * Resets the pointer content to -1 and returns + * the original value. + */ +static inline int +steal_fd(int *ptr) +{ + if (ptr) { + int original = *ptr; + *ptr = -1; + return original; + } + return -1; +} + /** * Never-failing calloc with a size limit check. */