| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | #include <config.h> | - |
| 20 | | - |
| 21 | | - |
| 22 | #ifdef SAFE_WRITE | - |
| 23 | # include "safe-write.h" | - |
| 24 | #else | - |
| 25 | # include "safe-read.h" | - |
| 26 | #endif | - |
| 27 | | - |
| 28 | | - |
| 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 | | - |
| 53 | | - |
| 54 | | - |
| 55 | size_t | - |
| 56 | safe_rw (int fd, void const *buf, size_t count) | - |
| 57 | { | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 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)| TRUE | evaluated 110726 times by 14 testsEvaluated by:- cat
- cp
- csplit
- factor
- ginstall
- head
- mv
- split
- sum
- tac
- tail
- tr
- wc
- yes
| | FALSE | evaluated 168 times by 5 tests |
| 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))| TRUE | never evaluated | | FALSE | evaluated 168 times by 5 tests |
| 0-168 |
| 71 | continue; never executed: continue; | 0 |
| 72 | else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)| TRUE | evaluated 57 times by 1 test | | FALSE | evaluated 111 times by 5 tests |
| TRUE | never evaluated | | FALSE | evaluated 57 times by 1 test |
| 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; | 168 |
| 76 | } | - |
| 77 | } never executed: end of block | 0 |
| | |