Removed superfluous file.
[gromacs/rigid-bodies.git] / include / futil.h
blobcbd313e46811200d0462515573b96a02d963d02f
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gromacs Runs On Most of All Computer Systems
36 #ifndef _futil_h
37 #define _futil_h
39 #include <stdio.h>
40 #include "typedefs.h"
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 #if 0
47 #endif
49 /* Native windows uses backslash path separators.
50 * Cygwin and everybody else in the world use slash.
51 * When reading the PATH environment variable, Unix separates entries
52 * with colon, while windows uses semicolon.
54 #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
55 #define DIR_SEPARATOR '\\'
56 #define PATH_SEPARATOR ";"
57 #else
58 #define DIR_SEPARATOR '/'
59 #define PATH_SEPARATOR ":"
60 #endif
63 /* Now get the maximum path size. */
64 #ifdef PATH_MAX
65 # define GMX_PATH_MAX PATH_MAX
66 #elif defined MAX_PATH
67 # define GMX_PATH_MAX MAX_PATH
68 #else
69 # define GMX_PATH_MAX 4096
70 #endif
73 #ifdef HAVE_FSEEKO
74 typedef off_t gmx_off_t;
75 # define SIZEOF_GMX_OFF_T SIZEOF_OFF_T
76 #elif defined HAVE__FSEEKI64
77 typedef __int64 gmx_off_t;
78 # define SIZEOF_GMX_OFF_T 8
79 #else
80 /* Almost certainly 64 bits, and guaranteed to be available */
81 typedef gmx_large_int_t gmx_off_t;
82 # define SIZEOF_GMX_OFF_T SIZEOF_GMX_LARGE_INT
83 #endif
87 void no_buffers(void);
88 /* Turn off buffering of files (which is default) for debugging purposes */
90 gmx_bool gmx_fexist(const char *fname);
91 /* Return TRUE when fname exists, FALSE otherwise */
93 gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr);
94 /* Return TRUE when fname exists, FALSE otherwise, bcast from master to others */
96 gmx_bool gmx_eof(FILE *fp);
97 /* Return TRUE on end-of-file, FALSE otherwise */
99 gmx_bool is_pipe(FILE *fp);
100 /* Check whether the file (opened by ffopen) is a pipe */
102 /* Make a backup of file if necessary.
103 Return false if there was a problem.
105 gmx_bool make_backup(const char * file);
107 FILE *ffopen(const char *file, const char *mode);
108 /* Return a valid file pointer when successful, exits otherwise
109 * If the file is in compressed format, open a pipe which uncompresses
110 * the file! Therefore, files must be closed with ffclose (see below)
113 int ffclose(FILE *fp);
114 /* Close files or pipes */
117 void frewind(FILE *fp);
118 /* Does not rewind pipes, but does so for normal files */
120 #define rewind frewind
123 int gmx_fseek(FILE *stream, gmx_off_t offset, int whence);
124 /* OS-independent fseek. 64-bit when available */
126 gmx_off_t gmx_ftell(FILE *stream);
127 /* OS-independent fseek. 64-bit when available. */
130 gmx_bool is_pipe(FILE *fp);
132 char *gmxlibfn(const char *file);
133 /* allocates and returns a string with the full file name for a library file */
135 FILE *libopen(const char *file);
136 /* Open a library file for reading. This looks in the current directory
137 * first, and then in the library directory. If the file is not found,
138 * it terminates with a fatal_error
141 /* Opaque data type to list directories */
142 typedef struct gmx_directory *
143 gmx_directory_t;
145 /* Open a directory for reading. The first argument should be a pointer
146 * to a declared gmx_directory_t variable. Returns 0 on success.
149 gmx_directory_open(gmx_directory_t *p_gmxdir,const char *dirname);
152 /* Given an initialized gmx_directory_t, if there are more files in
153 * the directory this routine returns 0 and write the next name
154 * into the USER-PROVIDED buffer name. The last argument is the max
155 * number of characters that will be written. Just as strncpy, the
156 * string will NOT be terminated it it is longer than maxlength_name.
159 gmx_directory_nextfile(gmx_directory_t gmxdir,char *name,int maxlength_name);
161 /* Release all data for a directory structure */
162 int
163 gmx_directory_close(gmx_directory_t gmxdir);
167 gmx_bool get_libdir(char *libdir);
169 char *low_gmxlibfn(const char *file,gmx_bool bAddCWD,gmx_bool bFatal);
171 FILE *low_libopen(const char *file,gmx_bool bFatal);
172 /* The same as the above, but does not terminate if (!bFatal) */
174 /* Create unique name for temp file (wrapper around mkstemp).
175 * Buf should be at least 7 bytes long
177 void gmx_tmpnam(char *buf);
179 /* truncte the file to the specified length */
180 int gmx_truncatefile(char *path, gmx_off_t length);
182 /* rename/move the file (atomically, if the OS makes that available) oldname
183 to newname */
184 int gmx_file_rename(const char *oldname, const char *newname);
186 /* copy the file (data only) oldname to newname. if copy_if_empty==FALSE,
187 the file won't be copied if it's empty.*/
188 int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty);
190 /* do an fsync() on an open file pointer.
191 Only use this during checkpointing! */
192 int gmx_fsync(FILE *fp);
194 #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && ! defined __CYGWIN__ && !defined __CYGWIN32__)
195 #define chdir _chdir
196 #define getcwd _getcwd
197 #endif
199 #ifdef __cplusplus
201 #endif
203 #endif /* _futil_h */