| 126 // to complete the line |
126 // to complete the line |
| 127 size_t len_until_nl = (size_t)(nl.ptr - input.ptr) + 1; |
127 size_t len_until_nl = (size_t)(nl.ptr - input.ptr) + 1; |
| 128 |
128 |
| 129 if (cxBufferAppend(input.ptr, 1, |
129 if (cxBufferAppend(input.ptr, 1, |
| 130 len_until_nl, &prop->buffer) < len_until_nl) { |
130 len_until_nl, &prop->buffer) < len_until_nl) { |
| 131 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
131 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE |
| 132 } |
132 } |
| 133 |
133 |
| 134 // advance the position in the input buffer |
134 // advance the position in the input buffer |
| 135 prop->input.pos += len_until_nl; |
135 prop->input.pos += len_until_nl; |
| 136 |
136 |
| 195 // from a previous rescue there might be already read data |
195 // from a previous rescue there might be already read data |
| 196 // reset the buffer to avoid unnecessary buffer extension |
196 // reset the buffer to avoid unnecessary buffer extension |
| 197 cxBufferReset(&prop->buffer); |
197 cxBufferReset(&prop->buffer); |
| 198 } |
198 } |
| 199 if (cxBufferAppend(buf, 1, len, &prop->buffer) < len) { |
199 if (cxBufferAppend(buf, 1, len, &prop->buffer) < len) { |
| 200 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
200 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE |
| 201 } |
201 } |
| 202 // reset the input buffer (make way for a re-fill) |
202 // reset the input buffer (make way for a re-fill) |
| 203 cxBufferReset(&prop->input); |
203 cxBufferReset(&prop->input); |
| 204 return CX_PROPERTIES_INCOMPLETE_DATA; |
204 return CX_PROPERTIES_INCOMPLETE_DATA; |
| 205 } |
205 } |
| 254 cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); |
254 cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); |
| 255 } |
255 } |
| 256 prop->buffer.size = 0; |
256 prop->buffer.size = 0; |
| 257 prop->buffer.pos = 0; |
257 prop->buffer.pos = 0; |
| 258 if (cxBufferWrite(val.ptr, 1, val.length, &prop->buffer) != val.length) { |
258 if (cxBufferWrite(val.ptr, 1, val.length, &prop->buffer) != val.length) { |
| 259 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
259 return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE |
| 260 } |
260 } |
| 261 val.ptr = prop->buffer.space; |
261 val.ptr = prop->buffer.space; |
| 262 ptr = prop->buffer.space; |
262 ptr = prop->buffer.space; |
| 263 } |
263 } |
| 264 // value.ptr is now inside the rescue buffer and we can |
264 // value.ptr is now inside the rescue buffer and we can |
| 349 status = CX_PROPERTIES_NO_DATA; |
349 status = CX_PROPERTIES_NO_DATA; |
| 350 size_t keys_found = 0; |
350 size_t keys_found = 0; |
| 351 while (true) { |
351 while (true) { |
| 352 size_t r = fread(fillbuf, 1, cx_properties_load_fill_size, f); |
352 size_t r = fread(fillbuf, 1, cx_properties_load_fill_size, f); |
| 353 if (ferror(f)) { |
353 if (ferror(f)) { |
| |
354 // LCOV_EXCL_START |
| 354 status = CX_PROPERTIES_FILE_ERROR; |
355 status = CX_PROPERTIES_FILE_ERROR; |
| 355 break; |
356 break; |
| |
357 // LCOV_EXCL_STOP |
| 356 } |
358 } |
| 357 if (r == 0) { |
359 if (r == 0) { |
| 358 break; |
360 break; |
| 359 } |
361 } |
| 360 if (cxPropertiesFilln(&parser, fillbuf, r)) { |
362 if (cxPropertiesFilln(&parser, fillbuf, r)) { |
| |
363 // LCOV_EXCL_START |
| 361 status = CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
364 status = CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
| 362 break; |
365 break; |
| |
366 // LCOV_EXCL_STOP |
| 363 } |
367 } |
| 364 cxstring key, value; |
368 cxstring key, value; |
| 365 while (true) { |
369 while (true) { |
| 366 status = cxPropertiesNext(&parser, &key, &value); |
370 status = cxPropertiesNext(&parser, &key, &value); |
| 367 if (status != CX_PROPERTIES_NO_ERROR) { |
371 if (status != CX_PROPERTIES_NO_ERROR) { |
| 368 break; |
372 break; |
| 369 } else { |
373 } else { |
| 370 cxmutstr v = cx_strdup_a(allocator, value); |
374 cxmutstr v = cx_strdup_a(allocator, value); |
| |
375 // LCOV_EXCL_START |
| 371 if (v.ptr == NULL) { |
376 if (v.ptr == NULL) { |
| 372 status = CX_PROPERTIES_MAP_ERROR; |
377 status = CX_PROPERTIES_MAP_ERROR; |
| 373 break; |
378 break; |
| 374 } |
379 } |
| |
380 // LCOV_EXCL_STOP |
| 375 void *mv = use_cstring ? (void*)v.ptr : &v; |
381 void *mv = use_cstring ? (void*)v.ptr : &v; |
| 376 if (cxMapPut(target, key, mv)) { |
382 if (cxMapPut(target, key, mv)) { |
| |
383 // LCOV_EXCL_START |
| 377 cx_strfree(&v); |
384 cx_strfree(&v); |
| 378 status = CX_PROPERTIES_MAP_ERROR; |
385 status = CX_PROPERTIES_MAP_ERROR; |
| 379 break; |
386 break; |
| |
387 // LCOV_EXCL_STOP |
| 380 } |
388 } |
| 381 keys_found++; |
389 keys_found++; |
| 382 } |
390 } |
| 383 } |
391 } |
| 384 if (status > CX_PROPERTIES_OK) { |
392 if (status > CX_PROPERTIES_OK) { |