| 1 |
/* SPDX-License-Identifier: MIT-0 */ |
| 2 |
|
| 3 |
#include <errno.h> |
| 4 |
#include <string.h> |
| 5 |
#include <unistd.h> |
| 6 |
#include <systemd/sd-bus.h> |
| 7 |
|
| 8 |
int writer_with_negative_errno_return(int fd, sd_bus_error *error) { |
| 9 |
const char *message = "Hello, World!\n"; |
| 10 |
|
| 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. */ |
| 14 |
|
| 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: %s", fd, strerror(errno)); |
| 18 |
} |