| 86 | } |
| 87 | |
| 88 | int UArray_readLineFromCStream_(UArray *self, FILE *stream) { |
| 89 | int readSomething = 0; |
| 90 | |
| 91 | if (self->itemSize == 1) { |
| 92 | char *s = (char *)io_calloc(1, CHUNK_SIZE); |
| 93 | |
| 94 | while (fgets(s, CHUNK_SIZE, stream) != NULL) { |
| 95 | long i; |
| 96 | long start = strlen(s) - 1; |
| 97 | |
| 98 | /* Remove trailing newline characters */ |
| 99 | for (i = start; (i >= 0) && ((s[i] == '\n') || (s[i] == '\r')); |
| 100 | s[i--] = '\0') |
| 101 | ; |
| 102 | |
| 103 | readSomething = 1; |
| 104 | |
| 105 | if (*s) { |
| 106 | UArray_appendCString_(self, s); |
| 107 | } |
| 108 | |
| 109 | /* I think this might not quite be right, but it's equivalent to |
| 110 | * what was happening before... */ |
| 111 | if (i < start) { |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | io_free(s); |
| 117 | } |
| 118 | |
| 119 | return readSomething; |
| 120 | } |
| 121 | |
| 122 | // write ------------------------------------------------------ |
| 123 |
no test coverage detected