Clean-up gmx_eof
authorRoland Schulz <roland@utk.edu>
Wed, 30 Apr 2014 07:37:36 +0000 (03:37 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 17 May 2014 19:20:25 +0000 (21:20 +0200)
- 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
src/gromacs/utility/futil.cpp
src/gromacs/utility/futil.h

index cb834342bb8725d216b5e870daec028470592228..47cb580a59e4e29dd25313ef1a1c053dbd3f2dbb 100644 (file)
@@ -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;
     }
index 8c344e0781c59144d8b2bf7289a8a836e0540713..312d6a4a8e03ebc57ba6b5c307f35c846bde66cc 100644 (file)
@@ -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
index bec08e5a489546fbb116c24bcad3d0e9104a29cd..dc7441012ad8c1a121f37fff98129ae71c98247e 100644 (file)
@@ -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.
  *