9#include <ascii-chat/platform/terminal.h>
10#include <ascii-chat/platform/abstraction.h>
11#include <ascii-chat/options/options.h>
12#include <ascii-chat/common.h>
40 if (!buf || count == 0) {
44 size_t written_total = 0;
46 const int MAX_ATTEMPTS = 1000;
48 while (written_total < count && attempts < MAX_ATTEMPTS) {
49 ssize_t result =
platform_write(fd, (
const char *)buf + written_total, count - written_total);
52 written_total += (size_t)result;
54 }
else if (result < 0) {
56 if (errno == EAGAIN || errno == EWOULDBLOCK) {
61 log_warn(
"platform_write_all: write() error on fd=%d (wrote %zu/%zu so far, errno=%d)", fd, written_total,
71 if (attempts >= MAX_ATTEMPTS && written_total < count) {
72 log_warn(
"platform_write_all: Hit retry limit on fd=%d: wrote %zu of %zu bytes", fd, written_total, count);
94 if (GET_OPTION(snapshot_mode)) {
97 const char *testing_env = SAFE_GETENV(
"TESTING");
98 if (testing_env != NULL) {
size_t platform_write_all(int fd, const void *buf, size_t count)
Write all data to file descriptor with automatic retry on transient errors.
bool terminal_should_use_control_sequences(int fd)
Check if terminal control sequences should be used for the given fd.
int platform_isatty(int fd)
ssize_t platform_write(int fd, const void *buf, size_t count)