} 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
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;