1SD_DEVICE_REF(3) sd_device_ref SD_DEVICE_REF(3)
2
3
4
6 sd_device_ref, sd_device_unref, sd_device_unrefp - Create or destroy
7 references to a device object
8
10 #include <systemd/sd-device.h>
11
12 sd_device* sd_device_ref(sd_device *device);
13
14 sd_device* sd_device_unref(sd_device *device);
15
16 void sd_device_unrefp(sd_device **device);
17
18 sd_device_ref() increases the internal reference counter of device by
19 one.
20
21 sd_device_unref() decreases the internal reference counter of device by
22 one. Once the reference count has dropped to zero, device is destroyed
23 and cannot be used anymore, so further calls to sd_device_ref() or
24 sd_device_unref() are illegal.
25
26 sd_device_unrefp() is similar to sd_device_unref() but takes a pointer
27 to a pointer to an sd_device object. This call is useful in conjunction
28 with GCC's and LLVM's Clean-up Variable Attribute[1]. Note that this
29 function is defined as an inline function. Use a declaration like the
30 following, in order to allocate a device object that is freed
31 automatically as the code block is left:
32
33 {
34 __attribute__((cleanup(sd_device_unrefp))) sd_device *device = NULL;
35 int r;
36 ...
37 r = sd_device_new_from_syspath(&device, "...");
38 if (r < 0) {
39 errno = -r;
40 fprintf(stderr, "Failed to allocate device: %m\n");
41 }
42 ...
43 }
44
45 sd_device_ref() and sd_device_unref() execute no operation if the
46 argument is NULL. sd_device_unrefp() will first dereference its
47 argument, which must not be NULL, and will execute no operation if that
48 is NULL.
49
51 sd_device_ref() always returns the argument, and sd_device_unref()
52 always returns NULL.
53
55 1. Clean-up Variable Attribute
56 https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
57
58
59
60systemd 254 SD_DEVICE_REF(3)