9 |
|
|
10 |
|
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "ray.h" |
12 |
> |
#include <string.h> |
13 |
|
|
14 |
+ |
#include "platform.h" |
15 |
+ |
#include "ray.h" |
16 |
|
#include "otypes.h" |
15 |
– |
|
17 |
|
#include "ambient.h" |
17 |
– |
|
18 |
|
#include "random.h" |
19 |
|
|
20 |
|
#ifndef OCTSCALE |
158 |
|
} |
159 |
|
/* align file pointer */ |
160 |
|
pos += (long)nambvals*AMBVALSIZ; |
161 |
< |
flen = lseek(fileno(ambfp), (off_t)0L, 2); |
161 |
> |
flen = lseek(fileno(ambfp), (off_t)0, SEEK_END); |
162 |
|
if (flen != pos) { |
163 |
|
sprintf(errmsg, |
164 |
|
"ignoring last %ld values in ambient file (corrupted)", |
165 |
|
(flen - pos)/AMBVALSIZ); |
166 |
|
error(WARNING, errmsg); |
167 |
|
fseek(ambfp, pos, 0); |
168 |
+ |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
169 |
|
ftruncate(fileno(ambfp), (off_t)pos); |
170 |
+ |
#endif |
171 |
|
} |
172 |
|
} else if ((ambfp = fopen(ambfile, "w+")) != NULL) { |
173 |
|
initambfile(1); /* else create new file */ |
280 |
|
return; |
281 |
|
dumbamb: /* return global value */ |
282 |
|
copycolor(acol, ambval); |
283 |
< |
if (ambvwt <= 0 | navsum == 0) |
283 |
> |
if ((ambvwt <= 0) | (navsum == 0)) |
284 |
|
return; |
285 |
|
l = bright(ambval); /* average in computations */ |
286 |
|
if (l > FTINY) { |
476 |
|
#ifdef F_SETLKW |
477 |
|
aflock(creat ? F_WRLCK : F_RDLCK); |
478 |
|
#endif |
479 |
< |
#ifdef MSDOS |
478 |
< |
setmode(fileno(ambfp), O_BINARY); |
479 |
< |
#endif |
479 |
> |
SET_FILE_BINARY(ambfp); |
480 |
|
if (mybuf == NULL) |
481 |
|
mybuf = (char *)bmalloc(BUFSIZ+8); |
482 |
|
setbuf(ambfp, mybuf); |
529 |
|
|
530 |
|
if ((av = newambval()) == NULL) |
531 |
|
error(SYSTEM, "out of memory in avstore"); |
532 |
< |
copystruct(av, aval); |
532 |
> |
*av = *aval; |
533 |
|
av->latick = ambclock; |
534 |
|
av->next = NULL; |
535 |
|
nambvals++; |
564 |
|
} |
565 |
|
atp = atfreelist; |
566 |
|
atfreelist = atp->kid; |
567 |
< |
bzero((char *)atp, 8*sizeof(AMBTREE)); |
567 |
> |
memset((char *)atp, '\0', 8*sizeof(AMBTREE)); |
568 |
|
return(atp); |
569 |
|
} |
570 |
|
|
741 |
|
if (avlist2 != NULL) |
742 |
|
free((void *)avlist2); |
743 |
|
if (always) { /* rebuild without sorting */ |
744 |
< |
copystruct(&oldatrunk, &atrunk); |
744 |
> |
oldatrunk = atrunk; |
745 |
|
atrunk.alist = NULL; |
746 |
|
atrunk.kid = NULL; |
747 |
|
unloadatree(&oldatrunk, avinsert); |
772 |
|
if (avlist1[i].p == NULL) |
773 |
|
continue; |
774 |
|
tap = avlist2[i]; |
775 |
< |
copystruct(&tav, tap); |
775 |
> |
tav = *tap; |
776 |
|
for (j = i; (pnext = avlist1[j].p) != tap; |
777 |
|
j = avlmemi(pnext)) { |
778 |
< |
copystruct(avlist2[j], pnext); |
778 |
> |
*(avlist2[j]) = *pnext; |
779 |
|
avinsert(avlist2[j]); |
780 |
|
avlist1[j].p = NULL; |
781 |
|
} |
782 |
< |
copystruct(avlist2[j], &tav); |
782 |
> |
*(avlist2[j]) = tav; |
783 |
|
avinsert(avlist2[j]); |
784 |
|
avlist1[j].p = NULL; |
785 |
|
} |
829 |
|
/* gain exclusive access */ |
830 |
|
aflock(F_WRLCK); |
831 |
|
/* see if file has grown */ |
832 |
< |
if ((flen = lseek(fileno(ambfp), (off_t)0L, 2)) < 0) |
832 |
> |
if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0) |
833 |
|
goto seekerr; |
834 |
< |
if (n = flen - lastpos) { /* file has grown */ |
834 |
> |
if ( (n = flen - lastpos) ) { /* file has grown */ |
835 |
|
if (ambinp == NULL) { /* use duplicate filedes */ |
836 |
|
ambinp = fdopen(dup(fileno(ambfp)), "r"); |
837 |
|
if (ambinp == NULL) |
852 |
|
} |
853 |
|
/*** seek always as safety measure |
854 |
|
if (n) ***/ /* alignment */ |
855 |
< |
if (lseek(fileno(ambfp), (off_t)(flen-n), 0) < 0) |
855 |
> |
if (lseek(fileno(ambfp), (off_t)(flen-n), SEEK_SET) < 0) |
856 |
|
goto seekerr; |
857 |
|
} |
858 |
|
#ifdef DEBUG |
865 |
|
#endif |
866 |
|
syncend: |
867 |
|
n = fflush(ambfp); /* calls write() at last */ |
868 |
< |
if ((lastpos = lseek(fileno(ambfp), (off_t)0L, 1)) < 0) |
868 |
> |
if ((lastpos = lseek(fileno(ambfp), (off_t)0, SEEK_CUR)) < 0) |
869 |
|
goto seekerr; |
870 |
|
aflock(F_UNLCK); /* release file */ |
871 |
|
nunflshed = 0; |