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 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_FILEIO_FUTIL_H
39 #define GMX_FILEIO_FUTIL_H
42 #include "../legacyheaders/typedefs.h"
43 #include "../legacyheaders/types/commrec.h"
52 /* Native windows uses backslash path separators.
53 * Cygwin and everybody else in the world use slash.
55 #include "../utility/gmx_header_config.h"
56 #ifdef GMX_NATIVE_WINDOWS
57 #define DIR_SEPARATOR '\\'
59 #define DIR_SEPARATOR '/'
62 /* Now get the maximum path size. */
64 # define GMX_PATH_MAX PATH_MAX
65 #elif defined MAX_PATH
66 # define GMX_PATH_MAX MAX_PATH
68 # define GMX_PATH_MAX 4096
71 typedef gmx_int64_t gmx_off_t;
73 void no_buffers(void);
74 /* Turn off buffering of files (which is default) for debugging purposes */
76 gmx_bool gmx_fexist(const char *fname);
77 /* Return TRUE when fname exists, FALSE otherwise */
79 gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr);
80 /* Return TRUE when fname exists, FALSE otherwise, bcast from master to others */
82 gmx_bool gmx_eof(FILE *fp);
83 /* Return TRUE on end-of-file, FALSE otherwise */
85 gmx_bool is_pipe(FILE *fp);
86 /* Check whether the file (opened by gmx_ffopen) is a pipe */
88 /* Make a backup of file if necessary.
89 Return false if there was a problem.
91 gmx_bool make_backup(const char * file);
93 FILE *gmx_ffopen(const char *file, const char *mode);
94 /* Return a valid file pointer when successful, exits otherwise
95 * If the file is in compressed format, open a pipe which uncompresses
96 * the file! Therefore, files must be closed with gmx_ffclose (see below)
99 int gmx_ffclose(FILE *fp);
100 /* Close files or pipes */
103 void frewind(FILE *fp);
104 /* Does not rewind pipes, but does so for normal files */
106 #define rewind frewind
109 int gmx_fseek(FILE *stream, gmx_off_t offset, int whence);
110 /* OS-independent fseek. 64-bit when available */
112 gmx_off_t gmx_ftell(FILE *stream);
113 /* OS-independent fseek. 64-bit when available. */
116 gmx_bool is_pipe(FILE *fp);
118 char *gmxlibfn(const char *file);
119 /* allocates and returns a string with the full file name for a library file */
121 FILE *libopen(const char *file);
122 /* Open a library file for reading. This looks in the current directory
123 * first, and then in the library directory. If the file is not found,
124 * it terminates with a fatal_error
127 /* Opaque data type to list directories */
128 typedef struct gmx_directory *
131 /* Open a directory for reading. The first argument should be a pointer
132 * to a declared gmx_directory_t variable. Returns 0 on success.
135 gmx_directory_open(gmx_directory_t *p_gmxdir, const char *dirname);
138 /* Given an initialized gmx_directory_t, if there are more files in
139 * the directory this routine returns 0 and write the next name
140 * into the USER-PROVIDED buffer name. The last argument is the max
141 * number of characters that will be written. Just as strncpy, the
142 * string will NOT be terminated it it is longer than maxlength_name.
145 gmx_directory_nextfile(gmx_directory_t gmxdir, char *name, int maxlength_name);
147 /* Release all data for a directory structure */
149 gmx_directory_close(gmx_directory_t gmxdir);
152 char *low_gmxlibfn(const char *file, gmx_bool bAddCWD, gmx_bool bFatal);
154 FILE *low_libopen(const char *file, gmx_bool bFatal);
155 /* The same as the above, but does not terminate if (!bFatal) */
157 /* Create unique name for temp file (wrapper around mkstemp).
158 * Buf should be at least 7 bytes long
160 void gmx_tmpnam(char *buf);
162 /* truncte the file to the specified length */
163 int gmx_truncatefile(char *path, gmx_off_t length);
165 /* rename/move the file (atomically, if the OS makes that available) oldname
167 int gmx_file_rename(const char *oldname, const char *newname);
169 /* copy the file (data only) oldname to newname. if copy_if_empty==FALSE,
170 the file won't be copied if it's empty.*/
171 int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty);
173 /* do an fsync() on an open file pointer.
174 Only use this during checkpointing! */
175 int gmx_fsync(FILE *fp);
177 void gmx_chdir(const char *directory);
178 void gmx_getcwd(char *buffer, size_t size);
184 #endif /* GMX_FILEIO_FUTIL_H */