1SD_DEVICE_REF(3)                 sd_device_ref                SD_DEVICE_REF(3)
2
3
4

NAME

6       sd_device_ref, sd_device_unref, sd_device_unrefp - Create or destroy
7       references to a device object
8

SYNOPSIS

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           fprintf(stderr, "Failed to allocate device: %s\n", strerror(-r));
40         ...
41       }
42
43       sd_device_ref() and sd_device_unref() execute no operation if the
44       argument is NULL.  sd_device_unrefp() will first dereference its
45       argument, which must not be NULL, and will execute no operation if that
46       is NULL.
47

RETURN VALUE

49       sd_device_ref() always returns the argument, and sd_device_unref()
50       always returns NULL.
51

NOTES

53        1. Clean-up Variable Attribute
54           https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
55
56
57
58systemd 251                                                   SD_DEVICE_REF(3)
Impressum