dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 84.1% 37 / 0 / 44
Functions: 85.7% 6 / 0 / 7
Branches: 23.1% 6 / 2 / 28

src/util/xstdio.c
Line Branch Exec Source
1 #include <errno.h>
2 #include "xstdio.h"
3
4 1 char *xfgets(char *restrict buf, int bufsize, FILE *restrict stream)
5 {
6 1 char *r;
7 3 do {
8 1 clearerr(stream);
9 1 r = fgets(buf, bufsize, stream);
10
2/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 9 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 1 time.
✗ Branch 8 → 3 not taken.
✗ Branch 8 → 9 not taken.
1 } while (unlikely(!r && ferror(stream) && errno == EINTR));
11 1 return r;
12 }
13
14 9 int xfputs(const char *restrict str, FILE *restrict stream)
15 {
16 9 int r;
17 18 do {
18 9 r = fputs(str, stream);
19
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 9 times.
✗ Branch 5 → 3 not taken.
✗ Branch 5 → 6 not taken.
9 } while (unlikely(r == EOF && errno == EINTR));
20 9 return r;
21 }
22
23 9 int xfputc(int c, FILE *stream)
24 {
25 9 int r;
26 18 do {
27 9 r = fputc(c, stream);
28
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 9 times.
✗ Branch 5 → 3 not taken.
✗ Branch 5 → 6 not taken.
9 } while (unlikely(r == EOF && errno == EINTR));
29 9 return r;
30 }
31
32 size_t xfwrite_all(const char *restrict buf, size_t nitems, FILE *restrict stream)
33 {
34 // "The fwrite() function shall return the number of elements
35 // successfully written, which shall be less than nitems only
36 // if a write error is encountered."
37 // -- https://pubs.opengroup.org/onlinepubs/9799919799/functions/fwrite.html
38 size_t pos = 0;
39 do {
40 pos += fwrite(buf + pos, 1, nitems - pos, stream);
41 } while (unlikely(pos < nitems && errno == EINTR));
42
43 BUG_ON(pos > nitems);
44 return pos;
45 }
46
47 VPRINTF(2)
48 1 static int xvfprintf(FILE *restrict stream, const char *restrict fmt, va_list ap)
49 {
50 1 int r;
51 2 do {
52 1 r = vfprintf(stream, fmt, ap);
53
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1 time.
✗ Branch 5 → 3 not taken.
✗ Branch 5 → 6 not taken.
1 } while (unlikely(r < 0 && errno == EINTR));
54 1 return r;
55 }
56
57 1 int xfprintf(FILE *restrict stream, const char *restrict fmt, ...)
58 {
59 1 va_list ap;
60 1 va_start(ap, fmt);
61 1 int r = xvfprintf(stream, fmt, ap);
62 1 va_end(ap);
63 1 return r;
64 }
65
66 1 int xfflush(FILE *stream)
67 {
68 1 int r;
69 2 do {
70 1 r = fflush(stream);
71
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1 time.
✗ Branch 5 → 3 not taken.
✗ Branch 5 → 6 not taken.
1 } while (unlikely(r != 0 && errno == EINTR));
72 1 return r;
73 }
74