Skip to content

Commit 40300dc

Browse files
committed
ChafaStreamReader: Remember to save the errno
1 parent b0bbbc4 commit 40300dc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/chafa/chafa-stream-reader.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ read_from_stream (ChafaStreamReader *stream_reader, guchar *out, gint max)
129129
else if (GetLastError () != ERROR_IO_PENDING)
130130
result = -1;
131131
#else /* !G_OS_WIN32 */
132+
gint saved_errno;
133+
132134
/* Do a non-blocking read. We're forced to turn it on and off again:
133135
*
134136
* - If we're reading from stdin, we can't leave it in non-blocking
@@ -146,11 +148,12 @@ read_from_stream (ChafaStreamReader *stream_reader, guchar *out, gint max)
146148

147149
g_unix_set_fd_nonblocking (stream_reader->fd, TRUE, NULL);
148150
result = read (stream_reader->fd, out, max);
151+
saved_errno = errno;
149152
g_unix_set_fd_nonblocking (stream_reader->fd, FALSE, NULL);
150153

151154
if (result < 1)
152155
{
153-
result = (errno == EAGAIN || errno == EINTR) ? 0 : -1;
156+
result = (saved_errno == EAGAIN || saved_errno == EINTR) ? 0 : -1;
154157
}
155158
#endif
156159
}

0 commit comments

Comments
 (0)