*/
#include "gmxpre.h"
-#include "config.h"
-
#include <math.h>
#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/gmxfio.h"
}
}
-#ifndef GMX_NATIVE_WINDOWS
void do_trunc(const char *fn, real t0)
{
t_fileio *in;
{
fprintf(stderr, "Once again, I'm gonna DO this...\n");
close_trn(in);
- if (0 != truncate(fn, fpos))
+ if (0 != gmx_truncate(fn, fpos))
{
gmx_fatal(FARGS, "Error truncating file %s", fn);
}
}
}
}
-#endif
/*! \brief Read a full molecular topology if useful and available.
*
{ &bVels }, "Read and write velocities if possible" },
{ "-force", FALSE, etBOOL,
{ &bForce }, "Read and write forces if possible" },
-#ifndef GMX_NATIVE_WINDOWS
{ "-trunc", FALSE, etTIME,
{ &ttrunc },
"Truncate input trajectory file after this time (%t)" },
-#endif
{ "-exec", FALSE, etSTR,
{ &exec_command },
"Execute command for every output frame with the "
if (ttrunc != -1)
{
-#ifndef GMX_NATIVE_WINDOWS
do_trunc(in_file, ttrunc);
-#endif
}
else
{
#include <string.h>
#include <fcntl.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#ifdef GMX_NATIVE_WINDOWS
-/* _chsize_s */
#include <io.h>
#include <sys/locking.h>
#endif
"accumulated_plus", "accumulated_minus", "accumulated_plus_2", "accumulated_minus_2", "Tij", "Tij_empirical"
};
-#ifdef GMX_NATIVE_WINDOWS
-static int
-gmx_wintruncate(const char *filename, __int64 size)
-{
-#ifdef GMX_FAHCORE
- /*we do this elsewhere*/
- return 0;
-#else
- FILE *fp;
-
- fp = fopen(filename, "rb+");
-
- if (fp == NULL)
- {
- return -1;
- }
-
-#ifdef _MSC_VER
- return _chsize_s( fileno(fp), size);
-#else
- return _chsize( fileno(fp), size);
-#endif
-#endif
-}
-#endif
-
-
enum {
ecprREAL, ecprRVEC, ecprMATRIX
};
if (i != 0) /*log file is already seeked to correct position */
{
-#ifdef GMX_NATIVE_WINDOWS
- rc = gmx_wintruncate(outputfiles[i].filename, outputfiles[i].offset);
-#else
- rc = truncate(outputfiles[i].filename, outputfiles[i].offset);
-#endif
+#if !defined(GMX_NATIVE_WINDOWS) || !defined(GMX_FAHCORE)
+ /* For FAHCORE, we do this elsewhere*/
+ rc = gmx_truncate(outputfiles[i].filename, outputfiles[i].offset);
if (rc != 0)
{
gmx_fatal(FARGS, "Truncation of file %s failed. Cannot do appending because of this failure.", outputfiles[i].filename);
}
+#endif
}
}
}
/* POSIX */
#include <dirent.h>
#endif
-
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
#ifdef GMX_NATIVE_WINDOWS
#include <direct.h>
#include <io.h>
#include <windows.h>
#endif
-/* Windows file stuff, only necessary for visual studio */
-#ifdef _MSC_VER
-#include <windows.h>
-#endif
-
#include "thread_mpi/threads.h"
#include "gromacs/utility/cstringutil.h"
#endif
}
+int gmx_truncate(const char *filename, gmx_off_t length)
+{
+#ifdef GMX_NATIVE_WINDOWS
+ FILE *fp = fopen(filename, "rb+");
+ if (fp == NULL)
+ {
+ return -1;
+ }
+#ifdef _MSC_VER
+ int rc = _chsize_s(fileno(fp), length);
+#else
+ int rc = _chsize(fileno(fp), length);
+#endif
+ fclose(fp);
+ return rc;
+#else
+ return truncate(filename, length);
+#endif
+}
+
static FILE *uncompress(const char *fn, const char *mode)
{
FILE *fp;
/** OS-independent 64-bit ftell(). */
gmx_off_t gmx_ftell(FILE *stream);
+/** OS-independent truncate(). */
+int gmx_truncate(const char *filename, gmx_off_t length);
+
/*! \brief
* Finds full path for a library file.
*