diff options
| author | Thomas Schmucker <ts@its1.de> | 2025-04-13 10:45:35 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2025-04-13 10:45:35 +0200 |
| commit | 85fe3b67a67825dfc5e43959f001b2a7159dc23f (patch) | |
| tree | 51588584397d6147a77e5fd9d77aa2274b152c6a /lib | |
| parent | 0402756330a118e55d3d7d31baa06e1420347320 (diff) | |
| download | libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.tar.gz libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.tar.bz2 libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.zip | |
new directory structure
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/include/csv.h | 71 | ||||
| -rw-r--r-- | lib/makefile | 0 | ||||
| -rw-r--r-- | lib/src/csv.c | 464 |
3 files changed, 535 insertions, 0 deletions
diff --git a/lib/include/csv.h b/lib/include/csv.h new file mode 100644 index 0000000..9ac7c05 --- /dev/null +++ b/lib/include/csv.h | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stddef.h> /* size_t */ | ||
| 4 | #include <stdio.h> /* FILE */ | ||
| 5 | |||
| 6 | #ifdef __cplusplus | ||
| 7 | extern "C" { | ||
| 8 | #endif | ||
| 9 | |||
| 10 | typedef enum { | ||
| 11 | CSV_ERR_OK = 0, | ||
| 12 | CSV_ERR_OUT_OF_MEMORY = -1, | ||
| 13 | CSV_ERR_OUT_OF_RANGE = -2, | ||
| 14 | CSV_ERR_IO_READ = -3, | ||
| 15 | CSV_ERR_IO_WRITE = -4 | ||
| 16 | } csv_err_t; | ||
| 17 | |||
| 18 | typedef struct { | ||
| 19 | int field_delimiter; | ||
| 20 | int field_separator; | ||
| 21 | |||
| 22 | void (*cb_error)(csv_err_t, void *); | ||
| 23 | void *cb_error_arg; | ||
| 24 | |||
| 25 | void *(*cb_allocate)(size_t, size_t, void *); | ||
| 26 | void *(*cb_reallocate)(void *, size_t, size_t, void *); | ||
| 27 | void (*cb_free)(void *, size_t, size_t, void *); | ||
| 28 | void *cb_memory_arg; | ||
| 29 | } csv_options_t; | ||
| 30 | |||
| 31 | extern const csv_options_t csv_default_options; | ||
| 32 | |||
| 33 | typedef struct { | ||
| 34 | char * str; | ||
| 35 | size_t cap, pos; | ||
| 36 | } csv_string_t; | ||
| 37 | |||
| 38 | typedef struct { | ||
| 39 | size_t *fields; | ||
| 40 | size_t cap, pos; | ||
| 41 | } csv_field_t; | ||
| 42 | |||
| 43 | typedef struct { | ||
| 44 | const csv_options_t *csv_options; | ||
| 45 | csv_string_t csv_string; | ||
| 46 | csv_field_t csv_field; | ||
| 47 | } csv_t; | ||
| 48 | |||
| 49 | /* version */ | ||
| 50 | extern const char csv_version[]; | ||
| 51 | |||
| 52 | /* initialization */ | ||
| 53 | void csv_init(csv_t *csv); | ||
| 54 | void csv_init_opt(csv_t *csv, const csv_options_t *const csv_options); | ||
| 55 | |||
| 56 | /* cleanup after error */ | ||
| 57 | void csv_cleanup(csv_t *csv); | ||
| 58 | |||
| 59 | /* read */ | ||
| 60 | size_t csv_read(csv_t *csv, FILE *in); | ||
| 61 | |||
| 62 | /* field access */ | ||
| 63 | size_t csv_nfields(const csv_t *const csv); | ||
| 64 | const char *csv_field(const csv_t *const csv, size_t idx); | ||
| 65 | |||
| 66 | /* error handling */ | ||
| 67 | const char *csv_err_str(csv_err_t csv_err); | ||
| 68 | |||
| 69 | #ifdef __cplusplus | ||
| 70 | } | ||
| 71 | #endif | ||
diff --git a/lib/makefile b/lib/makefile new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/makefile | |||
diff --git a/lib/src/csv.c b/lib/src/csv.c new file mode 100644 index 0000000..e9c7464 --- /dev/null +++ b/lib/src/csv.c | |||
| @@ -0,0 +1,464 @@ | |||
| 1 | #include "csv.h" | ||
| 2 | |||
| 3 | #include <assert.h> | ||
| 4 | #include <stddef.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | // === Compile time options === | ||
| 10 | |||
| 11 | #ifndef CSV_DEFAULT_DELIMITER | ||
| 12 | # define CSV_DEFAULT_DELIMITER '"' | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #ifndef CSV_DEFAULT_SEPARATOR | ||
| 16 | # define CSV_DEFAULT_SEPARATOR ',' | ||
| 17 | #endif | ||
| 18 | |||
| 19 | // === some useful Makros === | ||
| 20 | |||
| 21 | #define UNUSED(x) (void) (x) // mark a parameter as 'unused' | ||
| 22 | #define STR(s) #s // Stringify a Makro | ||
| 23 | #define XSTR(s) STR(s) | ||
| 24 | |||
| 25 | // === Semantic Version Information === | ||
| 26 | |||
| 27 | #define CSV_VER_MAJOR 1 | ||
| 28 | #define CSV_VER_MINOR 0 | ||
| 29 | #define CSV_VER_PATCH 0 | ||
| 30 | #define CSV_VER_APPENDIX "-dev" | ||
| 31 | |||
| 32 | const char csv_version[] = XSTR(CSV_VER_MAJOR) "." XSTR(CSV_VER_MINOR) "." XSTR(CSV_VER_PATCH) CSV_VER_APPENDIX "\0" __DATE__ "\0" __TIME__; | ||
| 33 | |||
| 34 | // === CSV-MEMORY Interface === | ||
| 35 | |||
| 36 | static void * | ||
| 37 | csv_mem_reallocate(void *ptr, size_t num, size_t size, void *cb_arg) | ||
| 38 | { | ||
| 39 | UNUSED(cb_arg); | ||
| 40 | |||
| 41 | return reallocarray(ptr, num, size); | ||
| 42 | } | ||
| 43 | |||
| 44 | static void | ||
| 45 | csv_mem_free(void *ptr, size_t num, size_t size, void *cb_arg) | ||
| 46 | { | ||
| 47 | UNUSED(num); | ||
| 48 | UNUSED(size); | ||
| 49 | UNUSED(cb_arg); | ||
| 50 | |||
| 51 | free(ptr); | ||
| 52 | } | ||
| 53 | |||
| 54 | // === CSV-OPTIONS Interface === | ||
| 55 | |||
| 56 | const csv_options_t csv_default_options = { | ||
| 57 | .field_delimiter = CSV_DEFAULT_DELIMITER, | ||
| 58 | .field_separator = CSV_DEFAULT_SEPARATOR, | ||
| 59 | .cb_error = NULL, | ||
| 60 | .cb_reallocate = csv_mem_reallocate, | ||
| 61 | .cb_free = csv_mem_free | ||
| 62 | }; | ||
| 63 | |||
| 64 | // === CSV-ERROR Interface === | ||
| 65 | |||
| 66 | static void | ||
| 67 | csv_fatal_error(csv_err_t csv_err, const csv_options_t *const csv_options) | ||
| 68 | { | ||
| 69 | if ( csv_options->cb_error != NULL ) { | ||
| 70 | (*csv_options->cb_error)(csv_err, csv_options->cb_error_arg); | ||
| 71 | } | ||
| 72 | (void) fprintf(stderr, "fatal error: %s\n", csv_err_str(csv_err)); | ||
| 73 | abort(); | ||
| 74 | } | ||
| 75 | |||
| 76 | // === CSV-STRING Interface === | ||
| 77 | |||
| 78 | static inline void | ||
| 79 | csv_string_init(csv_string_t *csv_string) | ||
| 80 | { | ||
| 81 | assert(csv_string != NULL); | ||
| 82 | |||
| 83 | csv_string->str = NULL; | ||
| 84 | csv_string->cap = 0; | ||
| 85 | csv_string->pos = 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | static inline void | ||
| 89 | csv_string_reset(csv_string_t *csv_string) | ||
| 90 | { | ||
| 91 | assert(csv_string != NULL); | ||
| 92 | |||
| 93 | csv_string->pos = 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | static inline int | ||
| 97 | csv_string_isempty(csv_string_t *csv_string) | ||
| 98 | { | ||
| 99 | assert(csv_string != NULL); | ||
| 100 | |||
| 101 | return (csv_string->pos == 0) ? 1 : 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | static inline size_t | ||
| 105 | growth_strategy(size_t current_cap) | ||
| 106 | { | ||
| 107 | static const size_t INITIAL_CAP = 16; | ||
| 108 | |||
| 109 | return (current_cap == 0) ? INITIAL_CAP : (current_cap * 3) / 2; | ||
| 110 | } | ||
| 111 | |||
| 112 | static inline void | ||
| 113 | csv_string_grow_if_needed(csv_string_t *csv_string, const csv_options_t *const csv_options) | ||
| 114 | { | ||
| 115 | assert(csv_string != NULL); | ||
| 116 | assert(csv_options != NULL); | ||
| 117 | |||
| 118 | if ( csv_string->pos == csv_string->cap ) { | ||
| 119 | size_t cap = growth_strategy(csv_string->cap); | ||
| 120 | char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); | ||
| 121 | if ( str == NULL ) { | ||
| 122 | csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); | ||
| 123 | return; | ||
| 124 | } | ||
| 125 | csv_string->str = str; | ||
| 126 | csv_string->cap = cap; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | static inline void | ||
| 131 | csv_string_append(csv_string_t *csv_string, int ch, const csv_options_t *const csv_options) | ||
| 132 | { | ||
| 133 | assert(csv_string != NULL); | ||
| 134 | assert(csv_options != NULL); | ||
| 135 | |||
| 136 | csv_string_grow_if_needed(csv_string, csv_options); | ||
| 137 | |||
| 138 | csv_string->str[csv_string->pos++] = (char) ch; // append char | ||
| 139 | } | ||
| 140 | |||
| 141 | static inline void | ||
| 142 | csv_string_free(csv_string_t *csv_string, const csv_options_t *const csv_options) | ||
| 143 | { | ||
| 144 | assert(csv_string != NULL); | ||
| 145 | assert(csv_options != NULL); | ||
| 146 | |||
| 147 | csv_options->cb_free(csv_string->str, csv_string->cap, 1, csv_options->cb_memory_arg); | ||
| 148 | |||
| 149 | // call *_init() for sane default values; prevent possible double-free | ||
| 150 | csv_string_init(csv_string); | ||
| 151 | } | ||
| 152 | |||
| 153 | // === CSV-FIELD Interface === | ||
| 154 | |||
| 155 | static inline void | ||
| 156 | csv_field_init(csv_field_t *csv_field) | ||
| 157 | { | ||
| 158 | assert(csv_field != NULL); | ||
| 159 | |||
| 160 | csv_field->fields = NULL; | ||
| 161 | csv_field->cap = 0; | ||
| 162 | csv_field->pos = 0; | ||
| 163 | } | ||
| 164 | |||
| 165 | static inline void | ||
| 166 | csv_field_reset(csv_field_t *csv_field) | ||
| 167 | { | ||
| 168 | assert(csv_field != NULL); | ||
| 169 | |||
| 170 | csv_field->pos = 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | static inline void | ||
| 174 | csv_field_grow_if_needed(csv_field_t *csv_field, const csv_options_t *const csv_options) | ||
| 175 | { | ||
| 176 | assert(csv_field != NULL); | ||
| 177 | assert(csv_options != NULL); | ||
| 178 | |||
| 179 | if ( csv_field->pos == csv_field->cap ) { | ||
| 180 | size_t cap = growth_strategy(csv_field->cap); | ||
| 181 | size_t *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); | ||
| 182 | if ( fields == NULL ) { | ||
| 183 | csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); | ||
| 184 | return; | ||
| 185 | } | ||
| 186 | csv_field->fields = fields; | ||
| 187 | csv_field->cap = cap; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | static inline void | ||
| 192 | csv_field_append(csv_field_t *csv_field, size_t idx, const csv_options_t *const csv_options) | ||
| 193 | { | ||
| 194 | assert(csv_field != NULL); | ||
| 195 | assert(csv_options != NULL); | ||
| 196 | |||
| 197 | csv_field_grow_if_needed(csv_field, csv_options); | ||
| 198 | |||
| 199 | csv_field->fields[csv_field->pos++] = idx; // append index | ||
| 200 | } | ||
| 201 | |||
| 202 | static inline void | ||
| 203 | csv_field_free(csv_field_t *csv_field, const csv_options_t *const csv_options) | ||
| 204 | { | ||
| 205 | assert(csv_field != NULL); | ||
| 206 | assert(csv_options != NULL); | ||
| 207 | |||
| 208 | csv_options->cb_free(csv_field->fields, csv_field->cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); | ||
| 209 | |||
| 210 | csv_field_init(csv_field); | ||
| 211 | } | ||
| 212 | |||
| 213 | // === CSV Interface === | ||
| 214 | |||
| 215 | void | ||
| 216 | csv_init(csv_t *csv) | ||
| 217 | { | ||
| 218 | assert(csv != NULL); | ||
| 219 | |||
| 220 | csv_init_opt(csv, NULL); | ||
| 221 | } | ||
| 222 | |||
| 223 | void | ||
| 224 | csv_init_opt(csv_t *csv, const csv_options_t *const csv_options) | ||
| 225 | { | ||
| 226 | assert(csv != NULL); | ||
| 227 | |||
| 228 | if ( csv_options != NULL ) { | ||
| 229 | csv->csv_options = csv_options; | ||
| 230 | } | ||
| 231 | else { | ||
| 232 | csv->csv_options = &csv_default_options; | ||
| 233 | } | ||
| 234 | |||
| 235 | csv_string_init(&csv->csv_string); | ||
| 236 | csv_field_init(&csv->csv_field); | ||
| 237 | } | ||
| 238 | |||
| 239 | void | ||
| 240 | csv_cleanup(csv_t *csv) | ||
| 241 | { | ||
| 242 | assert(csv != NULL); | ||
| 243 | assert(csv->csv_options != NULL); | ||
| 244 | |||
| 245 | csv_string_free(&csv->csv_string, csv->csv_options); | ||
| 246 | csv_field_free(&csv->csv_field, csv->csv_options); | ||
| 247 | } | ||
| 248 | |||
| 249 | size_t | ||
| 250 | csv_nfields(const csv_t *const csv) | ||
| 251 | { | ||
| 252 | assert(csv != NULL); | ||
| 253 | |||
| 254 | return csv->csv_field.pos; | ||
| 255 | } | ||
| 256 | |||
| 257 | const char * | ||
| 258 | csv_field(const csv_t *const csv, size_t idx) | ||
| 259 | { | ||
| 260 | assert(csv != NULL); | ||
| 261 | assert(idx >= 0 && idx < csv->csv_field.pos); | ||
| 262 | |||
| 263 | if ( idx >= csv->csv_field.pos ) { | ||
| 264 | csv_fatal_error(CSV_ERR_OUT_OF_RANGE, csv->csv_options); | ||
| 265 | return NULL; | ||
| 266 | } | ||
| 267 | return &csv->csv_string.str[csv->csv_field.fields[idx]]; | ||
| 268 | } | ||
| 269 | |||
| 270 | size_t | ||
| 271 | csv_read(csv_t *csv, FILE *in) | ||
| 272 | { | ||
| 273 | assert(csv != NULL); | ||
| 274 | assert(in != NULL); | ||
| 275 | |||
| 276 | // initialize if needed... | ||
| 277 | if ( csv->csv_options == NULL ) { | ||
| 278 | csv_init(csv); | ||
| 279 | } | ||
| 280 | |||
| 281 | if ( ferror(in) ) { | ||
| 282 | csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); | ||
| 283 | return 0; | ||
| 284 | } | ||
| 285 | |||
| 286 | // do not try to read if EOF has already been seen | ||
| 287 | if ( feof(in) ) { | ||
| 288 | csv_cleanup(csv); | ||
| 289 | return 0; | ||
| 290 | } | ||
| 291 | |||
| 292 | enum { | ||
| 293 | STATE_START_FIELD, | ||
| 294 | STATE_QUOTED_FIELD, | ||
| 295 | STATE_SIMPLE_FIELD, | ||
| 296 | STATE_END_FIELD, | ||
| 297 | STATE_END_LINE, | ||
| 298 | STATE_END_FILE, | ||
| 299 | }; | ||
| 300 | |||
| 301 | register const int DELIM = csv->csv_options->field_delimiter; | ||
| 302 | register const int SEP = csv->csv_options->field_separator; | ||
| 303 | |||
| 304 | csv_string_reset(&csv->csv_string); | ||
| 305 | csv_field_reset(&csv->csv_field); | ||
| 306 | |||
| 307 | for ( int state = STATE_START_FIELD;; ) { | ||
| 308 | int ch; | ||
| 309 | |||
| 310 | switch ( state ) { | ||
| 311 | case STATE_START_FIELD: | ||
| 312 | csv_field_append(&csv->csv_field, csv->csv_string.pos, csv->csv_options); | ||
| 313 | |||
| 314 | ch = getc(in); | ||
| 315 | if ( ch == EOF ) { | ||
| 316 | state = STATE_END_FILE; | ||
| 317 | } | ||
| 318 | else if ( ch == '\r' ) { // test for CR.. | ||
| 319 | ch = getc(in); | ||
| 320 | if ( ch != '\n' ) { // ..LF | ||
| 321 | (void) ungetc(ch, in); | ||
| 322 | } | ||
| 323 | state = STATE_END_LINE; | ||
| 324 | } | ||
| 325 | else if ( ch == '\n' ) { | ||
| 326 | state = STATE_END_LINE; | ||
| 327 | } | ||
| 328 | else if ( ch == SEP ) { | ||
| 329 | state = STATE_END_FIELD; | ||
| 330 | } | ||
| 331 | else if ( ch == DELIM ) { | ||
| 332 | state = STATE_QUOTED_FIELD; | ||
| 333 | } | ||
| 334 | else { | ||
| 335 | if ( ch != '\0' ) { | ||
| 336 | csv_string_append(&csv->csv_string, ch, csv->csv_options); | ||
| 337 | } | ||
| 338 | state = STATE_SIMPLE_FIELD; | ||
| 339 | } | ||
| 340 | break; | ||
| 341 | |||
| 342 | case STATE_QUOTED_FIELD: | ||
| 343 | do { | ||
| 344 | ch = getc(in); | ||
| 345 | if ( ch == EOF ) { | ||
| 346 | state = STATE_END_FILE; | ||
| 347 | } | ||
| 348 | else if ( ch == DELIM ) { | ||
| 349 | ch = getc(in); | ||
| 350 | if ( ch == EOF ) { | ||
| 351 | state = STATE_END_FILE; | ||
| 352 | } | ||
| 353 | else if ( ch == DELIM ) { | ||
| 354 | csv_string_append(&csv->csv_string, DELIM, csv->csv_options); | ||
| 355 | } | ||
| 356 | else if ( ch == SEP ) { | ||
| 357 | state = STATE_END_FIELD; | ||
| 358 | } | ||
| 359 | else if ( ch == '\r' ) { | ||
| 360 | ch = getc(in); | ||
| 361 | if ( ch != '\n' ) { | ||
| 362 | (void) ungetc(ch, in); | ||
| 363 | } | ||
| 364 | state = STATE_END_LINE; | ||
| 365 | } | ||
| 366 | else if ( ch == '\n' ) { | ||
| 367 | state = STATE_END_LINE; | ||
| 368 | } | ||
| 369 | else { | ||
| 370 | csv_string_append(&csv->csv_string, DELIM, csv->csv_options); | ||
| 371 | (void) ungetc(ch, in); // we have read too far... Put the character back! | ||
| 372 | } | ||
| 373 | } | ||
| 374 | else { | ||
| 375 | if ( ch != '\0' ) { | ||
| 376 | csv_string_append(&csv->csv_string, ch, csv->csv_options); | ||
| 377 | } | ||
| 378 | } | ||
| 379 | } while ( state == STATE_QUOTED_FIELD ); | ||
| 380 | break; | ||
| 381 | |||
| 382 | case STATE_SIMPLE_FIELD: | ||
| 383 | do { | ||
| 384 | ch = getc(in); | ||
| 385 | if ( ch == EOF ) { | ||
| 386 | state = STATE_END_FILE; | ||
| 387 | } | ||
| 388 | else if ( ch == SEP ) { | ||
| 389 | state = STATE_END_FIELD; | ||
| 390 | } | ||
| 391 | else if ( ch == '\r' ) { | ||
| 392 | ch = getc(in); | ||
| 393 | if ( ch != '\n' ) { | ||
| 394 | (void) ungetc(ch, in); | ||
| 395 | } | ||
| 396 | state = STATE_END_LINE; | ||
| 397 | } | ||
| 398 | else if ( ch == '\n' ) { | ||
| 399 | state = STATE_END_LINE; | ||
| 400 | } | ||
| 401 | else { | ||
| 402 | if ( ch != '\0' ) { | ||
| 403 | csv_string_append(&csv->csv_string, ch, csv->csv_options); | ||
| 404 | } | ||
| 405 | } | ||
| 406 | } while ( state == STATE_SIMPLE_FIELD ); | ||
| 407 | break; | ||
| 408 | |||
| 409 | case STATE_END_FIELD: | ||
| 410 | csv_string_append(&csv->csv_string, '\0', csv->csv_options); | ||
| 411 | state = STATE_START_FIELD; | ||
| 412 | break; | ||
| 413 | |||
| 414 | case STATE_END_LINE: | ||
| 415 | csv_string_append(&csv->csv_string, '\0', csv->csv_options); | ||
| 416 | return csv->csv_field.pos; | ||
| 417 | |||
| 418 | case STATE_END_FILE: | ||
| 419 | if ( ferror(in) ) { | ||
| 420 | csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); | ||
| 421 | return 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | if ( csv_string_isempty(&csv->csv_string) ) { | ||
| 425 | csv_cleanup(csv); | ||
| 426 | return 0; // EOF reached | ||
| 427 | } | ||
| 428 | |||
| 429 | /* | ||
| 430 | * The last data record was not terminated with a NEWLINE-Symbol. | ||
| 431 | * So we can't signal End-Of-File for now. Terminate the current | ||
| 432 | * field and return the number of fields processed so far. | ||
| 433 | */ | ||
| 434 | csv_string_append(&csv->csv_string, '\0', csv->csv_options); | ||
| 435 | |||
| 436 | return csv->csv_field.pos; | ||
| 437 | |||
| 438 | default: | ||
| 439 | assert(!"this should never be happen..."); | ||
| 440 | break; | ||
| 441 | } | ||
| 442 | } | ||
| 443 | // NOT REACHED | ||
| 444 | } | ||
| 445 | |||
| 446 | const char * | ||
| 447 | csv_err_str(csv_err_t csv_err) | ||
| 448 | { | ||
| 449 | switch ( csv_err ) { | ||
| 450 | case CSV_ERR_OK: | ||
| 451 | return "no error"; | ||
| 452 | case CSV_ERR_OUT_OF_MEMORY: | ||
| 453 | return "out of memory"; | ||
| 454 | case CSV_ERR_OUT_OF_RANGE: | ||
| 455 | return "index out of range"; | ||
| 456 | case CSV_ERR_IO_READ: | ||
| 457 | return "read error"; | ||
| 458 | case CSV_ERR_IO_WRITE: | ||
| 459 | return "write error"; | ||
| 460 | default: | ||
| 461 | return "unknown error"; | ||
| 462 | } | ||
| 463 | // NOT REACHED | ||
| 464 | } | ||
