|
CoolProp 8.0.0
An open-source fluid property and humid air property database
|
#include "CoolProp/detail/PlatformDetermination.h"#include "CoolProp/Exceptions.h"#include "CoolProp/detail/filepaths.h"#include "CoolProp/detail/strings.h"#include "CoolProp/detail/tools.h"#include <fstream>#include <algorithm>#include <atomic>#include <cerrno>#include <filesystem>#include <random>#include <sstream>#include <stdexcept>#include <system_error>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <pwd.h>Go to the source code of this file.
Macros | |
| #define | NOMINMAX |
Functions | |
| unsigned long long | CalculateDirSize (const std::string &path) |
| std::vector< char > | get_binary_file_contents (const char *filename) |
| Get all the contents of a binary file. More... | |
| void | write_bytes_atomic (const std::filesystem::path &target, const void *bytes, std::size_t size, bool restrict_perms) |
| void | make_dirs (const std::string &file_path) |
| Make directory and all required intermediate directories. More... | |
| std::string | get_separator () |
| Get directory separator. More... | |
| std::string | get_home_dir () |
| Get the user's home directory; It is believed that is is always a place that files can be written. More... | |
| bool | path_exists (const std::string &path) |
| Return true if path exists. More... | |
| std::string | join_path (const std::string &one, const std::string &two) |
| Return merged path, append separator if string two is empty. More... | |
| std::string | get_file_contents (const char *filename) |
| #define NOMINMAX |
Definition at line 19 of file CPfilepaths.cpp.
| unsigned long long CalculateDirSize | ( | const std::string & | path | ) |
Get the size of a directory in bytes. Uses std::filesystem on modern platforms (Windows, Linux, macOS). Legacy Android/powerpc stub returns 0.
Definition at line 41 of file CPfilepaths.cpp.
| std::vector< char > get_binary_file_contents | ( | const char * | filename | ) |
Get all the contents of a binary file.
Definition at line 87 of file CPfilepaths.cpp.
| std::string get_file_contents | ( | const char * | filename | ) |
Definition at line 319 of file CPfilepaths.cpp.
| std::string get_home_dir | ( | ) |
Get the user's home directory; It is believed that is is always a place that files can be written.
Definition at line 226 of file CPfilepaths.cpp.
| std::string get_separator | ( | ) |
Get directory separator.
Definition at line 206 of file CPfilepaths.cpp.
| std::string join_path | ( | const std::string & | one, |
| const std::string & | two | ||
| ) |
Return merged path, append separator if string two is empty.
Definition at line 299 of file CPfilepaths.cpp.
| void make_dirs | ( | const std::string & | file_path | ) |
Make directory and all required intermediate directories.
Definition at line 167 of file CPfilepaths.cpp.
| bool path_exists | ( | const std::string & | path | ) |
Return true if path exists.
Definition at line 270 of file CPfilepaths.cpp.
| void write_bytes_atomic | ( | const std::filesystem::path & | target, |
| const void * | bytes, | ||
| std::size_t | size, | ||
| bool | restrict_perms = false |
||
| ) |
Atomically write size bytes from bytes to target.
Writes to a sibling <target>.tmp.<process-salt>.<seq> first, then std::filesystem::renames onto the target. The rename is atomic on POSIX same-filesystem and on Win32 (replace-existing semantics), so concurrent writers in different processes / threads either see the previous complete file or one complete writer's payload — never a partial-write file on the visible path.
The temp-path suffix combines a process-unique 64-bit salt (drawn once per process from std::random_device) with a process-local atomic counter, so concurrent writers never collide on their intermediates.
When restrict_perms is true, the temp file is chmod'd to owner-only (0600) before the rename, so the post-rename file inherits the tight permissions without a brief world-readable window. No-op on Windows where the POSIX permission model doesn't apply.
Throws std::runtime_error on open/write/rename failure; the temp file is unlinked before throwing. Assumes target.parent_path() already exists.
Definition at line 132 of file CPfilepaths.cpp.