| 251 #define CX_PROPERTIES_LOAD_BUF_SIZE 256 |
251 #define CX_PROPERTIES_LOAD_BUF_SIZE 256 |
| 252 #endif |
252 #endif |
| 253 const unsigned cx_properties_load_buf_size = CX_PROPERTIES_LOAD_BUF_SIZE; |
253 const unsigned cx_properties_load_buf_size = CX_PROPERTIES_LOAD_BUF_SIZE; |
| 254 |
254 |
| 255 CxPropertiesStatus cx_properties_load(CxPropertiesConfig config, |
255 CxPropertiesStatus cx_properties_load(CxPropertiesConfig config, |
| 256 cxstring filename, CxMap *target) { |
256 const CxAllocator *allocator, cxstring filename, CxMap *target) { |
| 257 // sanity check for the map |
257 // sanity check for the map |
| 258 const bool use_cstring = cxCollectionStoresPointers(target); |
258 const bool use_cstring = cxCollectionStoresPointers(target); |
| 259 if (!use_cstring && cxCollectionElementSize(target) != sizeof(cxmutstr)) { |
259 if (!use_cstring && cxCollectionElementSize(target) != sizeof(cxmutstr)) { |
| 260 return CX_PROPERTIES_MAP_ERROR; |
260 return CX_PROPERTIES_MAP_ERROR; |
| 261 } |
261 } |
| 300 while (true) { |
300 while (true) { |
| 301 status = cxPropertiesNext(&parser, &key, &value); |
301 status = cxPropertiesNext(&parser, &key, &value); |
| 302 if (status != CX_PROPERTIES_NO_ERROR) { |
302 if (status != CX_PROPERTIES_NO_ERROR) { |
| 303 break; |
303 break; |
| 304 } else { |
304 } else { |
| 305 cxmutstr v = cx_strdup(value); |
305 cxmutstr v = cx_strdup_a(allocator, value); |
| 306 if (v.ptr == NULL) { |
306 if (v.ptr == NULL) { |
| 307 status = CX_PROPERTIES_MAP_ERROR; |
307 status = CX_PROPERTIES_MAP_ERROR; |
| 308 break; |
308 break; |
| 309 } |
309 } |
| 310 void *mv = use_cstring ? (void*)v.ptr : &v; |
310 void *mv = use_cstring ? (void*)v.ptr : &v; |