version 1.1, 2012/05/29 09:29:42
|
version 1.1.1.2, 2021/03/17 13:38:46
|
Line 1
|
Line 1
|
/* An interface to read and write that retries after interrupts. |
/* An interface to read and write that retries after interrupts. |
|
|
Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2011 Free Software | Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2019 Free Software |
Foundation, Inc. |
Foundation, Inc. |
|
|
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
Line 14
|
Line 14
|
GNU General Public License for more details. |
GNU General Public License for more details. |
|
|
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
|
|
#include <config.h> |
#include <config.h> |
|
|
Line 37
|
Line 37
|
# define IS_EINTR(x) 0 |
# define IS_EINTR(x) 0 |
#endif |
#endif |
|
|
#include <limits.h> | #include "sys-limits.h" |
|
|
#ifdef SAFE_WRITE |
#ifdef SAFE_WRITE |
# define safe_rw safe_write |
# define safe_rw safe_write |
Line 55
|
Line 55
|
size_t |
size_t |
safe_rw (int fd, void const *buf, size_t count) |
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 (;;) |
for (;;) |
{ |
{ |
ssize_t result = rw (fd, buf, count); |
ssize_t result = rw (fd, buf, count); |
Line 69 safe_rw (int fd, void const *buf, size_t count)
|
Line 63 safe_rw (int fd, void const *buf, size_t count)
|
return result; |
return result; |
else if (IS_EINTR (errno)) |
else if (IS_EINTR (errno)) |
continue; |
continue; |
else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) | else if (errno == EINVAL && SYS_BUFSIZE_MAX < count) |
count = BUGGY_READ_MAXIMUM; | count = SYS_BUFSIZE_MAX; |
else |
else |
return result; |
return result; |
} |
} |