1 /* An interface to read and write that retries after interrupts.
3 Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2025 Free Software
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
23 # include "safe-write.h"
25 # include "safe-read.h"
29 #include <sys/types.h>
35 # define IS_EINTR(x) ((x) == EINTR)
37 # define IS_EINTR(x) 0
40 #include "sys-limits.h"
43 # define safe_rw safe_write
45 typedef void const *bufptr
;
47 # define safe_rw safe_read
52 /* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
53 interrupted. Return the number of bytes read(written), zero for EOF,
56 safe_rw (int fd
, bufptr buf
, idx_t count
)
60 ssize_t result
= rw (fd
, buf
, count
<= (size_t) -1 ? count
: (size_t) -1);
64 else if (IS_EINTR (errno
))
66 else if (errno
== EINVAL
&& SYS_BUFSIZE_MAX
< count
)
67 count
= SYS_BUFSIZE_MAX
;