--- /dev/null
+#include <stdio.h>
+#include <stdint.h>
+#include <sd-hwdb.h>
+
+int print_usb_properties(uint16_t vid, uint16_t pid) {
+ char match[15];
+ sd_hwdb *hwdb;
+ const char *key, *value;
+ int r;
+
+ /* Match this USB vendor and product ID combination */
+ snprintf(match, sizeof match, "usb:v%04Xp%04X", vid, pid);
+
+ r = sd_hwdb_new(&hwdb);
+ if (r < 0)
+ return r;
+
+ SD_HWDB_FOREACH_PROPERTY(hwdb, match, key, value)
+ printf("%s: \"%s\" → \"%s\"\n", match, key, value);
+
+ sd_hwdb_unref(hwdb);
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ print_usb_properties(0x046D, 0xC534);
+ return 0;
+}
'3',
['sd_get_machine_names', 'sd_get_sessions', 'sd_get_uids'],
'HAVE_PAM'],
- ['sd_hwdb_get', '3', ['sd_hwdb_enumerate', 'sd_hwdb_seek'], ''],
+ ['sd_hwdb_get',
+ '3',
+ ['SD_HWDB_FOREACH_PROPERTY', 'sd_hwdb_enumerate', 'sd_hwdb_seek'],
+ ''],
['sd_hwdb_new', '3', ['sd_hwdb_ref', 'sd_hwdb_unref'], ''],
['sd_id128_get_machine',
'3',
<refname>sd_hwdb_get</refname>
<refname>sd_hwdb_seek</refname>
<refname>sd_hwdb_enumerate</refname>
+ <refname>SD_HWDB_FOREACH_PROPERTY</refname>
<refpurpose>Seek to a location in hwdb or access entries</refpurpose>
</refnamediv>
<paramdef>const char **<parameter>value</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef><function>SD_HWDB_FOREACH_PROPERTY</function></funcdef>
+ <paramdef>hwdb</paramdef>
+ <paramdef>modalias</paramdef>
+ <paramdef>key</paramdef>
+ <paramdef>value</paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<parameter>modalias</parameter>, the combination of all matching key-value pairs is used. See
<citerefentry><refentrytitle>hwdb</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
details.</para>
+
+ <para>The <function>SD_HWDB_FOREACH_PROPERTY</function> macro combines
+ <function>sd_hwdb_seek()</function> and <function>sd_hwdb_enumerate()</function>. No error handling is
+ performed and interation simply stops on error. See the example below.</para>
</refsect1>
<refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />
+ <refsect1>
+ <title>Examples</title>
+
+ <example>
+ <title>Look up hwdb entries for a USB device</title>
+
+ <programlisting><xi:include href="hwdb-usb-device.c" parse="text" /></programlisting>
+
+ <para>The effect is similar to calling <command>systemd-hwdb query usb:v046DpC534</command>.
+ </para>
+ </example>
+ </refsect1>
+
<refsect1>
<title>See Also</title>