ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fltdepth.c
(Generate patch)

Comparing ray/src/common/fltdepth.c (file contents):
Revision 3.1 by greg, Thu Nov 7 23:20:28 2019 UTC vs.
Revision 3.4 by greg, Mon Nov 11 16:45:30 2019 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5   * Function to open floating-point depth file, making sure it's
6   * the correct length, and converting from encoded 16-bit
# Line 19 | Line 22 | open_float_depth(const char *fname, long expected_leng
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)) {
# Line 52 | Line 57 | open_float_depth(const char *fname, long expected_leng
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 <                n = read(fd, buf, len+1);
69 <                if (n < len+1)
63 <                        goto gotEOF;
68 >                if (read(fd, buf, len+1) < len+1)
69 >                        goto badEOF;
70                  if (lseek(fd, 0, SEEK_SET) != 0)
71                          goto seek_error;
72                  for (n = 0; n < len; n++)
73                          if (buf[n] != HDRSTR[n])
74                                  break;
75 <                if (n < len || !isprint(buf[len]))      
75 >                if ((n < len) | !isprint(buf[len]))    
76                          return(fd);     /* unknown length raw float... */
77          } else {
78                  off_t   flen = lseek(fd, 0, SEEK_END);
# Line 89 | Line 95 | open_float_depth(const char *fname, long expected_leng
95                  fclose(dc.finp);        /* already reported error */
96                  return(-1);
97          }
98 <        if (expected_length > 0 && (long)dc.res.xr*dc.res.yr != expected_length) {
98 >        if ((expected_length > 0) &
99 >                        ((long)dc.res.xr*dc.res.yr != expected_length)) {
100                  fprintf(stderr, "%s: expected length is %ld, actual length is %ld\n",
101 <                                fname, (long)expected_length, (long)dc.res.xr*dc.res.yr);
101 >                                fname, expected_length, (long)dc.res.xr*dc.res.yr);
102                  fclose(dc.finp);
103                  return(-1);
104          }
105          strcpy(buf, TEMPLATE);          /* create temporary file to hold raw */
106          fd = mkstemp(buf);
107          if (fd < 0) {
108 <                fputs(buf, stderr);
102 <                fputs(": cannot create temporary file\n", stderr);
108 >                perror(buf);
109                  fclose(dc.finp);
110                  return(-1);
111          }
112 <        unlink(buf);                    /* unlink it now (Windows forbids) */
112 >        unlink(buf);                    /* preemptive remove (Windows forbids) */
113          for (nleft = (ssize_t)dc.res.xr*dc.res.yr; nleft > 0; nleft -= FBUFLEN) {
114                  for (n = 0; n < FBUFLEN; 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] = (float)d;
121 >                        ((float *)buf)[n] = d;
122                  }
123                  n *= sizeof(float);
124                  if (write(fd, buf, n) != n) {
# Line 126 | Line 132 | open_float_depth(const char *fname, long expected_leng
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);
# Line 138 | Line 144 | seek_error:
144          return(-1);
145   }
146  
147 < #endif
147 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines