Gromacs
2019
|
#include <climits>
#include <cstdio>
#include <string>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/fileptr.h"
Low-level wrappers for OS-specific file handling with some GROMACS customizations.
Macros | |
#define | GMX_PATH_MAX 4096 |
Maximum path length, if the OS provides one, otherwise a fixed constant. | |
Typedefs | |
typedef int64_t | gmx_off_t |
GROMACS definition to use instead of off_t . More... | |
Functions | |
void | gmx_disable_file_buffering () |
Turn off buffering for output files (which is default) for debugging purposes. More... | |
void | gmx_set_max_backup_count (int count) |
Enables backups with the specified number of maximum backups. More... | |
gmx_bool | gmx_fexist (const std::string &fname) |
Check whether a path exists. More... | |
void | make_backup (const std::string &file) |
Makes a backup of file if the file exists. | |
FILE * | gmx_ffopen (const std::string &file, const char *mode) |
Opens a file, with GROMACS-specific additions. More... | |
int | gmx_ffclose (FILE *fp) |
Closes a file opened with gmx_ffopen(). More... | |
void | frewind (FILE *fp) |
Wraps rewind() for files opened with gmx_ffopen(). More... | |
int | gmx_fseek (FILE *stream, gmx_off_t offset, int whence) |
OS-independent 64-bit fseek(). More... | |
gmx_off_t | gmx_ftell (FILE *stream) |
OS-independent 64-bit ftell(). More... | |
int | gmx_truncate (const std::string &filename, gmx_off_t length) |
OS-independent truncate(). More... | |
std::string | gmx::findLibraryFile (const std::string &filename, bool bAddCWD=true, bool bFatal=true) |
Finds full path for a library file. More... | |
std::string | gmx::findLibraryFile (const char *filename, bool bAddCWD=true, bool bFatal=true) |
Finds full path for a library file. More... | |
FilePtr | gmx::openLibraryFile (const std::string &filename, bool bAddCWD=true, bool bFatal=true) |
Opens a library file for reading in an RAII-style FILE handle. More... | |
FilePtr | gmx::openLibraryFile (const char *filename, bool bAddCWD=true, bool bFatal=true) |
Opens a library file for reading in an RAII-style FILE handle. More... | |
FILE * | gmx_fopen_temporary (char *buf) |
Creates unique name for temp file (wrapper around mkstemp) and opens it. More... | |
void | gmx_tmpnam (char *buf) |
Creates unique name for temp file (wrapper around mkstemp). More... | |
int | gmx_file_rename (const char *oldname, const char *newname) |
OS-independent rename(). More... | |
int | gmx_file_copy (const char *oldname, const char *newname, gmx_bool copy_if_empty) |
Copies a file (data only) oldname to newname. More... | |
int | gmx_fsync (FILE *fp) |
OS-independent fsync(). More... | |
void | gmx_chdir (const char *directory) |
OS-independent chdir(). More... | |
void | gmx_getcwd (char *buffer, size_t size) |
OS-independent getcwd(). More... | |
const DataFileFinder & | gmx::getLibraryFileFinder () |
Gets a finder for locating data files from share/top/. More... | |
void | gmx::setLibraryFileFinder (const DataFileFinder *finder) |
Sets a finder for location data files from share/top/. More... | |
typedef int64_t gmx_off_t |
GROMACS definition to use instead of off_t
.
void frewind | ( | FILE * | fp | ) |
Wraps rewind() for files opened with gmx_ffopen().
A fatal error results if this function is called for a pipe (a compressed input file).
void gmx_chdir | ( | const char * | directory | ) |
OS-independent chdir().
Exits with a fatal error if changing the directory fails.
void gmx_disable_file_buffering | ( | ) |
Turn off buffering for output files (which is default) for debugging purposes.
This only has effect on files opened with gmx_ffopen().
gmx_bool gmx_fexist | ( | const std::string & | fname | ) |
Check whether a path exists.
TRUE
when fname
exists.Note that this returns TRUE
even if fname
is a directory instead of a file.
int gmx_ffclose | ( | FILE * | fp | ) |
Closes a file opened with gmx_ffopen().
FILE* gmx_ffopen | ( | const std::string & | file, |
const char * | mode | ||
) |
Opens a file, with GROMACS-specific additions.
If the file is in compressed format, opens a pipe which uncompresses the file on the fly. For this to work, gmx_ffclose() and frewind() should always be used for files opened with gmx_ffopen() instead of fclose() and rewind(). For compressed files, the file
parameter should be passed without the compressed extension; if that file is not found, then a few compression extensions are tried. Creates a backup if a file opened for writing already exists before overwriting it. A fatal error results if the file cannot be opened, for whatever reason.
int gmx_file_copy | ( | const char * | oldname, |
const char * | newname, | ||
gmx_bool | copy_if_empty | ||
) |
Copies a file (data only) oldname to newname.
If copy_if_empty
is FALSE
, the file won't be copied if it's empty.
int gmx_file_rename | ( | const char * | oldname, |
const char * | newname | ||
) |
OS-independent rename().
Renames/moves a file atomically, if the OS makes that available.
FILE* gmx_fopen_temporary | ( | char * | buf | ) |
Creates unique name for temp file (wrapper around mkstemp) and opens it.
buf
should be at least 7 bytes long
int gmx_fseek | ( | FILE * | stream, |
gmx_off_t | offset, | ||
int | whence | ||
) |
OS-independent 64-bit fseek().
int gmx_fsync | ( | FILE * | fp | ) |
OS-independent fsync().
Only use this during checkpointing!
gmx_off_t gmx_ftell | ( | FILE * | stream | ) |
OS-independent 64-bit ftell().
void gmx_getcwd | ( | char * | buffer, |
size_t | size | ||
) |
OS-independent getcwd().
Exits with a fatal error if the call fails.
void gmx_set_max_backup_count | ( | int | count | ) |
Enables backups with the specified number of maximum backups.
If count
== 0, disables backups. If not called, this is the default. If count
== -1, reads the count from an environment variable.
This is not currently thread-safe, as it is only called during initialization code.
void gmx_tmpnam | ( | char * | buf | ) |
Creates unique name for temp file (wrapper around mkstemp).
buf
should be at least 7 bytes long
int gmx_truncate | ( | const std::string & | filename, |
gmx_off_t | length | ||
) |
OS-independent truncate().