diff options
| -rw-r--r-- | csv-test.c | 6 | ||||
| -rw-r--r-- | csv.c | 4 | ||||
| -rw-r--r-- | csv.h | 2 |
3 files changed, 5 insertions, 7 deletions
| @@ -16,7 +16,6 @@ test(FILE *f) | |||
| 16 | for ( int n; (n = csv_read(csv, f)) != -1; ) { | 16 | for ( int n; (n = csv_read(csv, f)) != -1; ) { |
| 17 | ++line; | 17 | ++line; |
| 18 | } | 18 | } |
| 19 | csv_free(csv); | ||
| 20 | 19 | ||
| 21 | return line; | 20 | return line; |
| 22 | } | 21 | } |
| @@ -31,7 +30,6 @@ test_exception(FILE *f) | |||
| 31 | for ( int n; (n = csv_read(csv, f)) != -1; ) { | 30 | for ( int n; (n = csv_read(csv, f)) != -1; ) { |
| 32 | if (++line == 500000) csv_field(csv, -1); | 31 | if (++line == 500000) csv_field(csv, -1); |
| 33 | } | 32 | } |
| 34 | csv_free(csv); | ||
| 35 | 33 | ||
| 36 | return line; | 34 | return line; |
| 37 | } | 35 | } |
| @@ -57,7 +55,6 @@ test_exception_with_signal(FILE *f) | |||
| 57 | for ( int n; (n = csv_read(csv, f)) != -1; ) { | 55 | for ( int n; (n = csv_read(csv, f)) != -1; ) { |
| 58 | if (++line == 500000) csv_field(csv, -1); | 56 | if (++line == 500000) csv_field(csv, -1); |
| 59 | } | 57 | } |
| 60 | csv_free(csv); | ||
| 61 | 58 | ||
| 62 | signal(SIGABRT, old_handler); | 59 | signal(SIGABRT, old_handler); |
| 63 | 60 | ||
| @@ -93,11 +90,10 @@ test_exception_longjmp(FILE *f) | |||
| 93 | // process data... | 90 | // process data... |
| 94 | if (++line == 500000) csv_field(csv, -1); | 91 | if (++line == 500000) csv_field(csv, -1); |
| 95 | } | 92 | } |
| 96 | csv_free(csv); | ||
| 97 | return line; | 93 | return line; |
| 98 | } | 94 | } |
| 99 | else { | 95 | else { |
| 100 | csv_free(csv); | 96 | csv_cleanup(csv); |
| 101 | return -1; | 97 | return -1; |
| 102 | } | 98 | } |
| 103 | } | 99 | } |
| @@ -219,7 +219,7 @@ csv_init_opt(csv_t *csv, const csv_options_t * const csv_options) | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | void | 221 | void |
| 222 | csv_free(csv_t *csv) | 222 | csv_cleanup(csv_t *csv) |
| 223 | { | 223 | { |
| 224 | assert(csv != NULL); | 224 | assert(csv != NULL); |
| 225 | 225 | ||
| @@ -259,6 +259,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 259 | 259 | ||
| 260 | /* do not try to read if EOF has already been seen */ | 260 | /* do not try to read if EOF has already been seen */ |
| 261 | if ( feof(in) ) { | 261 | if ( feof(in) ) { |
| 262 | csv_cleanup(csv); | ||
| 262 | return -1; | 263 | return -1; |
| 263 | } | 264 | } |
| 264 | 265 | ||
| @@ -392,6 +393,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 392 | } | 393 | } |
| 393 | 394 | ||
| 394 | if ( csv_string_empty(&csv->csv_string) ) { | 395 | if ( csv_string_empty(&csv->csv_string) ) { |
| 396 | csv_cleanup(csv); | ||
| 395 | return -1; /* EOF reached */ | 397 | return -1; /* EOF reached */ |
| 396 | } | 398 | } |
| 397 | 399 | ||
| @@ -38,7 +38,7 @@ typedef struct { | |||
| 38 | 38 | ||
| 39 | void csv_init(csv_t *csv); | 39 | void csv_init(csv_t *csv); |
| 40 | void csv_init_opt(csv_t *csv, const csv_options_t * const csv_options); | 40 | void csv_init_opt(csv_t *csv, const csv_options_t * const csv_options); |
| 41 | void csv_free(csv_t *csv); | 41 | void csv_cleanup(csv_t *csv); |
| 42 | int csv_nfields(csv_t *csv); | 42 | int csv_nfields(csv_t *csv); |
| 43 | const char * csv_field(csv_t *csv, int idx); | 43 | const char * csv_field(csv_t *csv, int idx); |
| 44 | int csv_read(csv_t *csv, FILE *in); | 44 | int csv_read(csv_t *csv, FILE *in); |
