| 22 |
|
{ |
| 23 |
|
int fd = open(fname, O_RDONLY|O_BINARY); |
| 24 |
|
|
| 25 |
< |
if (fd < 0) |
| 25 |
> |
if (fd < 0) { |
| 26 |
> |
fprintf(stderr, "%s: cannot open for reading\n", fname); |
| 27 |
|
return(-1); |
| 28 |
+ |
} |
| 29 |
|
if (expected_length > 0) { |
| 30 |
|
off_t flen = lseek(fd, 0, SEEK_END); |
| 31 |
|
if (flen != expected_length*sizeof(float)) { |
| 57 |
|
ssize_t n, nleft; |
| 58 |
|
int fd = open(fname, O_RDONLY); |
| 59 |
|
|
| 60 |
< |
if (fd < 0) |
| 60 |
> |
if (fd < 0) { |
| 61 |
> |
perror(fname); |
| 62 |
|
return(-1); |
| 63 |
+ |
} |
| 64 |
|
dc.finp = NULL; |
| 65 |
|
if (expected_length <= 0) { /* need to sniff file? */ |
| 66 |
|
extern const char HDRSTR[]; |
| 67 |
|
const int len = strlen(HDRSTR); |
| 68 |
|
if (read(fd, buf, len+1) < len+1) |
| 69 |
< |
goto gotEOF; |
| 69 |
> |
goto badEOF; |
| 70 |
|
if (lseek(fd, 0, SEEK_SET) != 0) |
| 71 |
|
goto seek_error; |
| 72 |
|
for (n = 0; n < len; n++) |
| 115 |
|
double d = decode_depth_next(&dc); |
| 116 |
|
if (d < 0) { |
| 117 |
|
if (n < nleft) |
| 118 |
< |
goto gotEOF; |
| 118 |
> |
goto badEOF; |
| 119 |
|
break; |
| 120 |
|
} |
| 121 |
|
((float *)buf)[n] = d; |
| 132 |
|
if (lseek(fd, 0, SEEK_SET) != 0) |
| 133 |
|
goto seek_error; |
| 134 |
|
return(fd); |
| 135 |
< |
gotEOF: |
| 135 |
> |
badEOF: |
| 136 |
|
fputs(fname, stderr); |
| 137 |
|
fputs(": unexpected end-of-file\n", stderr); |
| 138 |
|
if (dc.finp) fclose(dc.finp); |