1:255.13-alt1
[systemd_ALT.git] / man / sd_bus_error-example.c
blob4b5217c433bd6a73c86637b43933c2a41acaeb0d
1 /* SPDX-License-Identifier: MIT-0 */
3 #include <errno.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <systemd/sd-bus.h>
8 int writer_with_negative_errno_return(int fd, sd_bus_error *error) {
9 const char *message = "Hello, World!\n";
11 ssize_t n = write(fd, message, strlen(message));
12 if (n >= 0)
13 return n; /* On success, return the number of bytes written, possibly 0. */
15 /* On error, initialize the error structure, and also propagate the errno
16 * value that write(2) set for us. */
17 return sd_bus_error_set_errnof(error, errno, "Failed to write to fd %i: %m", fd);