forked from drath/libratbag
Move the _cleanup_ functions over to shared-macro.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
8209ce56b6
commit
9450d1402f
@@ -1405,7 +1405,7 @@ ratbag_find_hidraw_node(struct ratbag_device *device,
|
||||
udev_enumerate_add_match_parent(e, parent_udev);
|
||||
udev_enumerate_scan_devices(e);
|
||||
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *udev_device = NULL;
|
||||
|
||||
path = udev_list_entry_get_name(entry);
|
||||
udev_device = udev_device_new_from_syspath(udev, path);
|
||||
|
||||
@@ -59,32 +59,6 @@ int list_empty(const struct list *list);
|
||||
pos = tmp, \
|
||||
tmp = container_of(pos->member.next, tmp, member))
|
||||
|
||||
static inline void
|
||||
cleanup_free(void *p) {
|
||||
free(*(void**)p);
|
||||
}
|
||||
|
||||
static inline void
|
||||
cleanup_close(int *p) {
|
||||
close(*p);
|
||||
}
|
||||
static inline void
|
||||
cleanup_udev_unref(struct udev **udev) {
|
||||
if (*udev)
|
||||
udev_unref(*udev);
|
||||
}
|
||||
|
||||
static inline void
|
||||
cleanup_udev_device_unref(struct udev_device **udev_device) {
|
||||
if (*udev_device)
|
||||
udev_device_unref(*udev_device);
|
||||
}
|
||||
|
||||
#define _cleanup_free_ _cleanup_(cleanup_free)
|
||||
#define _cleanup_close_ _cleanup_(cleanup_close)
|
||||
#define _cleanup_udev_unref_ _cleanup_(cleanup_udev_unref)
|
||||
#define _cleanup_udev_device_unref_ _cleanup_(cleanup_udev_device_unref)
|
||||
|
||||
static inline char*
|
||||
strncpy_safe(char *dest, const char *src, size_t n)
|
||||
{
|
||||
|
||||
@@ -118,6 +118,8 @@ static inline void reset_errno(int *saved_errno)
|
||||
}
|
||||
#define PROTECT_ERRNO _cleanup_(reset_errno) _unused_ int saved_errno = errno
|
||||
|
||||
#define _cleanup_free_ _cleanup_(freep)
|
||||
#define _cleanup_close_ _cleanup_(safe_closep)
|
||||
/*
|
||||
* DEFINE_TRIVIAL_CLEANUP_FUNC() - define helper suitable for _cleanup_()
|
||||
* @_type: type of object to cleanup
|
||||
@@ -131,6 +133,9 @@ static inline void reset_errno(int *saved_errno)
|
||||
} \
|
||||
struct __useless_struct_to_allow_trailing_semicolon__
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
|
||||
|
||||
/*
|
||||
* ELEMENTSOF() - number of array elements
|
||||
* @_array: C array
|
||||
|
||||
@@ -283,8 +283,8 @@ struct ratbag_device *
|
||||
ratbag_cmd_open_device(struct ratbag *ratbag, const char *path)
|
||||
{
|
||||
struct ratbag_device *device;
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
_cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
|
||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *udev_device = NULL;
|
||||
enum ratbag_error_code error;
|
||||
|
||||
udev = udev_new();
|
||||
|
||||
Reference in New Issue
Block a user