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)", |
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) { |
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; |