61 |
|
if (expected_length <= 0) { /* need to sniff file? */ |
62 |
|
extern const char HDRSTR[]; |
63 |
|
const int len = strlen(HDRSTR); |
64 |
< |
n = read(fd, buf, len+1); |
65 |
< |
if (n < len+1) |
64 |
> |
if (read(fd, buf, len+1) < len+1) |
65 |
|
goto gotEOF; |
66 |
|
if (lseek(fd, 0, SEEK_SET) != 0) |
67 |
|
goto seek_error; |
68 |
|
for (n = 0; n < len; n++) |
69 |
|
if (buf[n] != HDRSTR[n]) |
70 |
|
break; |
71 |
< |
if (n < len || !isprint(buf[len])) |
71 |
> |
if ((n < len) | !isprint(buf[len])) |
72 |
|
return(fd); /* unknown length raw float... */ |
73 |
|
} else { |
74 |
|
off_t flen = lseek(fd, 0, SEEK_END); |
91 |
|
fclose(dc.finp); /* already reported error */ |
92 |
|
return(-1); |
93 |
|
} |
94 |
< |
if (expected_length > 0 && (long)dc.res.xr*dc.res.yr != expected_length) { |
94 |
> |
if ((expected_length > 0) & |
95 |
> |
((long)dc.res.xr*dc.res.yr != expected_length)) { |
96 |
|
fprintf(stderr, "%s: expected length is %ld, actual length is %ld\n", |
97 |
< |
fname, (long)expected_length, (long)dc.res.xr*dc.res.yr); |
97 |
> |
fname, expected_length, (long)dc.res.xr*dc.res.yr); |
98 |
|
fclose(dc.finp); |
99 |
|
return(-1); |
100 |
|
} |
101 |
|
strcpy(buf, TEMPLATE); /* create temporary file to hold raw */ |
102 |
|
fd = mkstemp(buf); |
103 |
|
if (fd < 0) { |
104 |
< |
fputs(buf, stderr); |
105 |
< |
fputs(": cannot create temporary file\n", stderr); |
104 |
> |
perror(buf); |
105 |
|
fclose(dc.finp); |
106 |
|
return(-1); |
107 |
|
} |
108 |
< |
unlink(buf); /* unlink it now (Windows forbids) */ |
108 |
> |
unlink(buf); /* preemptive remove (Windows forbids) */ |
109 |
|
for (nleft = (ssize_t)dc.res.xr*dc.res.yr; nleft > 0; nleft -= FBUFLEN) { |
110 |
|
for (n = 0; n < FBUFLEN; n++) { |
111 |
|
double d = decode_depth_next(&dc); |
114 |
|
goto gotEOF; |
115 |
|
break; |
116 |
|
} |
117 |
< |
((float *)buf)[n] = (float)d; |
117 |
> |
((float *)buf)[n] = d; |
118 |
|
} |
119 |
|
n *= sizeof(float); |
120 |
|
if (write(fd, buf, n) != n) { |