basic/linux: update kernel headers from v6.14-rc1
[systemd.io.git] / man / sd_device_ref.xml
blob818edc2fc692c6f4af29199d0e5bda640d789a34
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_device_ref" xmlns:xi="http://www.w3.org/2001/XInclude">
7   <refentryinfo>
8     <title>sd_device_ref</title>
9     <productname>systemd</productname>
10   </refentryinfo>
12   <refmeta>
13     <refentrytitle>sd_device_ref</refentrytitle>
14     <manvolnum>3</manvolnum>
15   </refmeta>
17   <refnamediv>
18     <refname>sd_device_ref</refname>
19     <refname>sd_device_unref</refname>
20     <refname>sd_device_unrefp</refname>
22     <refpurpose>Create or destroy references to a device object</refpurpose>
23   </refnamediv>
25   <refsynopsisdiv>
26     <funcsynopsis>
27       <funcsynopsisinfo>#include &lt;systemd/sd-device.h&gt;</funcsynopsisinfo>
29       <funcprototype>
30         <funcdef>sd_device* <function>sd_device_ref</function></funcdef>
31         <paramdef>sd_device *<parameter>device</parameter></paramdef>
32       </funcprototype>
34       <funcprototype>
35         <funcdef>sd_device* <function>sd_device_unref</function></funcdef>
36         <paramdef>sd_device *<parameter>device</parameter></paramdef>
37       </funcprototype>
39       <funcprototype>
40         <funcdef>void <function>sd_device_unrefp</function></funcdef>
41         <paramdef>sd_device **<parameter>device</parameter></paramdef>
42       </funcprototype>
43     </funcsynopsis>
45     <para><function>sd_device_ref()</function> increases the internal reference counter of
46     <parameter>device</parameter> by one.</para>
48     <para><function>sd_device_unref()</function> decreases the internal reference counter of
49     <parameter>device</parameter> by one. Once the reference count has dropped to zero,
50     <parameter>device</parameter> is destroyed and cannot be used anymore, so further calls to
51     <function>sd_device_ref()</function> or <function>sd_device_unref()</function> are illegal.</para>
53     <para><function>sd_device_unrefp()</function> is similar to <function>sd_device_unref()</function> but
54     takes a pointer to a pointer to an <type>sd_device</type> object. This call is useful in conjunction with
55     GCC's and LLVM's <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
56     Variable Attribute</ulink>. Note that this function is defined as an inline function. Use a declaration
57     like the following, in order to allocate a device object that is freed automatically as the code block is
58     left:</para>
60     <programlisting>{
61   __attribute__((cleanup(sd_device_unrefp))) sd_device *device = NULL;
62   int r;
63   …
64   r = sd_device_new_from_syspath(&amp;device, "…");
65   if (r &lt; 0) {
66     errno = -r;
67     fprintf(stderr, "Failed to allocate device: %m\n");
68   }
69   …
70 }</programlisting>
72     <para><function>sd_device_ref()</function> and <function>sd_device_unref()</function> execute no
73     operation if the argument is <constant>NULL</constant>. <function>sd_device_unrefp()</function> will
74     first dereference its argument, which must not be <constant>NULL</constant>, and will execute no
75     operation if <emphasis>that</emphasis> is <constant>NULL</constant>.</para>
76   </refsynopsisdiv>
78   <refsect1>
79     <title>Return Value</title>
81     <para><function>sd_device_ref()</function> always returns the argument, and
82     <function>sd_device_unref()</function> always returns <constant>NULL</constant>.
83     </para>
84   </refsect1>
85 <refsect1>
86     <title>History</title>
87     <para><function>sd_device_ref()</function>,
88     <function>sd_device_unref()</function>, and
89     <function>sd_device_unrefp()</function> were added in version 251.</para>
90   </refsect1>
91 </refentry>