libsaria: Create the saria dir on startup

This is either ~/.saria or ~/.saria-debug, depending on if we're running
a debug build or not.
This commit is contained in:
Bryan Schumaker 2011-09-22 08:21:57 -04:00
parent 250964a351
commit a97da1dd05
3 changed files with 26 additions and 0 deletions

View File

@ -14,5 +14,7 @@ struct file
};
void readdir(string, vector<file> &, vector<file> &);
string get_saria_dir();
void make_saria_dir();
#endif /* LIBSARIA_PATH_H */

View File

@ -1,12 +1,16 @@
#include <libsaria/libsaria.h>
#include <libsaria/audio.h>
#include <libsaria/path.h>
#include <libsaria/print.h>
void libsaria_init(int argc, char **argv)
{
println("Initializing libsaria");
audio_init(argc, argv);
print("saria dir: ");
println(get_saria_dir());
make_saria_dir();
}
void libsaria_quit()

View File

@ -1,6 +1,7 @@
#include <dirent.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <libsaria/path.h>
#include <iostream>
@ -50,3 +51,22 @@ void readdir(string dir, vector<file> &files, vector<file> &dirs)
closedir(dp);
}
#ifdef DEBUG
static string SARIA_DIR = "/.saria-debug";
#else /* DEBUG */
static string SARIA_DIR = "/.saria";
#endif /* DEBUG */
string get_saria_dir()
{
string saria = getenv("HOME");
return saria += SARIA_DIR;
}
void make_saria_dir()
{
string saria = get_saria_dir();
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
mkdir(saria.c_str(), mode);
}