Run regressiontests from build
[gromacs.git] / include / futil.h
blob6d255bdd9156bc98dd16b7ae48cfb010b28ec7a5
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 #ifndef _futil_h
40 #define _futil_h
41 #include "visibility.h"
42 #include <stdio.h>
43 #include "typedefs.h"
44 #include "types/commrec.h"
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 #if 0
51 #endif
53 /* Native windows uses backslash path separators.
54 * Cygwin and everybody else in the world use slash.
55 * When reading the PATH environment variable, Unix separates entries
56 * with colon, while windows uses semicolon.
58 #include "gmx_header_config.h"
59 #ifdef GMX_NATIVE_WINDOWS
60 #define DIR_SEPARATOR '\\'
61 #define PATH_SEPARATOR ";"
62 #else
63 #define DIR_SEPARATOR '/'
64 #define PATH_SEPARATOR ":"
65 #endif
68 /* Now get the maximum path size. */
69 #ifdef PATH_MAX
70 # define GMX_PATH_MAX PATH_MAX
71 #elif defined MAX_PATH
72 # define GMX_PATH_MAX MAX_PATH
73 #else
74 # define GMX_PATH_MAX 4096
75 #endif
78 #ifdef HAVE_FSEEKO
79 typedef off_t gmx_off_t;
80 # define SIZEOF_GMX_OFF_T SIZEOF_OFF_T
81 #elif defined HAVE__FSEEKI64
82 typedef __int64 gmx_off_t;
83 # define SIZEOF_GMX_OFF_T 8
84 #else
85 /* Almost certainly 64 bits, and guaranteed to be available */
86 typedef gmx_large_int_t gmx_off_t;
87 # define SIZEOF_GMX_OFF_T SIZEOF_GMX_LARGE_INT
88 #endif
92 void no_buffers(void);
93 /* Turn off buffering of files (which is default) for debugging purposes */
95 GMX_LIBGMX_EXPORT
96 gmx_bool gmx_fexist(const char *fname);
97 /* Return TRUE when fname exists, FALSE otherwise */
99 GMX_LIBGMX_EXPORT
100 gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr);
101 /* Return TRUE when fname exists, FALSE otherwise, bcast from master to others */
103 gmx_bool gmx_eof(FILE *fp);
104 /* Return TRUE on end-of-file, FALSE otherwise */
106 gmx_bool is_pipe(FILE *fp);
107 /* Check whether the file (opened by ffopen) is a pipe */
109 /* Make a backup of file if necessary.
110 Return false if there was a problem.
112 GMX_LIBGMX_EXPORT
113 gmx_bool make_backup(const char * file);
115 GMX_LIBGMX_EXPORT
116 FILE *ffopen(const char *file, const char *mode);
117 /* Return a valid file pointer when successful, exits otherwise
118 * If the file is in compressed format, open a pipe which uncompresses
119 * the file! Therefore, files must be closed with ffclose (see below)
122 GMX_LIBGMX_EXPORT
123 int ffclose(FILE *fp);
124 /* Close files or pipes */
127 void frewind(FILE *fp);
128 /* Does not rewind pipes, but does so for normal files */
130 #define rewind frewind
133 GMX_LIBGMX_EXPORT
134 int gmx_fseek(FILE *stream, gmx_off_t offset, int whence);
135 /* OS-independent fseek. 64-bit when available */
137 GMX_LIBGMX_EXPORT
138 gmx_off_t gmx_ftell(FILE *stream);
139 /* OS-independent fseek. 64-bit when available. */
142 gmx_bool is_pipe(FILE *fp);
144 GMX_LIBGMX_EXPORT
145 char *gmxlibfn(const char *file);
146 /* allocates and returns a string with the full file name for a library file */
148 GMX_LIBGMX_EXPORT
149 FILE *libopen(const char *file);
150 /* Open a library file for reading. This looks in the current directory
151 * first, and then in the library directory. If the file is not found,
152 * it terminates with a fatal_error
155 /* Opaque data type to list directories */
156 typedef struct gmx_directory *
157 gmx_directory_t;
159 /* Open a directory for reading. The first argument should be a pointer
160 * to a declared gmx_directory_t variable. Returns 0 on success.
162 GMX_LIBGMX_EXPORT
164 gmx_directory_open(gmx_directory_t *p_gmxdir,const char *dirname);
167 /* Given an initialized gmx_directory_t, if there are more files in
168 * the directory this routine returns 0 and write the next name
169 * into the USER-PROVIDED buffer name. The last argument is the max
170 * number of characters that will be written. Just as strncpy, the
171 * string will NOT be terminated it it is longer than maxlength_name.
173 GMX_LIBGMX_EXPORT
175 gmx_directory_nextfile(gmx_directory_t gmxdir,char *name,int maxlength_name);
177 /* Release all data for a directory structure */
178 GMX_LIBGMX_EXPORT
179 int
180 gmx_directory_close(gmx_directory_t gmxdir);
184 GMX_LIBGMX_EXPORT
185 gmx_bool get_libdir(char *libdir);
187 GMX_LIBGMX_EXPORT
188 char *low_gmxlibfn(const char *file,gmx_bool bAddCWD,gmx_bool bFatal);
190 FILE *low_libopen(const char *file,gmx_bool bFatal);
191 /* The same as the above, but does not terminate if (!bFatal) */
193 /* Create unique name for temp file (wrapper around mkstemp).
194 * Buf should be at least 7 bytes long
196 GMX_LIBGMX_EXPORT
197 void gmx_tmpnam(char *buf);
199 /* truncte the file to the specified length */
200 int gmx_truncatefile(char *path, gmx_off_t length);
202 /* rename/move the file (atomically, if the OS makes that available) oldname
203 to newname */
204 int gmx_file_rename(const char *oldname, const char *newname);
206 /* copy the file (data only) oldname to newname. if copy_if_empty==FALSE,
207 the file won't be copied if it's empty.*/
208 int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty);
210 /* do an fsync() on an open file pointer.
211 Only use this during checkpointing! */
212 int gmx_fsync(FILE *fp);
214 #ifdef GMX_NATIVE_WINDOWS
215 #define chdir _chdir
216 #define getcwd _getcwd
217 #endif
219 #ifdef __cplusplus
221 #endif
223 #endif /* _futil_h */