| 39 |
|
#endif |
| 40 |
|
#endif |
| 41 |
|
/* protection from SYSV signals(!) */ |
| 42 |
< |
#if defined(sgi) || defined(hpux) |
| 42 |
> |
#if defined(sgi) |
| 43 |
|
#define guard_io() sighold(SIGALRM) |
| 44 |
|
#define unguard() sigrelse(SIGALRM) |
| 45 |
|
#endif |
| 148 |
|
case 'F': /* syncronization file */ |
| 149 |
|
if (argv[i][2]) |
| 150 |
|
break; |
| 151 |
< |
if ((syncfp = fopen(argv[++i],"r+")) == NULL) { |
| 151 |
> |
if ((syncfp = |
| 152 |
> |
fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { |
| 153 |
|
fprintf(stderr, "%s: cannot open\n", |
| 154 |
|
argv[i]); |
| 155 |
|
exit(1); |
| 187 |
|
int ltyp; |
| 188 |
|
{ |
| 189 |
|
static struct flock fls; /* static so initialized to zeroes */ |
| 190 |
+ |
extern char *sys_errlist[]; |
| 191 |
|
|
| 192 |
|
fls.l_type = ltyp; |
| 193 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
| 194 |
< |
fprintf(stderr, "%s: cannot lock/unlock file\n", progname); |
| 194 |
> |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
| 195 |
> |
progname, sys_errlist[errno]); |
| 196 |
|
exit(1); |
| 197 |
|
} |
| 198 |
|
} |
| 233 |
|
dolock(outfd, F_WRLCK); |
| 234 |
|
if ((fp = fdopen(dup(outfd), "w")) == NULL) |
| 235 |
|
goto filerr; |
| 236 |
< |
printargs(ac, av, fp); /* write header */ |
| 236 |
> |
newheader("RADIANCE", fp); /* create header */ |
| 237 |
> |
printargs(ac, av, fp); |
| 238 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 239 |
|
fputs(VIEWSTR, fp); |
| 240 |
|
fprintview(&ourview, fp); |
| 325 |
|
sflock(F_UNLCK); /* release sync file */ |
| 326 |
|
return(1); |
| 327 |
|
} |
| 328 |
< |
if (scanf("%d %d", xp, yp) == 2) /* use stdin */ |
| 325 |
< |
return(1); |
| 326 |
< |
fprintf(stderr, "%s: input format error\n", progname); |
| 327 |
< |
exit(cleanup(1)); |
| 328 |
> |
return(scanf("%d %d", xp, yp) == 2); /* use stdin */ |
| 329 |
|
} |
| 330 |
|
|
| 331 |
|
|
| 485 |
|
/* lock file section so NFS doesn't mess up */ |
| 486 |
|
fls.l_whence = 0; |
| 487 |
|
fls.l_type = F_WRLCK; |
| 488 |
< |
fcntl(outfd, F_SETLKW, &fls); |
| 488 |
> |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
| 489 |
> |
filerr("lock"); |
| 490 |
|
#endif |
| 491 |
|
/* write new piece to file */ |
| 492 |
|
if (lseek(outfd, fls.l_start, 0) == -1) |
| 493 |
< |
goto seekerr; |
| 493 |
> |
filerr("seek"); |
| 494 |
|
if (hmult == 1) { |
| 495 |
|
if (writebuf(outfd, (char *)pbuf, |
| 496 |
|
vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR)) |
| 497 |
< |
goto writerr; |
| 497 |
> |
filerr("write"); |
| 498 |
|
} else |
| 499 |
|
for (y = 0; y < vr; y++) { |
| 500 |
|
if (writebuf(outfd, (char *)(pbuf+y*hr), |
| 501 |
|
hr*sizeof(COLR)) != hr*sizeof(COLR)) |
| 502 |
< |
goto writerr; |
| 502 |
> |
filerr("write"); |
| 503 |
|
if (y < vr-1 && lseek(outfd, |
| 504 |
|
(long)(hmult-1)*hr*sizeof(COLR), |
| 505 |
|
1) == -1) |
| 506 |
< |
goto seekerr; |
| 506 |
> |
filerr("seek"); |
| 507 |
|
} |
| 508 |
|
#if NFS |
| 509 |
|
fls.l_type = F_UNLCK; /* release lock */ |
| 510 |
< |
fcntl(outfd, F_SETLKW, &fls); |
| 510 |
> |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
| 511 |
> |
filerr("lock"); |
| 512 |
|
#endif |
| 513 |
|
if (syncfp != NULL) { /* record what's been done */ |
| 514 |
|
sflock(F_WRLCK); |
| 525 |
|
if (pid == -1) /* didn't fork or fork failed */ |
| 526 |
|
return(0); |
| 527 |
|
_exit(0); /* else exit child process (releasing locks) */ |
| 528 |
< |
seekerr: |
| 529 |
< |
fprintf(stderr, "%s: seek error on file \"%s\"\n", progname, outfile); |
| 530 |
< |
_exit(1); |
| 531 |
< |
writerr: |
| 532 |
< |
fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); |
| 528 |
> |
} |
| 529 |
> |
|
| 530 |
> |
|
| 531 |
> |
filerr(t) /* report file error and exit */ |
| 532 |
> |
char *t; |
| 533 |
> |
{ |
| 534 |
> |
extern char *sys_errlist[]; |
| 535 |
> |
|
| 536 |
> |
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
| 537 |
> |
progname, t, outfile, sys_errlist[errno]); |
| 538 |
|
_exit(1); |
| 539 |
|
} |
| 540 |
|
|