| 98 |
|
/* check if fseek() useful */ |
| 99 |
|
if (skip_len > skip_thresh && |
| 100 |
|
fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { |
| 101 |
+ |
int fd; |
| 102 |
|
off_t curpos; |
| 103 |
|
buf = (char *)malloc(ncols*elsiz); |
| 104 |
|
if (!buf) |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
|
#else |
| 119 |
+ |
fd = fileno(fp); |
| 120 |
|
curpos = ftello(fp); |
| 121 |
|
for (y = nrows; y-- > 0; curpos += width*elsiz) { |
| 122 |
< |
if (pread(fileno(fp), buf, ncols*elsiz, |
| 122 |
> |
if (pread(fd, buf, ncols*elsiz, |
| 123 |
|
curpos) != ncols*elsiz) |
| 124 |
|
goto readerr; |
| 125 |
|
if (putbinary(buf, elsiz, ncols, stdout) != ncols) |
| 271 |
|
cmin = atoi(argv[2]); |
| 272 |
|
nrows = atoi(argv[3]); |
| 273 |
|
ncols = atoi(argv[4]); |
| 274 |
< |
if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0)) |
| 274 |
> |
if ((rmin < 0) | (cmin < 0)) |
| 275 |
|
goto usage; |
| 276 |
|
if (argc <= 5) |
| 277 |
|
SET_FILE_BINARY(fp); |
| 303 |
|
fputs(": missing input dimensions\n", stderr); |
| 304 |
|
return(1); |
| 305 |
|
} |
| 306 |
< |
if (!nrows) |
| 307 |
< |
nrows = numscans(&res) - rmin; |
| 308 |
< |
if (!ncols) |
| 309 |
< |
ncols = scanlen(&res) - cmin; |
| 306 |
> |
if (nrows <= 0 ) |
| 307 |
> |
nrows += numscans(&res) - rmin; |
| 308 |
> |
if (ncols <= 0) |
| 309 |
> |
ncols += scanlen(&res) - cmin; |
| 310 |
|
if ((nrows <= 0) | (ncols <= 0) | |
| 311 |
|
(rmin+nrows > numscans(&res)) | |
| 312 |
|
(cmin+ncols > scanlen(&res))) { |