mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-14 18:08:12 +02:00
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: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
This commit is contained in:
parent
4440f15453
commit
c6c8f47b43
1 changed files with 15 additions and 0 deletions
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue