summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--csv-perf.c8
-rw-r--r--csv-test.c14
-rw-r--r--csv.c8
3 files changed, 15 insertions, 15 deletions
diff --git a/csv-perf.c b/csv-perf.c
index efd2155..ddb4808 100644
--- a/csv-perf.c
+++ b/csv-perf.c
@@ -13,7 +13,7 @@ test(FILE *f)
13 int line = 0; 13 int line = 0;
14 csv_t csv = { 0 }; 14 csv_t csv = { 0 };
15 15
16 while ( csv_read(&csv, f) != -1 ) { 16 while ( csv_read(&csv, f) != EOF ) {
17 ++line; 17 ++line;
18 } 18 }
19 19
@@ -27,7 +27,7 @@ test_exception(FILE *f)
27 csv_t csv[1]; 27 csv_t csv[1];
28 28
29 csv_init(csv); 29 csv_init(csv);
30 for ( int n; (n = csv_read(csv, f)) != -1; ) { 30 for ( int n; (n = csv_read(csv, f)) != EOF; ) {
31 if (++line == 500000) csv_field(csv, -1); 31 if (++line == 500000) csv_field(csv, -1);
32 } 32 }
33 33
@@ -52,7 +52,7 @@ test_exception_with_signal(FILE *f)
52 csv_t csv[1]; 52 csv_t csv[1];
53 53
54 csv_init(csv); 54 csv_init(csv);
55 for ( int n; (n = csv_read(csv, f)) != -1; ) { 55 for ( int n; (n = csv_read(csv, f)) != EOF; ) {
56 if (++line == 500000) csv_field(csv, -1); 56 if (++line == 500000) csv_field(csv, -1);
57 } 57 }
58 58
@@ -88,7 +88,7 @@ test_exception_longjmp(FILE *f)
88 if ( setjmp(env) == 0 ) { 88 if ( setjmp(env) == 0 ) {
89 int line = 0; 89 int line = 0;
90 90
91 for ( int n; (n = csv_read(csv, f)) != -1; ) { 91 for ( int n; (n = csv_read(csv, f)) != EOF; ) {
92 // process data... 92 // process data...
93 if (++line == 500000) csv_field(csv, -1); 93 if (++line == 500000) csv_field(csv, -1);
94 } 94 }
diff --git a/csv-test.c b/csv-test.c
index c5152ea..552bbb8 100644
--- a/csv-test.c
+++ b/csv-test.c
@@ -39,7 +39,7 @@ test_line_endings1(void)
39 assert( strcmp(csv_field(&csv, 1), "E") == 0 ); 39 assert( strcmp(csv_field(&csv, 1), "E") == 0 );
40 assert( strcmp(csv_field(&csv, 2), "F") == 0 ); 40 assert( strcmp(csv_field(&csv, 2), "F") == 0 );
41 41
42 assert( csv_read(&csv, f) == -1 ); 42 assert( csv_read(&csv, f) == EOF );
43 43
44 FMEMCLOSE(f); 44 FMEMCLOSE(f);
45} 45}
@@ -67,7 +67,7 @@ test_line_endings2(void)
67 assert( strcmp(csv_field(&csv, 1), "E") == 0 ); 67 assert( strcmp(csv_field(&csv, 1), "E") == 0 );
68 assert( strcmp(csv_field(&csv, 2), "F") == 0 ); 68 assert( strcmp(csv_field(&csv, 2), "F") == 0 );
69 69
70 assert( csv_read(&csv, f) == -1 ); 70 assert( csv_read(&csv, f) == EOF );
71 71
72 FMEMCLOSE(f); 72 FMEMCLOSE(f);
73} 73}
@@ -216,7 +216,7 @@ test_empty_fields(void)
216 assert( strcmp(csv_field(&csv, 2), "") == 0 ); 216 assert( strcmp(csv_field(&csv, 2), "") == 0 );
217 217
218 // EOF 218 // EOF
219 assert( csv_read(&csv, f) == -1 ); 219 assert( csv_read(&csv, f) == EOF );
220 220
221 FMEMCLOSE(f); 221 FMEMCLOSE(f);
222} 222}
@@ -365,7 +365,7 @@ test_simple_fields(void)
365 assert( strcmp(csv_field(&csv, 2), "C") == 0 ); 365 assert( strcmp(csv_field(&csv, 2), "C") == 0 );
366 366
367 // EOF 367 // EOF
368 assert( csv_read(&csv, f) == -1 ); 368 assert( csv_read(&csv, f) == EOF );
369 369
370 FMEMCLOSE(f); 370 FMEMCLOSE(f);
371} 371}
@@ -388,7 +388,7 @@ test_quoted_fields(void)
388 assert( strcmp(csv_field(&csv, 3), "foo \"baz\" bar") == 0 ); 388 assert( strcmp(csv_field(&csv, 3), "foo \"baz\" bar") == 0 );
389 assert( strcmp(csv_field(&csv, 4), "foo \"baz\", bar") == 0 ); 389 assert( strcmp(csv_field(&csv, 4), "foo \"baz\", bar") == 0 );
390 390
391 assert( csv_read(&csv, f) == -1 ); 391 assert( csv_read(&csv, f) == EOF );
392 392
393 FMEMCLOSE(f); 393 FMEMCLOSE(f);
394} 394}
@@ -407,7 +407,7 @@ test_wrong_quoted_field(void)
407 assert( csv_nfields(&csv) == 1 ), 407 assert( csv_nfields(&csv) == 1 ),
408 assert( strcmp(csv_field(&csv, 0), "foo") == 0 ); 408 assert( strcmp(csv_field(&csv, 0), "foo") == 0 );
409 409
410 assert( csv_read(&csv, f) == -1 ); 410 assert( csv_read(&csv, f) == EOF );
411 411
412 FMEMCLOSE(f); 412 FMEMCLOSE(f);
413} 413}
@@ -471,7 +471,7 @@ test_read_error(void)
471 471
472 switch ( setjmp(env) ) { 472 switch ( setjmp(env) ) {
473 case CSV_ERR_OK: 473 case CSV_ERR_OK:
474 assert( csv_read(&csv, f) == -1 ); 474 assert( csv_read(&csv, f) == EOF );
475 break; 475 break;
476 476
477 case CSV_ERR_IO_READ: 477 case CSV_ERR_IO_READ:
diff --git a/csv.c b/csv.c
index 430630b..71c0e0f 100644
--- a/csv.c
+++ b/csv.c
@@ -291,13 +291,13 @@ csv_read(csv_t *csv, FILE *in)
291 291
292 if ( ferror(in) ) { 292 if ( ferror(in) ) {
293 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); 293 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options);
294 return -1; 294 return EOF;
295 } 295 }
296 296
297 // do not try to read if EOF has already been seen 297 // do not try to read if EOF has already been seen
298 if ( feof(in) ) { 298 if ( feof(in) ) {
299 csv_cleanup(csv); 299 csv_cleanup(csv);
300 return -1; 300 return EOF;
301 } 301 }
302 302
303 enum { 303 enum {
@@ -429,12 +429,12 @@ csv_read(csv_t *csv, FILE *in)
429 case STATE_END_FILE: 429 case STATE_END_FILE:
430 if ( ferror(in) ) { 430 if ( ferror(in) ) {
431 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); 431 csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options);
432 return -1; 432 return EOF;
433 } 433 }
434 434
435 if ( csv_string_empty(&csv->csv_string) ) { 435 if ( csv_string_empty(&csv->csv_string) ) {
436 csv_cleanup(csv); 436 csv_cleanup(csv);
437 return -1; // EOF reached 437 return EOF; // EOF reached
438 } 438 }
439 439
440 /* 440 /*