- Changed name to gmx_one_before_eof so that the different
behavior from feof is obvious.
- Changed one usage of gmx_eof to feof where the std
behavior is OK
- Moved to confio and made static because it is only
used there.
- Removed the special treatment for pipes. It was incorrect.
gmx_before_eof is only used for gro file reading and
those could not be read from compressed files anyhow.
Their is no possible correct implemenation for pipes
(which cannot be seeked) and even if it wouldn't help
because gro file reading also uses rewind which
doesn't work for pipes.
Change-Id: I77fd34253817cd591011b8a2ec39ae95ce7b7378
+static gmx_bool gmx_one_before_eof(FILE *fp)
+{
+ char data[4];
+ gmx_bool beof;
+
+ if ((beof = fread(data, 1, 1, fp)) == 1)
+ {
+ gmx_fseek(fp, -1, SEEK_CUR);
+ }
+ return !beof;
+}
+
gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr)
{
t_atoms atoms;
gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr)
{
t_atoms atoms;
double tt;
int ndec = 0, i;
double tt;
int ndec = 0, i;
+ if (gmx_one_before_eof(status))
-
-//! Check whether the file (opened by gmx_ffopen()) is a pipe.
-static bool is_pipe(FILE *fp)
-{
- tMPI_Thread_mutex_lock(&pstack_mutex);
-
- t_pstack *ps = pstack;
- while (ps != NULL)
- {
- if (ps->fp == fp)
- {
- tMPI_Thread_mutex_unlock(&pstack_mutex);
- return true;
- }
- ps = ps->prev;
- }
- tMPI_Thread_mutex_unlock(&pstack_mutex);
- return false;
-}
-
-
static FILE *uncompress(const char *fn, const char *mode)
{
FILE *fp;
static FILE *uncompress(const char *fn, const char *mode)
{
FILE *fp;
-gmx_bool gmx_eof(FILE *fp)
-{
- char data[4];
- gmx_bool beof;
-
- if (is_pipe(fp))
- {
- return feof(fp);
- }
- else
- {
- if ((beof = fread(data, 1, 1, fp)) == 1)
- {
- gmx_fseek(fp, -1, SEEK_CUR);
- }
- return !beof;
- }
-}
-
static char *backup_fn(const char *file, int count_max)
{
/* Use a reasonably low value for countmax; we might
static char *backup_fn(const char *file, int count_max)
{
/* Use a reasonably low value for countmax; we might
*/
gmx_bool gmx_fexist(const char *fname);
*/
gmx_bool gmx_fexist(const char *fname);
-/*! \brief
- * Checks for end of file.
- *
- * \returns `TRUE` on end-of-file
- *
- * \todo
- * There are only two callers for this function, while there are ~20 direct
- * calls to feof(). Probably this is unnecessary.
- */
-gmx_bool gmx_eof(FILE *fp);
-
/*! \brief
* Makes a backup of file if the file exists.
*
/*! \brief
* Makes a backup of file if the file exists.
*