From 2a1a7910f9af6ec1ce0e5e6e8f271e3ea89b9d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 12 Apr 2022 11:51:52 +0200 Subject: man: add page for sd_device_{ref,unref,unrefp} Gotta start somewhere. --- man/sd_device_ref.xml | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 man/sd_device_ref.xml (limited to 'man/sd_device_ref.xml') diff --git a/man/sd_device_ref.xml b/man/sd_device_ref.xml new file mode 100644 index 0000000000..b7ed4d985c --- /dev/null +++ b/man/sd_device_ref.xml @@ -0,0 +1,83 @@ + + + + + + + sd_device_ref + systemd + + + + sd_device_ref + 3 + + + + sd_device_ref + sd_device_unref + sd_device_unrefp + + Create or destroy references to a device object + + + + + #include <systemd/sd-device.h> + + + sd_device* sd_device_ref + sd_device *device + + + + sd_device* sd_device_unref + sd_device *device + + + + void sd_device_unrefp + sd_device **device + + + + sd_device_ref() increases the reference counter of + device by one. + + sd_device_unref() decreases the reference counter of + device by one. Once the reference count has dropped to zero, + device is destroyed and cannot be used anymore, so further calls to + sd_device_ref() or sd_device_unref() are illegal. + + sd_device_unrefp() is similar to sd_device_unref() but + takes a pointer to a pointer to an sd_device object. This call is useful in conjunction with + GCC's and LLVM's Clean-up + Variable Attribute. Note that this function is defined as an inline function. Use a declaration + like the following, in order to allocate a device object that is freed automatically as the code block is + left: + + { + __attribute__((cleanup(sd_device_unrefp))) sd_device *device = NULL; + int r; + … + r = sd_device_new_from_syspath(&device, "…"); + if (r < 0) + fprintf(stderr, "Failed to allocate device: %s\n", strerror(-r)); + … +} + + sd_device_ref() and sd_device_unref() execute no + operation if the argument is NULL. sd_device_unrefp() will + first dereference its argument, which must not be NULL, and will execute no + operation if that is NULL. + + + + Return Value + + sd_device_ref() always returns the argument, and + sd_device_unref() always returns NULL. + + + -- cgit v1.2.1