diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-22 08:46:51 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-23 08:16:38 +0900 |
commit | d6985e76f2c3c40552e310e3e93fca86da5a3e3a (patch) | |
tree | 69573409a40f507a8e761630f3270f68d0ace2f9 /src/basic/alloc-util.h | |
parent | 5eb83e9000413a0d1344476d44596397f57963b0 (diff) | |
download | systemd-d6985e76f2c3c40552e310e3e93fca86da5a3e3a.tar.gz |
sd-device: introduce device_unref_and_replace()
Diffstat (limited to 'src/basic/alloc-util.h')
-rw-r--r-- | src/basic/alloc-util.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index cf4b8b166a..b38db7d473 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -63,6 +63,17 @@ typedef void* (*mfree_func_t)(void *p); #define free_and_replace(a, b) \ free_and_replace_full(a, b, free) +/* This is similar to free_and_replace_full(), but NULL is not assigned to 'b', and its reference counter is + * increased. */ +#define unref_and_replace_full(a, b, ref_func, unref_func) \ + ({ \ + typeof(a)* _a = &(a); \ + typeof(b) _b = ref_func(b); \ + unref_func(*_a); \ + *_a = _b; \ + 0; \ + }) + void* memdup(const void *p, size_t l) _alloc_(2); void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, since we return a buffer one byte larger than the specified size */ |