--- ray/src/common/readmesh.c 2019/05/04 00:36:58 2.17 +++ ray/src/common/readmesh.c 2023/02/07 20:28:16 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readmesh.c,v 2.17 2019/05/04 00:36:58 greg Exp $"; +static const char RCSid[] = "$Id: readmesh.c,v 2.19 2023/02/07 20:28:16 greg Exp $"; #endif /* * Routines for reading a compiled mesh from a file @@ -35,11 +35,11 @@ static long mgetint(siz) /* get a siz-byte integer */ int siz; { - long r; + long r = getint(siz, meshfp); - r = getint(siz, meshfp); - if (feof(meshfp)) + if (r == EOF && feof(meshfp)) mesherror(USER, "truncated mesh file"); + return(r); } @@ -47,11 +47,11 @@ int siz; static double mgetflt() /* get a floating point number */ { - double r; + double r = getflt(meshfp); - r = getflt(meshfp); - if (feof(meshfp)) + if (r == (double)EOF && feof(meshfp)) mesherror(USER, "truncated mesh file"); + return(r); } @@ -250,6 +250,9 @@ int flags; error(SYSTEM, errmsg); } SET_FILE_BINARY(meshfp); +#ifdef getc_unlocked /* avoid stupid semaphores */ + flockfile(meshfp); +#endif /* read header */ checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL); /* read format number */ @@ -292,6 +295,10 @@ int flags; /* clean up */ if (meshfp != stdin) fclose(meshfp); +#ifdef getc_unlocked + else + funlockfile(meshfp); +#endif mp->ldflags |= flags; /* verify data */ if ((err = checkmesh(mp)) != NULL)