diff options
author | Mia Herkt <mia@0x0.st> | 2022-12-20 10:45:36 +0100 |
---|---|---|
committer | Mia Herkt <mia@0x0.st> | 2022-12-20 10:45:36 +0100 |
commit | 56f0ba22f13cf94efad1ee6c41ad48ae24f9ff14 (patch) | |
tree | ed03e466be4ed53e5bf84e5bc98fafc1996d42e0 /video | |
parent | 125fd4c2f962ddd68cde54445c1437fbe29c36b2 (diff) | |
download | mpv-56f0ba22f13cf94efad1ee6c41ad48ae24f9ff14.tar.bz2 mpv-56f0ba22f13cf94efad1ee6c41ad48ae24f9ff14.tar.xz |
vo_sixel: Implement write() loop
Not all systems are Linux. Also update the comment to better reflect
POSIX documentation.
Diffstat (limited to 'video')
-rw-r--r-- | video/out/vo_sixel.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/video/out/vo_sixel.c b/video/out/vo_sixel.c index 6c4b0d7466..77eeb571e6 100644 --- a/video/out/vo_sixel.c +++ b/video/out/vo_sixel.c @@ -336,11 +336,23 @@ static inline int sixel_write(char *data, int size, void *priv) { FILE *p = (FILE *)priv; // On POSIX platforms, write() is the fastest method. It also is the only - // one that—if implemented correctly—ensures atomic writes so mpv’s - // output will not be interrupted by other processes or threads that write - // to stdout, which would cause screen corruption. + // one that allows atomic writes so mpv’s output will not be interrupted + // by other processes or threads that write to stdout, which would cause + // screen corruption. POSIX does not guarantee atomicity for writes + // exceeding PIPE_BUF, but at least Linux does seem to implement it that + // way. #if HAVE_POSIX - return write(fileno(p), data, size); + int remain = size; + + while (remain > 0) { + ssize_t written = write(fileno(p), data, remain); + if (written < 0) + return written; + remain -= written; + data += written; + } + + return size; #else int ret = fwrite(data, 1, size, p); fflush(p); |