more safexx posix stuff
This commit is contained in:
@@ -172,7 +172,7 @@ ConfSimple::ConfSimple(const char *fname, int readonly, bool tildexp)
|
||||
// It seems that there is no separate 'create if not exists'
|
||||
// open flag. Have to truncate to create, but dont want to do
|
||||
// this to an existing file !
|
||||
if (access(fname, 0) < 0) {
|
||||
if (!path_exists(fname)) {
|
||||
mode |= ios::trunc;
|
||||
}
|
||||
input.open(fname, mode);
|
||||
|
||||
@@ -433,6 +433,11 @@ long long path_filesize(const string& path)
|
||||
return (long long)st.st_size;
|
||||
}
|
||||
|
||||
bool path_exists(const string& path)
|
||||
{
|
||||
return access(path.c_str(), 0) == 0;
|
||||
}
|
||||
|
||||
// Allowed punctuation in the path part of an URI according to RFC2396
|
||||
// -_.!~*'():@&=+$,
|
||||
/*
|
||||
|
||||
+5
-2
@@ -18,8 +18,6 @@
|
||||
#define _PATHUT_H_INCLUDED_
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
@@ -75,6 +73,11 @@ extern bool path_isdir(const std::string& path);
|
||||
/// Retrieve file size
|
||||
extern long long path_filesize(const std::string& path);
|
||||
|
||||
/// Check that path is traversable and last element exists
|
||||
/// Returns true if last elt could be checked to exist. False may mean that
|
||||
/// the file/dir does not exist or that an error occurred.
|
||||
extern bool path_exists(const std::string& path);
|
||||
|
||||
/// Dump directory
|
||||
extern bool readdir(const std::string& dir, std::string& reason,
|
||||
std::set<std::string>& entries);
|
||||
|
||||
Reference in New Issue
Block a user