Debian Codegraph @

man/sd_device_enumerator_new.xml

raw
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 -->
5
6 <refentry id="sd_device_enumerator_new" xmlns:xi="http://www.w3.org/2001/XInclude">
7 <refentryinfo>
8 <title>sd_device_enumerator_new</title>
9 <productname>systemd</productname>
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>sd_device_enumerator_new</refentrytitle>
14 <manvolnum>3</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>sd_device_enumerator_new</refname>
19 <refname>sd_device_enumerator_ref</refname>
20 <refname>sd_device_enumerator_unref</refname>
21 <refname>sd_device_enumerator_unrefp</refname>
22 <refpurpose>Create, reference, and release a device enumerator object</refpurpose>
23 </refnamediv>
24
25 <refsynopsisdiv>
26 <funcsynopsis>
27 <funcsynopsisinfo>#include &lt;systemd/sd-device.h&gt;</funcsynopsisinfo>
28
29 <funcprototype>
30 <funcdef>int <function>sd_device_enumerator_new</function></funcdef>
31 <paramdef>sd_device_enumerator **<parameter>ret</parameter></paramdef>
32 </funcprototype>
33
34 <funcprototype>
35 <funcdef>sd_device_enumerator* <function>sd_device_enumerator_ref</function></funcdef>
36 <paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef>
37 </funcprototype>
38
39 <funcprototype>
40 <funcdef>sd_device_enumerator* <function>sd_device_enumerator_unref</function></funcdef>
41 <paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef>
42 </funcprototype>
43
44 <funcprototype>
45 <funcdef>void <function>sd_device_enumerator_unrefp</function></funcdef>
46 <paramdef>sd_device_enumerator **<parameter>enumerator</parameter></paramdef>
47 </funcprototype>
48 </funcsynopsis>
49 </refsynopsisdiv>
50
51 <refsect1>
52 <title>Description</title>
53 <para>The <function>sd_device_enumerator</function> family of functions provides a way to iterate
54 over devices recognized by <citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum>
55 </citerefentry>. The enumerator allows filtering and matching devices by subsystem, properties and
56 other attributes.</para>
57
58 <para><function>sd_device_enumerator_new()</function> creates a new device enumerator object and
59 stores the result in the pointer referenced by <parameter>ret</parameter>. Returns 0 on success,
60 or a negative errno-style error code on failure.</para>
61
62 <para><function>sd_device_enumerator_ref()</function> increases the reference count of the
63 specified <parameter>enumerator</parameter> by one.</para>
64
65 <para><function>sd_device_enumerator_unref()</function> decreases the reference count of the
66 <parameter>enumerator</parameter> by one. When the reference count reaches zero, the enumerator
67 object is destroyed and cannot be used anymore, so further calls to <function>sd_device_enumerator_unref()
68 </function> or <function>sd_device_enumerator_unrefp()</function> are illegal.</para>
69
70 <para><function>sd_device_enumerator_unrefp()</function> is similar to
71 <function>sd_device_enumerator_unref()</function> but takes a pointer to a
72 pointer to an <type>sd_device_enumerator</type> object. This call is useful in
73 conjunction with GCC's and LLVM's <ulink
74 url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
75 Variable Attribute</ulink>. Note that this function is defined as an
76 inline function. Use a declaration like the following, in order to
77 allocate a <type>sd_device_enumerator</type> object that is freed automatically as the code
78 block is left:</para>
79
80 <programlisting>{
81 __attribute__((cleanup(sd_device_enumerator_unrefp))) sd_device_enumerator *enumerator = NULL;
82 int r;
83 …
84 r = sd_device_enumerator_new(&amp;enumerator);
85 if (r &lt; 0)
86 fprintf(stderr, "Failed to allocate sd_device_enumerator: %s\n", strerror(-r));
87 …
88 }</programlisting>
89
90 <para><function>sd_device_enumerator_ref()</function> and <function>sd_device_enumerator_unref()</function>
91 execute no operation if the <parameter>enumerator</parameter> is <constant>NULL</constant>.
92 <function>sd_device_enumerator_unrefp()</function> will first dereference
93 its argument, which must not be <constant>NULL</constant>, and will execute no operation if
94 <emphasis>that</emphasis> is <constant>NULL</constant>.</para>
95 </refsect1>
96
97 <refsect1>
98 <title>Return Value</title>
99
100 <para><function>sd_device_enumerator_new()</function> returns 0 on success or a negative
101 errno-style error code on failure.</para>
102
103 <para><function>sd_device_enumerator_ref()</function> always returns the enumerator pointer.</para>
104 <para><function>sd_device_enumerator_unref()</function> always returns <constant>NULL</constant>.</para>
105
106 <refsect2>
107 <title>Errors</title>
108
109 <para>Returned errors may indicate the following problems:</para>
110
111 <variablelist>
112 <varlistentry>
113 <term><constant>-ENOMEM</constant></term>
114
115 <listitem><para>Memory allocation failed.</para></listitem>
116 </varlistentry>
117 <varlistentry>
118 <term><constant>-EINVAL</constant></term>
119
120 <listitem><para>The argument is invalid.</para></listitem>
121 </varlistentry>
122 </variablelist>
123 </refsect2>
124 </refsect1>
125
126 <refsect1>
127 <title>Example</title>
128 <example>
129 <title>Using sd_device_enumerator_new()</title>
130 <programlisting><xi:include href="sd_device_enumerator_new-example.c" parse="text"/></programlisting>
131 </example>
132 </refsect1>
133
134 <refsect1>
135 <title>History</title>
136 <para><function>sd_device_enumerator_new()</function>, <function>sd_device_enumerator_ref()</function>,
137 <function>sd_device_enumerator_unref()</function>, and <function>sd_device_enumerator_unrefp()</function>
138 were added in version 240.</para>
139 </refsect1>
140
141 <refsect1>
142 <title>See Also</title>
143 <para><simplelist type="inline">
144 <member><citerefentry><refentrytitle>sd_device_ref</refentrytitle><manvolnum>3</manvolnum>
145 </citerefentry></member>
146 <member><citerefentry><refentrytitle>sd_device_enumerator_add_match_parent</refentrytitle>
147 <manvolnum>3</manvolnum></citerefentry></member>
148 </simplelist></para>
149 </refsect1>
150
151 </refentry>