<?xml version='1.0'?> <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> <!-- SPDX-License-Identifier: LGPL-2.1+ --> <refentry id="sd_bus_message_append_basic" xmlns:xi="http://www.w3.org/2001/XInclude"> <refentryinfo> <title>sd_bus_message_append_basic</title> <productname>systemd</productname> </refentryinfo> <refmeta> <refentrytitle>sd_bus_message_append_basic</refentrytitle> <manvolnum>3</manvolnum> </refmeta> <refnamediv> <refname>sd_bus_message_append_basic</refname> <refpurpose>Attach a single field to a message</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> <funcprototype> <funcdef>int sd_bus_message_append_basic</funcdef> <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> <paramdef>char <parameter>type</parameter></paramdef> <paramdef>const void *<parameter>p</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para><function>sd_bus_message_append_basic()</function> appends a single field to the message <parameter>m</parameter>. The parameter <parameter>type</parameter> determines how the pointer <parameter>p</parameter> is interpreted. <parameter>type</parameter> must be one of the basic types as defined by the <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic Types</ulink> section of the D-Bus specification, and listed in the table below. </para> <table id='format-specifiers'> <title>Item type specifiers</title> <tgroup cols='5'> <colspec colname='specifier' /> <colspec colname='constant' /> <colspec colname='description' /> <colspec colname='size' /> <colspec colname='ctype' /> <thead> <row> <entry>Specifier</entry> <entry>Constant</entry> <entry>Description</entry> <entry>Size</entry> <entry>Expected C Type</entry> </row> </thead> <tbody> <row> <entry><literal>y</literal></entry> <entry><constant>SD_BUS_TYPE_BYTE</constant></entry> <entry>unsigned integer</entry> <entry>1 byte</entry> <entry>uint8_t</entry> </row> <row> <entry><literal>b</literal></entry> <entry><constant>SD_BUS_TYPE_BOOLEAN</constant></entry> <entry>boolean</entry> <entry>4 bytes</entry> <entry>int</entry> </row> <row> <entry><literal>n</literal></entry> <entry><constant>SD_BUS_TYPE_INT16</constant></entry> <entry>signed integer</entry> <entry>2 bytes</entry> <entry>int16_t</entry> </row> <row> <entry><literal>q</literal></entry> <entry><constant>SD_BUS_TYPE_UINT16</constant></entry> <entry>unsigned integer</entry> <entry>2 bytes</entry> <entry>uint16_t</entry> </row> <row> <entry><literal>i</literal></entry> <entry><constant>SD_BUS_TYPE_INT32</constant></entry> <entry>signed integer</entry> <entry>4 bytes</entry> <entry>int32_t</entry> </row> <row> <entry><literal>u</literal></entry> <entry><constant>SD_BUS_TYPE_UINT32</constant></entry> <entry>unsigned integer</entry> <entry>4 bytes</entry> <entry>uint32_t</entry> </row> <row> <entry><literal>x</literal></entry> <entry><constant>SD_BUS_TYPE_INT64</constant></entry> <entry>signed integer</entry> <entry>8 bytes</entry> <entry>int64_t</entry> </row> <row> <entry><literal>t</literal></entry> <entry><constant>SD_BUS_TYPE_UINT64</constant></entry> <entry>unsigned integer</entry> <entry>8 bytes</entry> <entry>uint64_t</entry> </row> <row> <entry><literal>d</literal></entry> <entry><constant>SD_BUS_TYPE_DOUBLE</constant></entry> <entry>floating-point</entry> <entry>8 bytes</entry> <entry>double</entry> </row> <row> <entry><literal>s</literal></entry> <entry><constant>SD_BUS_TYPE_STRING</constant></entry> <entry>Unicode string</entry> <entry>variable</entry> <entry>char[]</entry> </row> <row> <entry><literal>o</literal></entry> <entry><constant>SD_BUS_TYPE_OBJECT_PATH</constant></entry> <entry>object path</entry> <entry>variable</entry> <entry>char[]</entry> </row> <row> <entry><literal>g</literal></entry> <entry><constant>SD_BUS_TYPE_SIGNATURE</constant></entry> <entry>signature</entry> <entry>variable</entry> <entry>char[]</entry> </row> <row> <entry><literal>h</literal></entry> <entry><constant>SD_BUS_TYPE_UNIX_FD</constant></entry> <entry>UNIX file descriptor</entry> <entry>4 bytes</entry> <entry>int</entry> </row> </tbody> </tgroup> </table> <para>The value of the parameter is copied into a memory area held by the message object, stays in the possession of the caller and may hence be freely changed after this call without affecting the bus message it has been added to. If <parameter>type</parameter> is <literal>h</literal> (UNIX file descriptor), the descriptor is duplicated by this call and the passed descriptor stays in possession of the caller.</para> <para>For types <literal>s</literal>, <literal>o</literal>, and <literal>g</literal>, the parameter <parameter>p</parameter> is interpreted as a pointer to a <constant>NUL</constant>-terminated character sequence. As a special case, a <constant>NULL</constant> pointer is interpreted as an empty string. The string should be valid Unicode string encoded as UTF-8. In case of the two latter types, the additional requirements for a D-Bus object path or type signature should be satisfied. Those requirements should be verified by the recipient of the message. </para> </refsect1> <refsect1> <title>Return Value</title> <para>On success, this call returns 0 or a positive integer. On failure, it returns a negative errno-style error code.</para> <refsect2 id='errors'> <title>Errors</title> <para>Returned errors may indicate the following problems:</para> <variablelist> <varlistentry> <term><constant>-EINVAL</constant></term> <listitem><para>Specified parameter is invalid. </para></listitem> </varlistentry> <varlistentry> <term><constant>-EPERM</constant></term> <listitem><para>Message has been sealed. </para></listitem> </varlistentry> <varlistentry> <term><constant>-ESTALE</constant></term> <listitem><para>Message is in invalid state. </para></listitem> </varlistentry> <varlistentry> <term><constant>-ENXIO</constant></term> <listitem><para>Message cannot be appended to. </para></listitem> </varlistentry> <varlistentry> <term><constant>-ENOMEM</constant></term> <listitem><para>Memory allocation failed.</para></listitem> </varlistentry> </variablelist> </refsect2> </refsect1> <xi:include href="libsystemd-pkgconfig.xml" /> <refsect1> <title>See Also</title> <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_message_read_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink> </para> </refsect1> </refentry>