From 273b2dc26f8de4e9af5613febf5634f6efe9401e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 7 Mar 2010 14:54:12 +0000 Subject: [PATCH] check for \nEOF in im_csv2vips() --- libvips/format/im_csv2vips.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libvips/format/im_csv2vips.c b/libvips/format/im_csv2vips.c index ef78042c..cee47ec9 100644 --- a/libvips/format/im_csv2vips.c +++ b/libvips/format/im_csv2vips.c @@ -60,17 +60,23 @@ #endif /*WITH_DMALLOC*/ /* Skip to the start of the next line (ie. read until we see a '\n'), return - * zero if we are at EOF. Don't forget to allow for lines that are terminated - * by EOF rather than \n. + * zero if we are at EOF. + * + * Files can end with EOF or with \nEOF. Tricky! */ static int skip_line( FILE *fp ) { int ch; - if( feof( fp ) ) + /* Are we at a delayed EOF? See below. + */ + if( (ch = fgetc( fp )) == EOF ) return( 0 ); + ungetc( ch, fp ); + /* If we hit EOF and no \n, wait until the next call to report EOF. + */ while( (ch = fgetc( fp )) != '\n' && ch != EOF ) ; @@ -195,8 +201,10 @@ read_csv( FILE *fp, IMAGE *out, "%s", _( "unable to seek" ) ); return( -1 ); } - for( columns = 0; (ch = read_double( fp, whitemap, sepmap, - start_skip + 1, columns + 1, &d )) == 0; columns++ ) + for( columns = 0; + (ch = read_double( fp, whitemap, sepmap, + start_skip + 1, columns + 1, &d )) == 0; + columns++ ) ; fsetpos( fp, &pos ); @@ -217,6 +225,8 @@ read_csv( FILE *fp, IMAGE *out, for( lines = 0; skip_line( fp ); lines++ ) ; fsetpos( fp, &pos ); + + printf( "detected %d lines after skip\n", lines ); } im_initdesc( out, columns, lines, 1,