1 |
– |
/* Copyright (c) 1999 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines for managing holodeck files |
6 |
|
* |
78 |
|
/* allocate and clear beam list */ |
79 |
|
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
80 |
|
if (hp->bl == NULL) { |
81 |
< |
free((char *)hp); |
81 |
> |
free((void *)hp); |
82 |
|
return(NULL); |
83 |
|
} |
84 |
|
bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
101 |
|
register char *newp; |
102 |
|
/* call malloc/realloc */ |
103 |
|
if (ptr == NULL) newp = (char *)malloc(siz); |
104 |
< |
else newp = (char *)realloc(ptr, siz); |
104 |
> |
else newp = (char *)realloc((void *)ptr, siz); |
105 |
|
/* check success */ |
106 |
|
if (newp == NULL && rout != NULL) { |
107 |
|
hdfreecache(25, NULL); /* free some memory */ |
129 |
|
} |
130 |
|
hdfragl[fd].nlinks++; |
131 |
|
hdfragl[fd].writable = wr; /* set writable flag */ |
132 |
< |
hdfragl[fd].flen = lseek(fd, 0L, 2); /* get file length */ |
132 |
> |
hdfragl[fd].flen = lseek(fd, (off_t)0L, 2); /* get file length */ |
133 |
|
} |
134 |
|
|
135 |
|
|
142 |
|
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
143 |
|
return; |
144 |
|
if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { |
145 |
< |
free((char *)hdfragl[fd].fi); |
145 |
> |
free((void *)hdfragl[fd].fi); |
146 |
|
hdfragl[fd].fi = NULL; |
147 |
|
hdfragl[fd].nfrags = 0; |
148 |
|
} |
161 |
|
register int n; |
162 |
|
/* prepare for system errors */ |
163 |
|
errno = 0; |
164 |
< |
if ((fpos = lseek(fd, 0L, 1)) < 0) |
164 |
> |
if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) |
165 |
|
error(SYSTEM, "cannot determine holodeck file position"); |
166 |
|
if (hproto == NULL) { /* assume we're loading it */ |
167 |
|
HDGRID hpr; |
186 |
|
if (fd < nhdfragls && hdfragl[fd].nlinks) |
187 |
|
writable = hdfragl[fd].writable; |
188 |
|
else |
189 |
< |
writable = lseek(fd, fpos, 0) == fpos && |
189 |
> |
writable = lseek(fd, (off_t)fpos, 0) == fpos && |
190 |
|
write(fd, (char *)hp, sizeof(HDGRID)) == |
191 |
|
sizeof(HDGRID); |
192 |
|
} else { /* else assume we're creating it */ |
242 |
|
register int j; |
243 |
|
|
244 |
|
if (!hp->dirty++) { /* write smudge first time */ |
245 |
< |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 |
245 |
> |
if (lseek(hp->fd, (off_t)(biglob(hp)->fo+(i-1)*sizeof(BEAMI)), 0) < 0 |
246 |
|
|| write(hp->fd, (char *)&smudge, |
247 |
|
sizeof(BEAMI)) != sizeof(BEAMI)) |
248 |
|
error(SYSTEM, "seek/write error in hdmarkdirty"); |
305 |
|
return(0); |
306 |
|
errno = 0; /* write dirty segments */ |
307 |
|
for (j = 0; j < hp->dirty; j++) { |
308 |
< |
if (lseek(hp->fd, biglob(hp)->fo + |
309 |
< |
(hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) |
308 |
> |
if (lseek(hp->fd, (off_t)(biglob(hp)->fo + |
309 |
> |
(hp->dirseg[j].s-1)*sizeof(BEAMI)), 0) < 0) |
310 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
311 |
|
n = hp->dirseg[j].n * sizeof(BEAMI); |
312 |
|
if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) |
355 |
|
if (fd < 0) |
356 |
|
return(-1); |
357 |
|
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
358 |
< |
if ((fpos = lseek(fd, 0L, 1)) < 0) |
358 |
> |
if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) |
359 |
|
return(-1); |
360 |
< |
flen = lseek(fd, 0L, 2); |
361 |
< |
lseek(fd, fpos, 0); |
360 |
> |
flen = lseek(fd, (off_t)0L, 2); |
361 |
> |
lseek(fd, (off_t)fpos, 0); |
362 |
|
return(flen); |
363 |
|
} |
364 |
|
return(hdfragl[fd].flen); |
413 |
|
blglob(hp)->nrm += n; |
414 |
|
if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { |
415 |
|
errno = 0; |
416 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
416 |
> |
if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) |
417 |
|
error(SYSTEM, "seek error on holodeck file"); |
418 |
|
n *= sizeof(RAYVAL); |
419 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
452 |
|
hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); |
453 |
|
blglob(hp)->nrm += hp->bl[i]->nrm = n; |
454 |
|
errno = 0; |
455 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
455 |
> |
if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) |
456 |
|
error(SYSTEM, "seek error on holodeck file"); |
457 |
|
n *= sizeof(RAYVAL); |
458 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
569 |
|
if (f->fi == NULL) |
570 |
|
newp = (BEAMI *)malloc((j+FRAGBLK)*sizeof(BEAMI)); |
571 |
|
else |
572 |
< |
newp = (BEAMI *)realloc((char *)f->fi, |
572 |
> |
newp = (BEAMI *)realloc((void *)f->fi, |
573 |
|
(j+FRAGBLK)*sizeof(BEAMI)); |
574 |
|
if (newp == NULL) { |
575 |
|
f->nfrags--; /* graceful failure */ |
683 |
|
if (nrays) { /* get and write new fragment */ |
684 |
|
nfo = hdallocfrag(hp->fd, nrays); |
685 |
|
errno = 0; |
686 |
< |
if (lseek(hp->fd, nfo, 0) < 0) |
686 |
> |
if (lseek(hp->fd, (off_t)nfo, 0) < 0) |
687 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
688 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
689 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
737 |
|
if (nchanged) |
738 |
|
hdsyncbeam(hp, i); /* write new fragment */ |
739 |
|
blglob(hp)->nrm -= hp->bl[i]->nrm; |
740 |
< |
free((char *)hp->bl[i]); /* free memory */ |
740 |
> |
free((void *)hp->bl[i]); /* free memory */ |
741 |
|
hp->bl[i] = NULL; |
742 |
|
return(nchanged); |
743 |
|
} |
774 |
|
"hdkillbeam called on read-only holodeck"); |
775 |
|
if (hp->bl[i] != NULL) { /* free memory */ |
776 |
|
blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm; |
777 |
< |
free((char *)hp->bl[i]); |
777 |
> |
free((void *)hp->bl[i]); |
778 |
|
hp->bl[i] = NULL; |
779 |
|
} else |
780 |
|
nchanged = hp->bi[i].nrd; |
872 |
|
if (hp == NULL) { /* NULL means clean up everything */ |
873 |
|
while (hdlist[0] != NULL) |
874 |
|
hddone(hdlist[0]); |
875 |
< |
free((char *)hdfragl); |
875 |
> |
free((void *)hdfragl); |
876 |
|
hdfragl = NULL; nhdfragls = 0; |
877 |
|
return; |
878 |
|
} |
887 |
|
i++; |
888 |
|
break; |
889 |
|
} |
890 |
< |
free((char *)hp->bl); /* free beam list */ |
891 |
< |
free((char *)hp); /* free holodeck struct */ |
890 |
> |
free((void *)hp->bl); /* free beam list */ |
891 |
> |
free((void *)hp); /* free holodeck struct */ |
892 |
|
} |