318 |
|
HDGRID *gp; |
319 |
|
{ |
320 |
|
long endloc = 0; |
321 |
+ |
int fd; |
322 |
|
FILE *fp; |
323 |
|
/* open & truncate file */ |
324 |
|
if ((fp = fopen(hdkfile, "w+")) == NULL) { |
332 |
|
fputc('\n', fp); |
333 |
|
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
334 |
|
fwrite(&endloc, sizeof(long), 1, fp); |
335 |
< |
fflush(fp); /* flush buffer */ |
336 |
< |
hdinit(fileno(fp), gp); /* allocate and initialize index */ |
337 |
< |
/* we're dropping fp here.... */ |
335 |
> |
fd = dup(fileno(fp)); |
336 |
> |
fclose(fp); /* flush and close stdio stream */ |
337 |
> |
hdinit(fd, gp); /* allocate and initialize index */ |
338 |
|
} |
339 |
|
|
340 |
|
|
364 |
|
|
365 |
|
loadholo() /* start loading a holodeck from fname */ |
366 |
|
{ |
367 |
+ |
extern long ftell(); |
368 |
|
FILE *fp; |
369 |
< |
long endloc; |
369 |
> |
int fd; |
370 |
> |
long fpos; |
371 |
|
/* open holodeck file */ |
372 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
373 |
|
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
382 |
|
hdkfile); |
383 |
|
error(USER, errmsg); |
384 |
|
} |
385 |
< |
fread(&endloc, sizeof(long), 1, fp); |
386 |
< |
if (endloc != 0) |
385 |
> |
fread(&fpos, sizeof(long), 1, fp); |
386 |
> |
if (fpos != 0) |
387 |
|
error(WARNING, "ignoring multiple sections in holodeck file"); |
388 |
< |
fseek(fp, 0L, 1); /* align system file pointer */ |
389 |
< |
hdinit(fileno(fp), NULL); /* allocate and load index */ |
390 |
< |
/* we're dropping fp here.... */ |
388 |
> |
fpos = ftell(fp); /* get stdio position */ |
389 |
> |
fd = dup(fileno(fp)); |
390 |
> |
fclose(fp); /* done with stdio */ |
391 |
> |
lseek(fd, fpos, 0); /* align system file pointer */ |
392 |
> |
hdinit(fd, NULL); /* allocate and load index */ |
393 |
|
} |
394 |
|
|
395 |
|
|