mirror of
https://github.com/mpv-player/mpv
synced 2025-04-26 13:19:12 +00:00
vo_sixel: Implement write() loop
Not all systems are Linux. Also update the comment to better reflect POSIX documentation.
This commit is contained in:
parent
125fd4c2f9
commit
56f0ba22f1
@ -336,11 +336,23 @@ static inline int sixel_write(char *data, int size, void *priv)
|
|||||||
{
|
{
|
||||||
FILE *p = (FILE *)priv;
|
FILE *p = (FILE *)priv;
|
||||||
// On POSIX platforms, write() is the fastest method. It also is the only
|
// On POSIX platforms, write() is the fastest method. It also is the only
|
||||||
// one that—if implemented correctly—ensures atomic writes so mpv’s
|
// one that allows atomic writes so mpv’s output will not be interrupted
|
||||||
// output will not be interrupted by other processes or threads that write
|
// by other processes or threads that write to stdout, which would cause
|
||||||
// to stdout, which would cause screen corruption.
|
// 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
|
#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
|
#else
|
||||||
int ret = fwrite(data, 1, size, p);
|
int ret = fwrite(data, 1, size, p);
|
||||||
fflush(p);
|
fflush(p);
|
||||||
|
Loading…
Reference in New Issue
Block a user