Index · Directives systemd 244


sd_bus_message_read_basic — Read a basic type from a message


#include <systemd/sd-bus.h>
int sd_bus_message_read_basic(sd_bus_message *m,
 char type,
 void *p);


sd_bus_message_read_basic() reads a basic type from a message and advances the read position in the message. The set of basic types and their ascii codes passed in type are described in the D-Bus Specification.

If p is not NULL, it should contain a pointer to an appropriate object. For example, if type is 'y', the object passed in p should have type uint8_t *. If type is 's', the object passed in p should have type const char **. Note that, if the basic type is a pointer (e.g., const char * in the case of a string), the pointer is only borrowed and the contents must be copied if they are to be used after the end of the messages lifetime. Similarly, during the lifetime of such a pointer, the message must not be modified. See the table below for a complete list of allowed types.

Table 1. Item type specifiers

SpecifierConstantDescriptionExpected C Type
"y"SD_BUS_TYPE_BYTEunsigned integeruint8_t *
"b"SD_BUS_TYPE_BOOLEANbooleanint *
"n"SD_BUS_TYPE_INT16signed integerint16_t *
"q"SD_BUS_TYPE_UINT16unsigned integeruint16_t *
"i"SD_BUS_TYPE_INT32signed integerint32_t *
"u"SD_BUS_TYPE_UINT32unsigned integeruint32_t *
"x"SD_BUS_TYPE_INT64signed integerint64_t *
"t"SD_BUS_TYPE_UINT64unsigned integeruint64_t *
"d"SD_BUS_TYPE_DOUBLEfloating-pointdouble *
"s"SD_BUS_TYPE_STRINGUnicode stringconst char **
"o"SD_BUS_TYPE_OBJECT_PATHobject pathconst char **
"g"SD_BUS_TYPE_SIGNATUREsignatureconst char **
"h"SD_BUS_TYPE_UNIX_FDUNIX file descriptorint *

If there is no object of the specified type at the current position in the message, an error is returned.

Return Value

On success, sd_bus_message_read_basic() returns 0 or a positive integer. On failure, it returns a negative errno-style error code.


Returned errors may indicate the following problems:


Specified type string is invalid or the message parameter is NULL.


The message does not contain the specified type at current position.


The message cannot be parsed.

See Also

systemd(1), sd-bus(3), sd_bus_message_append_basic(3), sd_bus_message_skip(3), sd_bus_message_read(3)