diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-07-24 12:23:33 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-07-24 12:23:33 +0200 |
| commit | 0ba2797fdf4577588bcf7f5cac9d94ae43b8b31b (patch) | |
| tree | db3313317439e4eff369ea4687f4cd1181eb569e /csv.c | |
| parent | 4a77a81d349d81bf9ed479bb3b8ddedb1c22aa82 (diff) | |
| download | libcsv-0ba2797fdf4577588bcf7f5cac9d94ae43b8b31b.tar.gz libcsv-0ba2797fdf4577588bcf7f5cac9d94ae43b8b31b.tar.bz2 libcsv-0ba2797fdf4577588bcf7f5cac9d94ae43b8b31b.zip | |
Benutze size_t statt int bei Größenangaben
Diffstat (limited to 'csv.c')
| -rw-r--r-- | csv.c | 28 |
1 files changed, 14 insertions, 14 deletions
| @@ -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 | ||
| 194 | static inline void | 194 | static inline void |
| 195 | csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t *const csv_options) | 195 | csv_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 | ||
| 273 | int | 273 | size_t |
| 274 | csv_nfields(const csv_t *const csv) | 274 | csv_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 | ||
| 281 | const char * | 281 | const char * |
| 282 | csv_field(const csv_t *const csv, int idx) | 282 | csv_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 | /* |
