1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* An interface to read and write that retries after interrupts.
5 Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2011 Free Software
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 # include "safe-write.h"
27 # include "safe-read.h"
31 #include <sys/types.h>
37 # define IS_EINTR(x) ((x) == EINTR)
39 # define IS_EINTR(x) 0
45 # define safe_rw safe_write
48 # define safe_rw safe_read
51 # define const /* empty */
54 /* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
55 interrupted. Return the actual number of bytes read(written), zero for EOF,
56 or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */
58 safe_rw (int fd
, void const *buf
, size_t count
)
60 /* Work around a bug in Tru64 5.1. Attempting to read more than
61 INT_MAX bytes fails with errno == EINVAL. See
62 <http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
63 When decreasing COUNT, keep it block-aligned. */
64 enum { BUGGY_READ_MAXIMUM
= INT_MAX
& ~8191 };
68 ssize_t result
= rw (fd
, buf
, count
);
72 else if (IS_EINTR (errno
))
74 else if (errno
== EINVAL
&& BUGGY_READ_MAXIMUM
< count
)
75 count
= BUGGY_READ_MAXIMUM
;