Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / utility / futil.cpp
similarity index 92%
rename from src/gromacs/fileio/futil.cpp
rename to src/gromacs/utility/futil.cpp
index a93bf6f1f0a6a55ddda9693fb51e426c874d15a1..af28843ef532da32ed1df43370144d54af280627 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
+#include "gmxpre.h"
+
+#include "gromacs/utility/futil.h"
+
 #include "config.h"
-#endif
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "thread_mpi/threads.h"
 
-#include "gromacs/legacyheaders/gmx_fatal.h"
-#include "gromacs/legacyheaders/types/commrec.h"
-#include "gromacs/legacyheaders/network.h"
-
-#include "gromacs/fileio/futil.h"
-#include "gromacs/fileio/path.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
@@ -90,15 +88,15 @@ typedef struct t_pstack {
 } t_pstack;
 
 static t_pstack    *pstack      = NULL;
-static gmx_bool     bUnbuffered = FALSE;
+static bool         bUnbuffered = false;
 
 /* this linked list is an intrinsically globally shared object, so we have
    to protect it with mutexes */
 static tMPI_Thread_mutex_t pstack_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
 
-void no_buffers(void)
+void gmx_disable_file_buffering(void)
 {
-    bUnbuffered = TRUE;
+    bUnbuffered = true;
 }
 
 void push_ps(FILE *fp)
@@ -199,10 +197,6 @@ int gmx_ffclose(FILE *fp)
 }
 
 
-#ifdef rewind
-#undef rewind
-#endif
-
 void frewind(FILE *fp)
 {
     tMPI_Thread_mutex_lock(&pstack_mutex);
@@ -252,26 +246,6 @@ gmx_off_t gmx_ftell(FILE *stream)
 #endif
 }
 
-
-gmx_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;
@@ -330,41 +304,6 @@ gmx_bool gmx_fexist(const char *fname)
     }
 }
 
-
-gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr)
-{
-    gmx_bool bExist;
-
-    if (SIMMASTER(cr))
-    {
-        bExist = gmx_fexist(fname);
-    }
-    if (PAR(cr))
-    {
-        gmx_bcast(sizeof(bExist), &bExist, cr);
-    }
-    return bExist;
-}
-
-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
@@ -870,28 +809,6 @@ void gmx_tmpnam(char *buf)
     /* name in Buf should now be OK */
 }
 
-int gmx_truncatefile(char *path, gmx_off_t length)
-{
-#ifdef GMX_NATIVE_WINDOWS
-    /* Microsoft visual studio does not have "truncate" */
-    HANDLE        fh;
-    LARGE_INTEGER win_length;
-
-    win_length.QuadPart = length;
-
-    fh = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                    OPEN_EXISTING, 0, NULL);
-    SetFilePointerEx(fh, win_length, NULL, FILE_BEGIN);
-    SetEndOfFile(fh);
-    CloseHandle(fh);
-
-    return 0;
-#else
-    return truncate(path, length);
-#endif
-}
-
-
 int gmx_file_rename(const char *oldname, const char *newname)
 {
 #ifndef GMX_NATIVE_WINDOWS
@@ -994,13 +911,15 @@ int gmx_fsync(FILE *fp)
     rc = fah_fsync(fp);
 #else /* GMX_FAHCORE */
     {
-        int fn = -1;
+        int fn;
 
         /* get the file number */
 #if defined(HAVE_FILENO)
         fn = fileno(fp);
 #elif defined(HAVE__FILENO)
         fn = _fileno(fp);
+#else
+        fn = -1;
 #endif
 
         /* do the actual fsync */