File, Directory Permissions

- Added default and override permissions for files and directories.
This commit is contained in:
Paul Beckingham 2013-07-07 13:04:19 -04:00
parent 061bf4882e
commit 82c4b05fe4
6 changed files with 50 additions and 10 deletions

View file

@ -28,6 +28,7 @@
#include <cmake.h>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <pwd.h>
#include <unistd.h>
@ -90,10 +91,11 @@ File& File::operator= (const File& other)
}
////////////////////////////////////////////////////////////////////////////////
bool File::create ()
bool File::create (int mode /* = 0640 */)
{
if (open ())
{
fchmod (_h, mode);
close ();
return true;
}
@ -361,12 +363,14 @@ time_t File::btime () const
}
////////////////////////////////////////////////////////////////////////////////
bool File::create (const std::string& name)
bool File::create (const std::string& name, int mode /* = 0640 */)
{
std::ofstream out (expand (name).c_str ());
std::string full_name = expand (name);
std::ofstream out (full_name.c_str ());
if (out.good ())
{
out.close ();
chmod (full_name.c_str (), mode);
return true;
}