From: Ralph Ronnquist Date: Sun, 17 Jul 2022 05:01:22 +0000 (+1000) Subject: more argument polishing X-Git-Tag: 0.4~3 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=bcaeffd9fc73b359636ff32629fc07374c50cf16;hp=7059a8375f259a9d739fe6a642d0162ee83c30c8;p=rrq%2Ffusefile.git more argument polishing --- diff --git a/fusefile.c b/fusefile.c index 9c4b964..0936da9 100644 --- a/fusefile.c +++ b/fusefile.c @@ -117,10 +117,10 @@ static int setup_sources(char **argv,int i,int n) { } else if ( RANGE( sscanf( range, "%d:%n", &a, &c ), 1 )) { p->from = ( a < 0 )? ( p->to + a ) : a; } else if ( RANGE( sscanf( range, "%d%n", &a, &c ), 1 )) { - if ( a < 0 ) { - p->from = p->to + a; + if ( a >= 0 ) { + p->from = a; } else { - p->to = p->from + a; + p->from = p->to + a; } } else if ( RANGE( sscanf( range, ":%n", &c), 0 ) ) { // to end from start @@ -129,8 +129,16 @@ static int setup_sources(char **argv,int i,int n) { return 1; } } - if ( p->from >= p->to || - p->from >= filestat.st_size || p->to > filestat.st_size ) { + if ( ( filestat.st_mode & S_IFMT ) == S_IFCHR ) { + filestat.st_size = p->to; // Pretend size of character device + } + if ( p->from < 0 ) { + p->from = 0; + } + if ( p->to > filestat.st_size ) { + p->to = filestat.st_size; + } + if ( p->from >= p->to || p->from >= filestat.st_size ) { fprintf( stderr, "** BAD RANGE: %s [%ld:%ld]\n", argv[i], p->from, p->to ); return 1;