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.91 by greg, Tue Nov 13 19:58:33 2018 UTC vs.
Revision 2.92 by greg, Thu Mar 21 16:52:40 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 304 | Line 288 | rpict(                 /* generate image(s) */
288                          break;
289                  pctdone = 0.0;
290                  if (pout != NULL) {
291 +                        close(1);                       /* reassign stdout */
292                          sprintf(fbuf, pout, seq);
293 <                        if (file_exists(fbuf)) {
294 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
293 >                        errno = 0;                      /* exclusive open */
294 >                        if (open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666) != 1) {
295 >                                if ((errno != EEXIST) | (prvr != NULL) ||
296 >                                                !strcmp(fbuf, pout)) {
297                                          sprintf(errmsg,
298 <                                                "output file \"%s\" exists",
298 >                                                "cannot open output file \"%s\"",
299                                                  fbuf);
300 <                                        error(USER, errmsg);
300 >                                        error(SYSTEM, errmsg);
301                                  }
302                                  setview(&ourview);
303                                  continue;               /* don't clobber */
304                          }
305 <                        if (freopen(fbuf, "w", stdout) == NULL) {
319 <                                sprintf(errmsg,
320 <                                        "cannot open output file \"%s\"", fbuf);
321 <                                error(SYSTEM, errmsg);
322 <                        }
323 <                        SET_FILE_BINARY(stdout);
305 >                        SET_FD_BINARY(1);
306                          dupheader();
307                  }
308                  hres = hresolu; vres = vresolu; pa = pixaspect;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines