more safexx posix stuff

This commit is contained in:
Jean-Francois Dockes
2015-08-22 08:37:58 +02:00
parent f095e38633
commit 62f4f7bd81
18 changed files with 50 additions and 18 deletions
+1 -1
View File
@@ -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);
+5
View File
@@ -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
View File
@@ -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);