ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
stdout_writer.h 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.

4 {
5 if (!stream || (!data && size))
6 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing output stream or bytes");
7 const unsigned char *bytes = data;
8 size_t offset = 0;
9 while (offset < size) {
10 size_t written = fwrite(bytes + offset, 1, size - offset, stream);
11 offset += written;
12 if (ferror(stream)) {
13 if (errno == EINTR) {
14 clearerr(stream);
15 continue;
16 }
17 return SET_ERRNO_SYS(ERROR_FILE_OPERATION, "Cannot write output stream");
18 }
19 if (!written)
20 return SET_ERRNO(ERROR_FILE_OPERATION, "Output stream made no progress");
21 }
22 while (fflush(stream) != 0) {
23 if (errno != EINTR)
24 return SET_ERRNO_SYS(ERROR_FILE_OPERATION, "Cannot flush output stream");
25 clearerr(stream);
26 }
27 return ASCIICHAT_OK;
28}
#define SET_ERRNO(code,...)
#define SET_ERRNO_SYS(code,...)
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_FILE_OPERATION
@ ERROR_INVALID_PARAM
#define EINTR
int errno

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

Referenced by kitty_image_write(), and terminal_fd_writer_write().