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