summaryrefslogtreecommitdiff
path: root/csv.c
diff options
context:
space:
mode:
Diffstat (limited to 'csv.c')
-rw-r--r--csv.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/csv.c b/csv.c
index 3804095..ce8cb00 100644
--- a/csv.c
+++ b/csv.c
@@ -134,7 +134,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const
134 assert(csv_string != NULL); 134 assert(csv_string != NULL);
135 assert(csv_options != NULL); 135 assert(csv_options != NULL);
136 136
137 static const int INITIAL_CAP = 16; 137 static const size_t INITIAL_CAP = 16;
138 138
139 if ( csv_string->pos == csv_string->cap ) { // grow if needed 139 if ( csv_string->pos == csv_string->cap ) { // grow if needed
140 if ( csv_string->str == NULL ) { // first call? 140 if ( csv_string->str == NULL ) { // first call?
@@ -144,9 +144,9 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const
144 } 144 }
145 csv_string->cap = INITIAL_CAP; 145 csv_string->cap = INITIAL_CAP;
146 } 146 }
147 else { // subsequent call 147 else { // subsequent call
148 int cap = (csv_string->cap * 3) / 2; // *= 1.5 148 size_t cap = (csv_string->cap * 3) / 2; // *= 1.5
149 char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); 149 char * str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg);
150 if ( str == NULL ) { 150 if ( str == NULL ) {
151 csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); 151 csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options);
152 return; 152 return;
@@ -192,7 +192,7 @@ csv_field_reset(csv_field_t *csv_field)
192} 192}
193 193
194static inline void 194static inline void
195csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t *const csv_options) 195csv_field_append(csv_field_t *csv_field, size_t idx, const csv_options_t *const csv_options)
196{ 196{
197 assert(csv_field != NULL); 197 assert(csv_field != NULL);
198 assert(csv_options != NULL); 198 assert(csv_options != NULL);
@@ -207,9 +207,9 @@ csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t *const csv
207 } 207 }
208 csv_field->cap = INITIAL_CAP; 208 csv_field->cap = INITIAL_CAP;
209 } 209 }
210 else { // subsequent call 210 else { // subsequent call
211 int cap = (csv_field->cap * 3) / 2; // *= 1.5 211 size_t cap = (csv_field->cap * 3) / 2; // *= 1.5
212 int *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); 212 size_t *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg);
213 if ( fields == NULL ) { 213 if ( fields == NULL ) {
214 csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); 214 csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options);
215 return; 215 return;
@@ -270,7 +270,7 @@ csv_cleanup(csv_t *csv)
270 csv->csv_options = NULL; 270 csv->csv_options = NULL;
271} 271}
272 272
273int 273size_t
274csv_nfields(const csv_t *const csv) 274csv_nfields(const csv_t *const csv)
275{ 275{
276 assert(csv != NULL); 276 assert(csv != NULL);
@@ -279,7 +279,7 @@ csv_nfields(const csv_t *const csv)
279} 279}
280 280
281const char * 281const char *
282csv_field(const csv_t *const csv, int idx) 282csv_field(const csv_t *const csv, size_t idx)
283{ 283{
284 assert(csv != NULL); 284 assert(csv != NULL);
285 assert(idx >= 0 && idx < csv->csv_field.pos); 285 assert(idx >= 0 && idx < csv->csv_field.pos);
@@ -304,13 +304,13 @@ csv_read(csv_t *csv, FILE *in)
304 304
305 if ( ferror(in) ) { 305 if ( ferror(in) ) {
306 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); 306 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options);
307 return EOF; 307 return 0;
308 } 308 }
309 309
310 // do not try to read if EOF has already been seen 310 // do not try to read if EOF has already been seen
311 if ( feof(in) ) { 311 if ( feof(in) ) {
312 csv_cleanup(csv); 312 csv_cleanup(csv);
313 return EOF; 313 return 0;
314 } 314 }
315 315
316 enum { 316 enum {
@@ -442,12 +442,12 @@ csv_read(csv_t *csv, FILE *in)
442 case STATE_END_FILE: 442 case STATE_END_FILE:
443 if ( ferror(in) ) { 443 if ( ferror(in) ) {
444 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); 444 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options);
445 return EOF; 445 return 0;
446 } 446 }
447 447
448 if ( csv_string_empty(&csv->csv_string) ) { 448 if ( csv_string_empty(&csv->csv_string) ) {
449 csv_cleanup(csv); 449 csv_cleanup(csv);
450 return EOF; // EOF reached 450 return 0; // EOF reached
451 } 451 }
452 452
453 /* 453 /*