Handle windows paths: mostly change tests for relative, and some other tweaks.

--HG--
branch : WINDOWSPORT
This commit is contained in:
Jean-Francois Dockes
2015-08-31 17:20:04 +02:00
parent 3aeffea387
commit 94da56aadc
12 changed files with 46 additions and 19 deletions
+11 -5
View File
@@ -574,8 +574,8 @@ bool ConfSimple::hasNameAnywhere(const string& nm) const
int ConfTree::get(const std::string &name, string &value, const string &sk)
const
{
if (sk.empty() || sk[0] != '/') {
// LOGDEB((stderr, "ConfTree::get: looking in global space\n"));
if (sk.empty() || !path_isabsolute(sk) ) {
// LOGDEB((stderr, "ConfTree::get: looking in global space for sk [%s]\n", sk.c_str()));
return ConfSimple::get(name, value, sk);
}
@@ -588,15 +588,21 @@ int ConfTree::get(const std::string &name, string &value, const string &sk)
// Look in subkey and up its parents until root ('')
for (;;) {
// LOGDEB((stderr,"ConfTree::get: looking for '%s' in '%s'\n",
// name.c_str(), msk.c_str()));
LOGDEB((stderr,"ConfTree::get: looking for '%s' in '%s'\n",
name.c_str(), msk.c_str()));
if (ConfSimple::get(name, value, msk))
return 1;
string::size_type pos = msk.rfind("/");
if (pos != string::npos) {
msk.replace(pos, string::npos, string());
} else
} else {
#ifdef _WIN32
if (msk.size() == 2 && isalpha(msk[0]) && msk[1] == ':')
msk.clear();
else
#endif
break;
}
}
return 0;
}
+5 -2
View File
@@ -75,7 +75,7 @@ class DLFWImpl {
} else {
fp = fopen(filename, (truncate) ? "w" : "a");
if (fp) {
setvbuf(fp, 0, _IOLBF, 0);
setvbuf(fp, 0, _IOLBF, BUFSIZ);
#ifdef O_APPEND
{
int flgs = 0;
@@ -83,7 +83,10 @@ class DLFWImpl {
fcntl(fileno(fp), F_SETFL, flgs|O_APPEND);
}
#endif
}
} else {
fprintf(stderr, "Debuglog: could not open [%s] errno %d\n",
filename, errno);
}
}
return;
}
+15 -3
View File
@@ -380,10 +380,11 @@ string path_getfather(const string &s) {
if (father.empty())
return "./";
if (path_isroot(father))
return father;
if (father[father.length() - 1] == '/') {
// Input ends with /. Strip it, handle special case for root
if (father.length() == 1)
return father;
// Input ends with /. Strip it, root special case was tested above
father.erase(father.length()-1);
}
@@ -514,6 +515,17 @@ string path_tildexpand(const string &s)
return o;
}
bool path_isroot(const string& path)
{
if (path.size() == 1 && path[0] == '/')
return true;
#ifdef _WIN32
if (path.size == 3 && isalpha(path[0]) && path[1] == ':' && path[2] == '/')
return true;
#endif
return false;
}
bool path_isabsolute(const string &path)
{
if (!path.empty() && (path[0] == '/'
+3
View File
@@ -111,6 +111,9 @@ extern const std::string& path_sharedatadir();
/// Test if path is absolute
extern bool path_isabsolute(const std::string& s);
/// Test if path is root (x:/). root is defined by root/.. == root
extern bool path_isroot(const std::string& p);
/// Temporary file class
class TempFileInternal {
public:
+5
View File
@@ -78,6 +78,11 @@ const int RDBUFSZ = 8192;
bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
size_t cnttoread, string *reason)
{
if (startoffs < 0) {
*reason += " file_scan: negative startoffs not allowed";
return false;
}
bool ret = false;
bool noclosing = true;
int fd = 0;