* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
-#include "gromacs/utility/futil.h"
+#include "gmxpre.h"
+
+#include "futil.h"
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#ifdef HAVE_DIRENT_H
/* POSIX */
#ifdef GMX_NATIVE_WINDOWS
#include <direct.h>
#include <io.h>
+#include <windows.h>
#endif
/* Windows file stuff, only necessary for visual studio */
} 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)
return ftello(stream);
#else
#ifdef HAVE__FSEEKI64
+#ifndef __MINGW32__
return _ftelli64(stream);
+#else
+ return ftello64(stream);
+#endif
#else
return ftell(stream);
#endif
/* Check whether we should be using buffering (default) or not
* (for debugging)
*/
- if (bUnbuffered || ((bufsize = getenv("LOG_BUFS")) != NULL))
+ if (bUnbuffered || ((bufsize = getenv("GMX_LOG_BUFFER")) != NULL))
{
/* Check whether to use completely unbuffered */
if (bUnbuffered)
/* Our own implementation of dirent-like functionality to scan directories. */
struct gmx_directory
{
-#ifdef HAVE_DIRENT_H
- DIR * dirent_handle;
-#elif (defined GMX_NATIVE_WINDOWS)
+#if defined(GMX_NATIVE_WINDOWS)
intptr_t windows_handle;
struct _finddata_t finddata;
int first;
+#elif defined(HAVE_DIRENT_H)
+ DIR * dirent_handle;
#else
int dummy;
#endif
*p_gmxdir = gmxdir;
-#ifdef HAVE_DIRENT_H
- if ( (gmxdir->dirent_handle = opendir(dirname)) != NULL)
- {
- rc = 0;
- }
- else
- {
- sfree(gmxdir);
- *p_gmxdir = NULL;
- rc = EINVAL;
- }
-#elif (defined GMX_NATIVE_WINDOWS)
-
+#if defined(GMX_NATIVE_WINDOWS)
if (dirname != NULL && strlen(dirname) > 0)
{
char * tmpname;
{
rc = EINVAL;
}
+#elif defined(HAVE_DIRENT_H)
+ if ( (gmxdir->dirent_handle = opendir(dirname)) != NULL)
+ {
+ rc = 0;
+ }
+ else
+ {
+ sfree(gmxdir);
+ *p_gmxdir = NULL;
+ rc = EINVAL;
+ }
#else
gmx_fatal(FARGS,
"Source compiled without POSIX dirent or windows support - cannot scan directories.\n"
{
int rc;
-#ifdef HAVE_DIRENT_H
+#if defined(GMX_NATIVE_WINDOWS)
+ if (gmxdir != NULL)
+ {
+ if (gmxdir->windows_handle <= 0)
+ {
+ name[0] = '\0';
+ rc = ENOENT;
+ }
+ else if (gmxdir->first == 1)
+ {
+ strncpy(name, gmxdir->finddata.name, maxlength_name);
+ rc = 0;
+ gmxdir->first = 0;
+ }
+ else
+ {
+ if (_findnext(gmxdir->windows_handle, &gmxdir->finddata) == 0)
+ {
+ strncpy(name, gmxdir->finddata.name, maxlength_name);
+ rc = 0;
+ }
+ else
+ {
+ name[0] = '\0';
+ rc = ENOENT;
+ }
+ }
+ }
+ else
+ {
+ name[0] = '\0';
+ rc = EINVAL;
+ }
+#elif defined(HAVE_DIRENT_H)
struct dirent * direntp_large;
struct dirent * p;
name[0] = '\0';
rc = EINVAL;
}
-
-#elif (defined GMX_NATIVE_WINDOWS)
-
- if (gmxdir != NULL)
- {
- if (gmxdir->windows_handle <= 0)
- {
-
- name[0] = '\0';
- rc = ENOENT;
- }
- else if (gmxdir->first == 1)
- {
- strncpy(name, gmxdir->finddata.name, maxlength_name);
- rc = 0;
- gmxdir->first = 0;
- }
- else
- {
- if (_findnext(gmxdir->windows_handle, &gmxdir->finddata) == 0)
- {
- strncpy(name, gmxdir->finddata.name, maxlength_name);
- rc = 0;
- }
- else
- {
- name[0] = '\0';
- rc = ENOENT;
- }
- }
- }
-
#else
gmx_fatal(FARGS,
"Source compiled without POSIX dirent or windows support - cannot scan directories.\n");
gmx_directory_close(gmx_directory_t gmxdir)
{
int rc;
-#ifdef HAVE_DIRENT_H
- rc = (gmxdir != NULL) ? closedir(gmxdir->dirent_handle) : EINVAL;
-#elif (defined GMX_NATIVE_WINDOWS)
+#if defined(GMX_NATIVE_WINDOWS)
rc = (gmxdir != NULL) ? _findclose(gmxdir->windows_handle) : EINVAL;
+#elif defined(HAVE_DIRENT_H)
+ rc = (gmxdir != NULL) ? closedir(gmxdir->dirent_handle) : EINVAL;
#else
gmx_fatal(FARGS,
"Source compiled without POSIX dirent or windows support - cannot scan directories.\n");
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 */