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 File Reference

Go to the source code of this file.

Functions

asciichat_error_t stdout_writer_write (FILE *stream, const void *data, size_t size)

Function Documentation

◆ stdout_writer_write()

asciichat_error_t stdout_writer_write ( FILE * stream,
const void * data,
size_t size )

Write exactly size bytes, including embedded NULs, without closing stream.

Definition at line 4 of file stdout_writer.c.

5 {
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,...)
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_FILE_OPERATION
@ ERROR_INVALID_PARAM

References ASCIICHAT_OK, ERROR_FILE_OPERATION, ERROR_INVALID_PARAM, SET_ERRNO, and SET_ERRNO_SYS.

Referenced by kitty_image_write(), and terminal_fd_writer_write().