OpenCoverage

safe-read.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/safe-read.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* An interface to read and write that retries after interrupts.-
2-
3 Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2018 Free Software-
4 Foundation, Inc.-
5-
6 This program is free software: you can redistribute it and/or modify-
7 it under the terms of the GNU General Public License as published by-
8 the Free Software Foundation; either version 3 of the License, or-
9 (at your option) any later version.-
10-
11 This program 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 General Public License for more details.-
15-
16 You should have received a copy of the GNU General Public License-
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
18-
19#include <config.h>-
20-
21/* Specification. */-
22#ifdef SAFE_WRITE-
23# include "safe-write.h"-
24#else-
25# include "safe-read.h"-
26#endif-
27-
28/* Get ssize_t. */-
29#include <sys/types.h>-
30#include <unistd.h>-
31-
32#include <errno.h>-
33-
34#ifdef EINTR-
35# define IS_EINTR(x) ((x) == EINTR)-
36#else-
37# define IS_EINTR(x) 0-
38#endif-
39-
40#include <limits.h>-
41-
42#ifdef SAFE_WRITE-
43# define safe_rw safe_write-
44# define rw write-
45#else-
46# define safe_rw safe_read-
47# define rw read-
48# undef const-
49# define const /* empty */-
50#endif-
51-
52/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if-
53 interrupted. Return the actual number of bytes read(written), zero for EOF,-
54 or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */-
55size_t-
56safe_rw (int fd, void const *buf, size_t count)-
57{-
58 /* Work around a bug in Tru64 5.1. Attempting to read more than-
59 INT_MAX bytes fails with errno == EINVAL. See-
60 <https://lists.gnu.org/r/bug-gnu-utils/2002-04/msg00010.html>.-
61 When decreasing COUNT, keep it block-aligned. */-
62 enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };-
63-
64 for (;;)-
65 {-
66 ssize_t result = rw (fd, buf, count);-
67-
68 if (0 <= result)
0 <= resultDescription
TRUEevaluated 110726 times by 14 tests
Evaluated by:
  • cat
  • cp
  • csplit
  • factor
  • ginstall
  • head
  • mv
  • split
  • sum
  • tac
  • tail
  • tr
  • wc
  • yes
FALSEevaluated 168 times by 5 tests
Evaluated by:
  • cat
  • split
  • tac
  • tail
  • yes
168-110726
69 return result;
executed 110726 times by 14 tests: return result;
Executed by:
  • cat
  • cp
  • csplit
  • factor
  • ginstall
  • head
  • mv
  • split
  • sum
  • tac
  • tail
  • tr
  • wc
  • yes
110726
70 else if (IS_EINTR (errno))
(( (*__errno_l...n ()) ) == 4 )Description
TRUEnever evaluated
FALSEevaluated 168 times by 5 tests
Evaluated by:
  • cat
  • split
  • tac
  • tail
  • yes
0-168
71 continue;
never executed: continue;
0
72 else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
(*__errno_location ()) == 22Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • tail
FALSEevaluated 111 times by 5 tests
Evaluated by:
  • cat
  • split
  • tac
  • tail
  • yes
BUGGY_READ_MAXIMUM < countDescription
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • tail
0-111
73 count = BUGGY_READ_MAXIMUM;
never executed: count = BUGGY_READ_MAXIMUM;
0
74 else-
75 return result;
executed 168 times by 5 tests: return result;
Executed by:
  • cat
  • split
  • tac
  • tail
  • yes
168
76 }-
77}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2