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

Comparing ray/src/rt/rpict.c (file contents):
Revision 2.89 by greg, Tue Feb 24 19:39:27 2015 UTC vs.
Revision 2.93 by greg, Sat May 4 00:32:47 2019 UTC

# Line 134 | Line 134 | static int pixnumber(int  x, int  y, int  xres, int  y
134  
135  
136  
137 #ifdef RHAS_STAT
138 #include  <sys/types.h>
139 #include  <sys/stat.h>
140 int
141 file_exists(fname)                              /* ordinary file exists? */
142 char  *fname;
143 {
144        struct stat  sbuf;
145        if (stat(fname, &sbuf) < 0) return(0);
146        return((sbuf.st_mode & S_IFREG) != 0);
147 }
148 #else
149 #define  file_exists(f) (access(f,F_OK)==0)
150 #endif
151
152
137   void
138   quit(code)                      /* quit program */
139   int  code;
# Line 198 | Line 182 | report(int dummy)              /* report progress */
182          pmapBiasCompReport(bcStat);
183          
184          sprintf(errmsg,
185 <                        "%lu rays, %s %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
185 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
186                          nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
187                          (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
188          eputs(errmsg);
# Line 217 | Line 201 | report(int dummy)              /* report progress */
201          /* PMAP: Get photon map bias compensation statistics */
202          pmapBiasCompReport(bcStat);
203          
204 <        sprintf(errmsg, "%lu rays, %s %4.2f%% after %5.4f hours\n",
204 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
205                          nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
206          eputs(errmsg);
207   }
# Line 304 | Line 288 | rpict(                 /* generate image(s) */
288                          break;
289                  pctdone = 0.0;
290                  if (pout != NULL) {
291 +                        int     myfd;
292 +                        close(1);                       /* reassign stdout */
293                          sprintf(fbuf, pout, seq);
294 <                        if (file_exists(fbuf)) {
295 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
294 >                tryagain:
295 >                        errno = 0;                      /* exclusive open */
296 >                        if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
297 >                                if ((errno != EEXIST) | (prvr != NULL) ||
298 >                                                !strcmp(fbuf, pout)) {
299                                          sprintf(errmsg,
300 <                                                "output file \"%s\" exists",
300 >                                                "cannot open output file \"%s\"",
301                                                  fbuf);
302 <                                        error(USER, errmsg);
302 >                                        error(SYSTEM, errmsg);
303                                  }
304                                  setview(&ourview);
305                                  continue;               /* don't clobber */
306                          }
307 <                        if (freopen(fbuf, "w", stdout) == NULL) {
308 <                                sprintf(errmsg,
309 <                                        "cannot open output file \"%s\"", fbuf);
321 <                                error(SYSTEM, errmsg);
307 >                        if (myfd != 1) {
308 >                                unlink(fbuf);
309 >                                goto tryagain;          /* leave it open */
310                          }
311 <                        SET_FILE_BINARY(stdout);
311 >                        SET_FD_BINARY(1);
312                          dupheader();
313                  }
314                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 746 | Line 734 | pixvalue(              /* compute pixel value */
734  
735          copycolor(col, thisray.rcol);           /* return color */
736  
737 <        return(thisray.rt);                     /* return distance */
737 >        return(raydistance(&thisray));          /* return distance */
738   }
739  
740  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines