94 |
|
|
95 |
|
double pixvalue(); |
96 |
|
|
97 |
+ |
#ifdef NIX |
98 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
99 |
+ |
#else |
100 |
+ |
#include <sys/types.h> |
101 |
+ |
#include <sys/stat.h> |
102 |
+ |
int |
103 |
+ |
file_exists(fname) /* ordinary file exists? */ |
104 |
+ |
char *fname; |
105 |
+ |
{ |
106 |
+ |
struct stat sbuf; |
107 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
108 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
109 |
+ |
} |
110 |
+ |
#endif |
111 |
|
|
112 |
+ |
|
113 |
|
quit(code) /* quit program */ |
114 |
|
int code; |
115 |
|
{ |
205 |
|
cp--; |
206 |
|
strcpy(cp, RFTEMPLATE); |
207 |
|
prvr = mktemp(fbuf2); |
208 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
209 |
< |
sprintf(errmsg, |
208 |
> |
if (rename(fbuf, prvr) < 0) |
209 |
> |
if (errno == ENOENT) { /* ghost file */ |
210 |
> |
sprintf(errmsg, |
211 |
> |
"new output file \"%s\"", |
212 |
> |
fbuf); |
213 |
> |
error(WARNING, errmsg); |
214 |
> |
prvr = NULL; |
215 |
> |
} else { /* serious error */ |
216 |
> |
sprintf(errmsg, |
217 |
|
"cannot rename \"%s\" to \"%s\"", |
218 |
|
fbuf, prvr); |
219 |
< |
error(SYSTEM, errmsg); |
220 |
< |
} |
219 |
> |
error(SYSTEM, errmsg); |
220 |
> |
} |
221 |
|
} |
222 |
|
} |
223 |
|
npicts = 0; /* render sequence */ |
227 |
|
pctdone = 0.0; |
228 |
|
if (pout != NULL) { |
229 |
|
sprintf(fbuf, pout, seq); |
230 |
< |
if (prvr == NULL && access(fbuf, F_OK) == 0) |
230 |
> |
if (file_exists(fbuf)) { |
231 |
> |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
232 |
> |
sprintf(errmsg, |
233 |
> |
"output file \"%s\" exists", |
234 |
> |
fbuf); |
235 |
> |
error(USER, errmsg); |
236 |
> |
} |
237 |
|
continue; /* don't clobber */ |
238 |
+ |
} |
239 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
240 |
|
sprintf(errmsg, |
241 |
|
"cannot open output file \"%s\"", fbuf); |