From 105ead9e89003d8262fd682b7eef1273f8663b68 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Wed, 30 Apr 2014 03:37:36 -0400 Subject: [PATCH] Clean-up gmx_eof - 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 --- src/gromacs/fileio/confio.c | 14 +++++++++++- src/gromacs/utility/futil.cpp | 40 ----------------------------------- src/gromacs/utility/futil.h | 11 ---------- 3 files changed, 13 insertions(+), 52 deletions(-) diff --git a/src/gromacs/fileio/confio.c b/src/gromacs/fileio/confio.c index cb834342bb..47cb580a59 100644 --- a/src/gromacs/fileio/confio.c +++ b/src/gromacs/fileio/confio.c @@ -1143,6 +1143,18 @@ static void read_whole_conf(const char *infile, char *title, gmx_fio_fclose(in); } +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; @@ -1151,7 +1163,7 @@ gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr) double tt; int ndec = 0, i; - if (gmx_eof(status)) + if (gmx_one_before_eof(status)) { return FALSE; } diff --git a/src/gromacs/utility/futil.cpp b/src/gromacs/utility/futil.cpp index 8c344e0781..312d6a4a8e 100644 --- a/src/gromacs/utility/futil.cpp +++ b/src/gromacs/utility/futil.cpp @@ -241,27 +241,6 @@ gmx_off_t gmx_ftell(FILE *stream) #endif } - -//! 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; @@ -320,25 +299,6 @@ gmx_bool gmx_fexist(const char *fname) } } -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 diff --git a/src/gromacs/utility/futil.h b/src/gromacs/utility/futil.h index bec08e5a48..dc7441012a 100644 --- a/src/gromacs/utility/futil.h +++ b/src/gromacs/utility/futil.h @@ -109,17 +109,6 @@ void no_buffers(void); */ 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. * -- 2.22.0