Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Typedefs | Functions
#include <climits>
#include <cstdio>
#include <filesystem>
#include <string>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/fileptr.h"
+ Include dependency graph for futil.h:

Description

Low-level wrappers for OS-specific file handling with some GROMACS customizations.

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...
 
bool gmx_fexist (const std::filesystem::path &fname)
 Check whether a path exists. More...
 
void make_backup (const std::filesystem::path &file)
 Makes a backup of file if the file exists.
 
FILE * gmx_ffopen (const std::filesystem::path &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::filesystem::path &filename, gmx_off_t length)
 OS-independent truncate(). More...
 
std::filesystem::path gmx::findLibraryFile (const std::filesystem::path &filename, bool bAddCWD=true, bool bFatal=true)
 Finds full path for a library file. More...
 
FilePtr gmx::openLibraryFile (const std::filesystem::path &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...
 
void gmx_file_rename (const std::filesystem::path &oldname, const std::filesystem::path &newname)
 OS-independent rename(). More...
 
int gmx_file_copy (const std::filesystem::path &oldname, const std::filesystem::path &newname, 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 std::filesystem::path &directory)
 OS-independent chdir(). More...
 
std::filesystem::path gmx_getcwd ()
 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 Documentation

typedef int64_t gmx_off_t

GROMACS definition to use instead of off_t.

Function Documentation

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 std::filesystem::path &  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().

bool gmx_fexist ( const std::filesystem::path &  fname)

Check whether a path exists.

Returns
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::filesystem::path &  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 std::filesystem::path &  oldname,
const std::filesystem::path &  newname,
bool  copy_if_empty 
)

Copies a file (data only) oldname to newname.

If newname exists, it is overwritten.

If copy_if_empty is false, the file won't be copied if it's empty.

void gmx_file_rename ( const std::filesystem::path &  oldname,
const std::filesystem::path &  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().

Returns
0 when successful, or -1 (and set errno) in case of error.
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().

Returns
The current offset when successful, or -1 (and set errno) in case of error.
std::filesystem::path gmx_getcwd ( )

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::filesystem::path &  filename,
gmx_off_t  length 
)

OS-independent truncate().