[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
full_read depends on incoming errno
From: |
Andy Wingo |
Subject: |
full_read depends on incoming errno |
Date: |
Tue, 19 Feb 2013 20:05:48 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Hi,
We use full_read in Guile and just got a bug report that full_read was
depending on the incoming errno. Eli Zaretskii proposed that the fix be
like this:
> + errno = 0;
> if (full_read (fd, cookie, sizeof cookie) != sizeof cookie
[...]
To recall, safe_read (called by full_read) looks like this:
/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
interrupted. Return the actual number of bytes read(written), zero for
EOF,
or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */
size_t
safe_rw (int fd, void const *buf, size_t count)
{
/* Work around a bug in Tru64 5.1. Attempting to read more than
INT_MAX bytes fails with errno == EINVAL. See
<http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
When decreasing COUNT, keep it block-aligned. */
enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
for (;;)
{
ssize_t result = rw (fd, buf, count);
if (0 <= result)
return result;
else if (IS_EINTR (errno))
continue;
else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
count = BUGGY_READ_MAXIMUM;
else
return result;
}
}
Here we see that if the system does not set errno on a partial read, as
is apparently the case in MinGW, then we depend on the incoming value of
errno.
WDYT about having safe_rw set errno before entering the loop?
Thanks,
Andy
--
http://wingolog.org/
- full_read depends on incoming errno,
Andy Wingo <=
- Re: full_read depends on incoming errno, Paul Eggert, 2013/02/19
- Re: full_read depends on incoming errno, Eli Zaretskii, 2013/02/19
- Re: full_read depends on incoming errno, Paul Eggert, 2013/02/19
- Re: full_read depends on incoming errno, Andy Wingo, 2013/02/19
- Re: full_read depends on incoming errno, Eli Zaretskii, 2013/02/20
- Re: full_read depends on incoming errno, Andy Wingo, 2013/02/20
- Re: full_read depends on incoming errno, Eli Zaretskii, 2013/02/20
- Re: full_read depends on incoming errno, Paolo Bonzini, 2013/02/21
- Re: full_read depends on incoming errno, Andy Wingo, 2013/02/21
- Re: full_read depends on incoming errno, Paolo Bonzini, 2013/02/21