MCPcopy Create free account
hub / github.com/IoLanguage/io / UArray_readLineFromCStream_

Function UArray_readLineFromCStream_

libs/basekit/source/UArray_stream.c:88–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88int 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

Callers 1

IoFile.cFile · 0.85

Calls 2

UArray_appendCString_Function · 0.85
io_freeFunction · 0.85

Tested by

no test coverage detected