#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "gmx_header_config.h"
#include <stdio.h>
#include <stdlib.h>
#endif
-#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#ifdef GMX_NATIVE_WINDOWS
#include <direct.h>
#include <io.h>
#endif
#include "statutil.h"
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
#include "thread_mpi.h"
#endif
static t_pstack *pstack=NULL;
static gmx_bool bUnbuffered=FALSE;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
/* 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;
{
t_pstack *ps;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&pstack_mutex);
#endif
ps->fp = fp;
ps->prev = pstack;
pstack = ps;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
}
#else
t_pstack *ps,*tmp;
int ret=0;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&pstack_mutex);
#endif
else {
while ((ps->prev != NULL) && (ps->prev->fp != fp))
ps=ps->prev;
- if (ps->prev->fp == fp) {
+ if ((ps->prev != NULL) && ps->prev->fp == fp) {
if (ps->prev->fp != NULL)
ret = pclose(ps->prev->fp);
tmp=ps->prev;
ret = fclose(fp);
}
}
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
return ret;
void frewind(FILE *fp)
{
t_pstack *ps;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&pstack_mutex);
#endif
while (ps != NULL) {
if (ps->fp == fp) {
fprintf(stderr,"Cannot rewind compressed file!\n");
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
return;
ps=ps->prev;
}
rewind(fp);
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
}
gmx_bool is_pipe(FILE *fp)
{
t_pstack *ps;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&pstack_mutex);
#endif
ps=pstack;
while (ps != NULL) {
if (ps->fp == fp) {
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
return TRUE;
}
ps=ps->prev;
}
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&pstack_mutex);
#endif
return FALSE;
test=fopen(fname,"r");
if (test == NULL) {
/*Windows doesn't allow fopen of directory - so we need to check this seperately */
- #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+ #ifdef GMX_NATIVE_WINDOWS
DWORD attr = GetFileAttributes(fname);
return (attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY);
#else
gmx_bool bRead;
int bs;
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
if (mode[0]=='w') {
make_backup(file);
}
{
#ifdef HAVE_DIRENT_H
DIR * dirent_handle;
-#elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64)
+#elif (defined GMX_NATIVE_WINDOWS)
intptr_t windows_handle;
struct _finddata_t finddata;
int first;
*p_gmxdir = NULL;
rc = EINVAL;
}
-#elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64)
+#elif (defined GMX_NATIVE_WINDOWS)
if(dirname!=NULL && strlen(dirname)>0)
{
rc = EINVAL;
}
-#elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64)
+#elif (defined GMX_NATIVE_WINDOWS)
if(gmxdir!=NULL)
{
int rc;
#ifdef HAVE_DIRENT_H
rc = (gmxdir != NULL) ? closedir(gmxdir->dirent_handle) : EINVAL;
-#elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64)
+#elif (defined GMX_NATIVE_WINDOWS)
rc = (gmxdir != NULL) ? _findclose(gmxdir->windows_handle) : EINVAL;
#else
gmx_fatal(FARGS,
*/
static gmx_bool filename_is_absolute(char *name)
{
-#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#ifdef GMX_NATIVE_WINDOWS
return ((name[0] == DIR_SEPARATOR) || ((strlen(name)>3) && strncmp(name+1,":\\",2)) == 0);
#else
return (name[0] == DIR_SEPARATOR);
/* On windows & cygwin we need to add the .exe extension
* too, or we wont be able to detect that the file exists
*/
-#if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __CYGWIN__ || defined __CYGWIN32__)
+#if (defined GMX_NATIVE_WINDOWS || defined GMX_CYGWIN)
if(strlen(bin_name)<3 || gmx_strncasecmp(bin_name+strlen(bin_name)-4,".exe",4))
strcat(bin_name,".exe");
#endif
if (!strchr(bin_name,DIR_SEPARATOR)) {
/* No slash or backslash in name means it must be in the path - search it! */
/* Add the local dir since it is not in the path on windows */
-#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#ifdef GMX_NATIVE_WINDOWS
pdum=_getcwd(system_path,sizeof(system_path)-1);
#else
pdum=getcwd(system_path,sizeof(system_path)-1);
* it does not start at the root, i.e.
* name is relative to the current dir
*/
-#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#ifdef GMX_NATIVE_WINDOWS
pdum=_getcwd(buf,sizeof(buf)-1);
#else
pdum=getcwd(buf,sizeof(buf)-1);
/* Now we should have a full path and name in full_path,
* but on unix it might be a link, or a link to a link to a link..
*/
-#if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64)
+#ifndef GMX_NATIVE_WINDOWS
while( (i=readlink(full_path,buf,sizeof(buf)-1)) > 0 ) {
buf[i]='\0';
/* If it doesn't start with "/" it is relative */
* locations before giving up, in case we are running from e.g.
* a users home directory. This only works on unix or cygwin...
*/
-#if ((!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64) || defined __CYGWIN__ || defined __CYGWIN32__)
+#ifndef GMX_NATIVE_WINDOWS
if(!found)
found=search_subdirs("/usr/local",libdir);
if(!found)
* since windows doesnt support it we have to separate the cases.
* 20090307: mktemp deprecated, use iso c++ _mktemp instead.
*/
-#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#ifdef GMX_NATIVE_WINDOWS
_mktemp(buf);
#else
fd = mkstemp(buf);
int gmx_file_rename(const char *oldname, const char *newname)
{
-#if (!(defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)))
+#ifndef GMX_NATIVE_WINDOWS
/* under unix, rename() is atomic (at least, it should be). */
return rename(oldname, newname);
#else