core: use C++ std::strings for default directory and filename

The memory management and string concatenation was hard to follow.

Since the mobile files ios.cpp and android.cpp were already
converted to C++, let's do the same for Unix, Windows and MacOS.

Simply store the default directory and filename in a function-level
static string. Thus, it will be initialized on first call and
freed on application exit. Since the std::string data is
guaranteed to be contiguous and zero-terminated, it can be used
from C code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-04-29 11:43:17 +02:00 committed by bstoeger
parent 7771b444a1
commit 540cba07f3
8 changed files with 167 additions and 225 deletions

View file

@ -47,7 +47,6 @@ int main(int argc, char **argv)
logfile_name = strdup("subsurface-downloader.log");
const char *default_directory = system_default_directory();
const char *default_filename = system_default_filename();
subsurface_mkdir(default_directory);
if (subsurface_user_is_root() && !force_root) {
@ -107,8 +106,6 @@ int main(int argc, char **argv)
clear_divelog(&divelog);
taglist_free(g_tag_list);
parse_xml_exit();
free((void *)default_directory);
free((void *)default_filename);
// Sync struct preferences to disk
qPref::sync();