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
+5 -4
View File
@@ -22,6 +22,7 @@
#include <langinfo.h>
#include <limits.h>
#include "safesysstat.h"
#include "safeunistd.h"
#include <sys/param.h>
#ifdef __FreeBSD__
#include <osreldate.h>
@@ -179,7 +180,7 @@ RclConfig::RclConfig(const string *argcnf)
// want to avoid the imperfect test in isDefaultConfig() if we actually know
// this is the default conf
if (!autoconfdir && !isDefaultConfig()) {
if (access(m_confdir.c_str(), 0) < 0) {
if (!path_exists(m_confdir)) {
m_reason = "Explicitly specified configuration "
"directory must exist"
" (won't be automatically created). Use mkdir first";
@@ -187,7 +188,7 @@ RclConfig::RclConfig(const string *argcnf)
}
}
if (access(m_confdir.c_str(), 0) < 0) {
if (!path_exists(m_confdir)) {
if (!initUserConfig())
return;
}
@@ -1401,7 +1402,7 @@ bool RclConfig::initUserConfig()
// Use protective 700 mode to create the top configuration
// directory: documents can be reconstructed from index data.
if (access(m_confdir.c_str(), 0) < 0 &&
if (!path_exists(m_confdir) &&
mkdir(m_confdir.c_str(), 0700) < 0) {
m_reason += string("mkdir(") + m_confdir + ") failed: " +
strerror(errno);
@@ -1410,7 +1411,7 @@ bool RclConfig::initUserConfig()
string lang = localelang();
for (int i = 0; i < ncffiles; i++) {
string dst = path_cat(m_confdir, string(configfiles[i]));
if (access(dst.c_str(), 0) < 0) {
if (!path_exists(dst)) {
FILE *fp = fopen(dst.c_str(), "w");
if (fp) {
fprintf(fp, "%s\n", blurb);
+13 -1
View File
@@ -30,6 +30,16 @@
using namespace std;
// Note that we are storing each term twice. I don't think that the
// size could possibly be a serious issue, but if it was, we could
// reduce the storage a bit by storing (short hash)-> vector<int>
// correspondances in the direct map, and then checking all the
// resulting groups for the input word.
//
// As it is, a word can only index one group (the last it is found
// in). It can be part of several groups though (appear in
// expansions). I really don't know what we should do with multiple
// groups anyway
class SynGroups::Internal {
public:
Internal() : ok(false) {
@@ -40,10 +50,12 @@ public:
// Group num to group
STD_UNORDERED_MAP<int, vector<string> > groups;
};
bool SynGroups::ok()
{
return m && m->ok;
}
SynGroups::~SynGroups()
{
delete m;
@@ -215,7 +227,7 @@ int main(int argc, char **argv)
cout << group.size() << " terms in group\n";
for (vector<string>::const_iterator it = group.begin();
it != group.end(); it++) {
cout << *it << " ";
cout << "[" << *it << "] ";
}
cout << endl;
return 0;