more argument polishing
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 17 Jul 2022 05:01:22 +0000 (15:01 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 17 Jul 2022 05:01:22 +0000 (15:01 +1000)
fusefile.c

index 9c4b9648d226d11fb6a42c43e56ab5ac78447079..0936da92219a0e5877679c1bdbae2fc91d1680e6 100644 (file)
@@ -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;