vo_sixel: Implement write() loop

Not all systems are Linux. Also update the comment to better reflect
POSIX documentation.
This commit is contained in:
Mia Herkt 2022-12-20 10:45:36 +01:00
parent 125fd4c2f9
commit 56f0ba22f1
No known key found for this signature in database
GPG Key ID: 72E154B8622EC191
1 changed files with 16 additions and 4 deletions

View File

@ -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 mpvs
// 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 mpvs 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);