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. */