diff options
author | Bardur Arantsson <bardur@scientician.net> | 2014-12-23 17:19:34 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2014-12-23 17:45:36 +0100 |
commit | c99353f0823cc3d34d18d4453a1dc015130b50c6 (patch) | |
tree | fd29f86b6f8640ecf0dcecc0cad25ee3cb54aa29 /src/modules.cc | |
parent | a44d5bc11bf6d7049d75169ff81c20bec96f996c (diff) |
Move private_check_user_directory() to modules.cc
We need to move it out of main.c to support our test harness.
Diffstat (limited to 'src/modules.cc')
-rw-r--r-- | src/modules.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/modules.cc b/src/modules.cc index cab3685b..a2e26fe8 100644 --- a/src/modules.cc +++ b/src/modules.cc @@ -16,6 +16,46 @@ using std::this_thread::sleep_for; using std::chrono::milliseconds; +/* + * Check and create if needed the directory dirpath + */ +bool_ private_check_user_directory(cptr dirpath) +{ + /* Is this used anywhere else in *bands? */ + struct stat stat_buf; + + int ret; + + /* See if it already exists */ + ret = stat(dirpath, &stat_buf); + + /* It does */ + if (ret == 0) + { + /* Now we see if it's a directory */ + if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) return (TRUE); + + /* + * Something prevents us from create a directory with + * the same pathname + */ + return (FALSE); + } + + /* No - this maybe the first time. Try to create a directory */ + else + { + /* Create the ~/.ToME directory */ + ret = mkdir(dirpath, 0700); + + /* An error occured */ + if (ret == -1) return (FALSE); + + /* Success */ + return (TRUE); + } +} + static void module_reset_dir_aux(char **dir, cptr new_path) { char buf[1024]; |