X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;ds=sidebyside;f=fusefile.c;h=0936da92219a0e5877679c1bdbae2fc91d1680e6;hb=1bf026d416e3935c23c0f33eb32b337bec460558;hp=9c4b9648d226d11fb6a42c43e56ab5ac78447079;hpb=7059a8375f259a9d739fe6a642d0162ee83c30c8;p=rrq%2Ffusefile.git 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;