13 |
|
|
14 |
|
#include "holo.h" |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
+ |
|
18 |
|
#ifndef CACHESIZE |
19 |
|
#ifdef SMLMEM |
20 |
|
#define CACHESIZE 5 |
135 |
|
} |
136 |
|
hdfragl[fd].nlinks++; |
137 |
|
hdfragl[fd].writable = wr; /* set writable flag */ |
138 |
< |
hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ |
138 |
> |
/* get file length */ |
139 |
> |
hdfragl[fd].flen = lseek(fd, (off_t)0, SEEK_END); |
140 |
|
} |
141 |
|
|
142 |
|
|
168 |
|
register int n; |
169 |
|
/* prepare for system errors */ |
170 |
|
errno = 0; |
171 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
171 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
172 |
|
error(SYSTEM, "cannot determine holodeck file position"); |
173 |
|
if (hproto == NULL) { /* assume we're loading it */ |
174 |
|
HDGRID hpr; |
193 |
|
if (fd < nhdfragls && hdfragl[fd].nlinks) |
194 |
|
writable = hdfragl[fd].writable; |
195 |
|
else |
196 |
< |
writable = lseek(fd, fpos, 0) == fpos && |
196 |
> |
writable = lseek(fd, fpos, SEEK_SET) == fpos && |
197 |
|
write(fd, (char *)hp, sizeof(HDGRID)) == |
198 |
|
sizeof(HDGRID); |
199 |
|
} else { /* else assume we're creating it */ |
250 |
|
register int j; |
251 |
|
|
252 |
|
if (!hp->dirty++) { /* write smudge first time */ |
253 |
< |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 |
254 |
< |
|| write(hp->fd, (char *)&smudge, |
253 |
> |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), |
254 |
> |
SEEK_SET) < 0 || |
255 |
> |
write(hp->fd, (char *)&smudge, |
256 |
|
sizeof(BEAMI)) != sizeof(BEAMI)) |
257 |
|
error(SYSTEM, "seek/write error in hdmarkdirty"); |
258 |
|
hp->dirseg[0].s = i; |
315 |
|
errno = 0; /* write dirty segments */ |
316 |
|
for (j = 0; j < hp->dirty; j++) { |
317 |
|
if (lseek(hp->fd, biglob(hp)->fo + |
318 |
< |
(hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) |
318 |
> |
(hp->dirseg[j].s-1)*sizeof(BEAMI), SEEK_SET) < 0) |
319 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
320 |
|
n = hp->dirseg[j].n * sizeof(BEAMI); |
321 |
|
if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) |
364 |
|
if (fd < 0) |
365 |
|
return(-1); |
366 |
|
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
367 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
367 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
368 |
|
return(-1); |
369 |
< |
flen = lseek(fd, (off_t)0, 2); |
370 |
< |
lseek(fd, fpos, 0); |
369 |
> |
flen = lseek(fd, (off_t)0, SEEK_END); |
370 |
> |
lseek(fd, fpos, SEEK_SET); |
371 |
|
return(flen); |
372 |
|
} |
373 |
|
return(hdfragl[fd].flen); |
422 |
|
blglob(hp)->nrm += n; |
423 |
|
if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { |
424 |
|
errno = 0; |
425 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
425 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
426 |
|
error(SYSTEM, "seek error on holodeck file"); |
427 |
|
n *= sizeof(RAYVAL); |
428 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
461 |
|
hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); |
462 |
|
blglob(hp)->nrm += hp->bl[i]->nrm = n; |
463 |
|
errno = 0; |
464 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
464 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
465 |
|
error(SYSTEM, "seek error on holodeck file"); |
466 |
|
n *= sizeof(RAYVAL); |
467 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
692 |
|
if (nrays) { /* get and write new fragment */ |
693 |
|
nfo = hdallocfrag(hp->fd, nrays); |
694 |
|
errno = 0; |
695 |
< |
if (lseek(hp->fd, nfo, 0) < 0) |
695 |
> |
if (lseek(hp->fd, nfo, SEEK_SET) < 0) |
696 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
697 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
698 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |