ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
stdout_writer.c
Go to the documentation of this file.
2#include <errno.h>
3
4asciichat_error_t stdout_writer_write(FILE *stream, const void *data,
5 size_t size) {
6 if (!stream || (!data && size))
7 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing output stream or bytes");
8 const unsigned char *bytes = data;
9 size_t offset = 0;
10 while (offset < size) {
11 size_t written = fwrite(bytes + offset, 1, size - offset, stream);
12 offset += written;
13 if (ferror(stream)) {
14 if (errno == EINTR) {
15 clearerr(stream);
16 continue;
17 }
18 return SET_ERRNO_SYS(ERROR_FILE_OPERATION, "Cannot write output stream");
19 }
20 if (!written)
21 return SET_ERRNO(ERROR_FILE_OPERATION, "Output stream made no progress");
22 }
23 while (fflush(stream) != 0) {
24 if (errno != EINTR)
25 return SET_ERRNO_SYS(ERROR_FILE_OPERATION, "Cannot flush output stream");
26 clearerr(stream);
27 }
28 return ASCIICHAT_OK;
29}
#define SET_ERRNO(code,...)
#define SET_ERRNO_SYS(code,...)
Dedicated worker for all pending errno stacks and handled history. Signal handlers may only request a...
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_FILE_OPERATION
@ ERROR_INVALID_PARAM
asciichat_error_t stdout_writer_write(FILE *stream, const void *data, size_t size)