| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | #include <config.h> | - |
| 23 | | - |
| 24 | #include <sys/types.h> | - |
| 25 | | - |
| 26 | #if defined (HAVE_UNISTD_H) | - |
| 27 | # include <unistd.h> | - |
| 28 | #endif | - |
| 29 | | - |
| 30 | #include <errno.h> | - |
| 31 | #include "xmalloc.h" | - |
| 32 | | - |
| 33 | #if !defined (errno) | - |
| 34 | extern int errno; | - |
| 35 | #endif | - |
| 36 | | - |
| 37 | extern ssize_t zread __P((int, char *, size_t)); | - |
| 38 | extern ssize_t zreadc __P((int, char *)); | - |
| 39 | extern ssize_t zreadintr __P((int, char *, size_t)); | - |
| 40 | extern ssize_t zreadcintr __P((int, char *)); | - |
| 41 | | - |
| 42 | typedef ssize_t breadfunc_t __P((int, char *, size_t)); | - |
| 43 | typedef ssize_t creadfunc_t __P((int, char *)); | - |
| 44 | | - |
| 45 | | - |
| 46 | #define GET_LINE_INITIAL_ALLOCATION 16 | - |
| 47 | | - |
| 48 | | - |
| 49 | | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | ssize_t | - |
| 64 | zgetline (fd, lineptr, n, delim, unbuffered_read) | - |
| 65 | int fd; | - |
| 66 | char **lineptr; | - |
| 67 | size_t *n; | - |
| 68 | int delim; | - |
| 69 | int unbuffered_read; | - |
| 70 | { | - |
| 71 | int nr, retval; | - |
| 72 | char *line, c; | - |
| 73 | | - |
| 74 | if (lineptr == 0 || n == 0 || (*lineptr == 0 && *n != 0))| TRUE | never evaluated | | FALSE | evaluated 161 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 161 times by 1 test |
| TRUE | evaluated 23 times by 1 test | | FALSE | evaluated 138 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 23 times by 1 test |
| 0-161 |
| 75 | return -1; never executed: return -1; | 0 |
| 76 | | - |
| 77 | nr = 0; | - |
| 78 | line = *lineptr; | - |
| 79 | | - |
| 80 | while (1) | - |
| 81 | { | - |
| 82 | retval = unbuffered_read ? zread (fd, &c, 1) : zreadc(fd, &c);| TRUE | evaluated 24 times by 1 test | | FALSE | evaluated 2509 times by 1 test |
| 24-2509 |
| 83 | | - |
| 84 | if (retval <= 0)| TRUE | evaluated 27 times by 1 test | | FALSE | evaluated 2506 times by 1 test |
| 27-2506 |
| 85 | { | - |
| 86 | if (line && nr > 0)| TRUE | evaluated 16 times by 1 test | | FALSE | evaluated 11 times by 1 test |
| TRUE | evaluated 7 times by 1 test | | FALSE | evaluated 9 times by 1 test |
| 7-16 |
| 87 | line[nr] = '\0';executed 7 times by 1 test: line[nr] = '\0'; | 7 |
| 88 | break;executed 27 times by 1 test: break; | 27 |
| 89 | } | - |
| 90 | | - |
| 91 | if (nr + 2 >= *n)| TRUE | evaluated 20 times by 1 test | | FALSE | evaluated 2486 times by 1 test |
| 20-2486 |
| 92 | { | - |
| 93 | size_t new_size; | - |
| 94 | | - |
| 95 | new_size = (*n == 0) ? GET_LINE_INITIAL_ALLOCATION : *n * 2;| TRUE | evaluated 12 times by 1 test | | FALSE | evaluated 8 times by 1 test |
| 8-12 |
| 96 | line = (*n >= new_size) ? NULL : xrealloc (*lineptr, new_size);| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 97 | | - |
| 98 | if (line)| TRUE | evaluated 20 times by 1 test | | FALSE | never evaluated |
| 0-20 |
| 99 | { | - |
| 100 | *lineptr = line; | - |
| 101 | *n = new_size; | - |
| 102 | }executed 20 times by 1 test: end of block | 20 |
| 103 | else | - |
| 104 | { | - |
| 105 | if (*n > 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 106 | { | - |
| 107 | (*lineptr)[*n - 1] = '\0'; | - |
| 108 | nr = *n - 2; | - |
| 109 | } never executed: end of block | 0 |
| 110 | break; never executed: break; | 0 |
| 111 | } | - |
| 112 | } | - |
| 113 | | - |
| 114 | line[nr] = c; | - |
| 115 | nr++; | - |
| 116 | | - |
| 117 | if (c == delim)| TRUE | evaluated 134 times by 1 test | | FALSE | evaluated 2372 times by 1 test |
| 134-2372 |
| 118 | { | - |
| 119 | line[nr] = '\0'; | - |
| 120 | break;executed 134 times by 1 test: break; | 134 |
| 121 | } | - |
| 122 | }executed 2372 times by 1 test: end of block | 2372 |
| 123 | | - |
| 124 | return nr - 1;executed 161 times by 1 test: return nr - 1; | 161 |
| 125 | } | - |
| | |