ocarina/libsaria/fs.cpp
Bryan Schumaker 292d237561 libsaria: Idle queue cleanups
To make the code easier to follow and maintain.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
2012-04-07 10:01:15 -04:00

52 lines
962 B
C++

// Copyright (c) 2012 Bryan Schumaker.
#include <libsaria/fs.h>
#include <libsaria/task.h>
#include <libsaria/print.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
static string appdir;
static mode_t dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
static void make_dir(string path)
{
println("Making directory: " + path);
mkdir(path.c_str(), dirmode);
}
namespace libsaria
{
void app::mkdir()
{
make_dir(appdir.c_str());
}
void app::init(string name)
{
string home = getenv("HOME");
appdir = home + "/." + name;
#ifdef DEBUG
appdir += "-debug";
#endif
mkdir();
}
void app::save(string file, void (*func)(ofstream &), DataState *state)
{
new WriteTask(appdir + "/" + file, func, state);
}
void app::read_now(string file, void (*func)(ifstream &))
{
ifstream stream;
stream.open((appdir + "/" + file).c_str());
func(stream);
stream.close();
}
} /* Namespace: libsaria */