X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=fusefile.c;h=9e5cb45d835b771e73548b8b443461474fcaa487;hb=1cc0d530755f2869ed083aadb0f9898edb37e9f1;hp=5f7850ba106e2dd9d60278d9bfc2ceb5208f3070;hpb=2c3cea697eeba53a967bea599bb45bbe54f8bd8d;p=rrq%2Ffusefile.git diff --git a/fusefile.c b/fusefile.c index 5f7850b..9e5cb45 100644 --- a/fusefile.c +++ b/fusefile.c @@ -295,8 +295,14 @@ static int RANGE(int s,int n ) { static int setup_source(struct Source *p,char *frag) { struct stat filestat; // Open the fragment file rw if possible, else ro - range = strrchr( frag, '/' ); // last '/' - p->filename = range? strndup( frag, range - frag ) : frag; + // First try the fragment in full, thereafter with range appendix + if ( stat( frag, &filestat ) == 0 ) { + p->filename = strdup( frag ); + range = 0; + } else { + range = strrchr( frag, '/' ); // last '/' + p->filename = range? strndup( frag, range - frag ) : frag; + } p->fd = open( p->filename, O_RDWR ); int rdonly = 0; if ( p->fd < 0 ) { @@ -307,7 +313,7 @@ static int setup_source(struct Source *p,char *frag) { perror( p->filename ); return 1; // Error return } - if ( stat( p->filename, &filestat ) ) { + if ( ( range == 0 ) && stat( p->filename, &filestat ) ) { perror( p->filename ); return 1; } @@ -327,21 +333,21 @@ static int setup_source(struct Source *p,char *frag) { p->to = filestat.st_size; // Process any range variation if ( range && *(++range) ) { - int a,b; + long int a,b; if ( 0 ) { - } else if ( RANGE( sscanf( range, "%d:%d%n", &a, &b, &c ), 2 )) { + } else if ( RANGE( sscanf( range, "%ld:%ld%n", &a, &b, &c ), 2 )) { p->from = ( a < 0 )? ( p->to + a ) : a; p->to = ( b < 0 )? ( p->to + b ) : b; - } else if ( RANGE( sscanf( range, "%d+%d%n", &a, &b, &c ), 2 )) { + } else if ( RANGE( sscanf( range, "%ld+%ld%n", &a, &b, &c ), 2 )) { p->from = ( a < 0 )? ( p->to + a ) : a; p->to = ( ( b < 0 )? p->to : p->from ) + b; - } else if ( RANGE( sscanf( range, "%d+%n", &a, &c ), 1 )) { + } else if ( RANGE( sscanf( range, "%ld+%n", &a, &c ), 1 )) { p->from = ( a < 0 )? ( p->to + a ) : a; - } else if ( RANGE( sscanf( range, ":%d%n", &b, &c ), 1 )) { + } else if ( RANGE( sscanf( range, ":%ld%n", &b, &c ), 1 )) { p->to = ( b < 0 )? ( p->to + b ) : b; - } else if ( RANGE( sscanf( range, "%d:%n", &a, &c ), 1 )) { + } else if ( RANGE( sscanf( range, "%ld:%n", &a, &c ), 1 )) { p->from = ( a < 0 )? ( p->to + a ) : a; - } else if ( RANGE( sscanf( range, "%d%n", &a, &c ), 1 )) { + } else if ( RANGE( sscanf( range, "%ld%n", &a, &c ), 1 )) { if ( a >= 0 ) { p->from = a; } else { @@ -814,7 +820,7 @@ static int dump_fragments() { sources.array[ src ].to ); pos = ENDSOURCE( sources.array[ src ] ); } - if ( sources.array[ src ].start < x ) { + if ( ( src < sources.count ) && ( sources.array[ src ].start < x ) ) { // Dump sources.array[src] up to x; fprintf( stdout, "%s/%ld:%ld\n", sources.array[ src ].filename,