diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-03-16 13:00:28 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-03-16 13:00:28 -0500 |
commit | 8ff477ab1a3d9392dc6d68e15eaa24c887fa2e0f (patch) | |
tree | 30cecbef5909274cedb73b4d68d23c29be2ceee0 /libs/pbd/file_utils.cc | |
parent | 11a702149ea2e4a7bc858a2aeb4ea8efe12502ba (diff) |
add PBD::toggle_file_existence()
Diffstat (limited to 'libs/pbd/file_utils.cc')
-rw-r--r-- | libs/pbd/file_utils.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 5a0ffa928f..804f825b94 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -484,4 +484,17 @@ tmp_writable_directory (const char* domain, const string& prefix) return new_test_dir; } +int +toggle_file_existence (string const & path) +{ + if (Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) { + return g_unlink (path.c_str()); + } + + int fd = g_open (path.c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666); + GError* err; + g_close (fd, &err); + return !(fd >= 0); +} + } // namespace PBD |