]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/utils.cpp
Throw an exception for nonsensical arguments in some FS functions
[libs/core.git] / source / fs / utils.cpp
index 2bfd1bf3ff4c63d9152084fe1ffdc0b802223aa5..ed1ca0ab27c3e3c14070b88822e50cc742ca067c 100644 (file)
@@ -71,6 +71,9 @@ Path fix_case(const Path &path)
 
 Path relative(const Path &path, const Path &base)
 {
 
 Path relative(const Path &path, const Path &base)
 {
+       if(path.is_absolute()!=base.is_absolute())
+               throw invalid_argument("FS::relative");
+
        Path::Iterator i = path.begin();
        Path::Iterator j = base.begin();
        for(; (i!=path.end() && j!=base.end() && *i==*j); ++i, ++j) ;
        Path::Iterator i = path.begin();
        Path::Iterator j = base.begin();
        for(; (i!=path.end() && j!=base.end() && *i==*j); ++i, ++j) ;
@@ -96,6 +99,9 @@ Path common_ancestor(const Path &path1, const Path &path2)
 
 int descendant_depth(const Path &path, const Path &parent)
 {
 
 int descendant_depth(const Path &path, const Path &parent)
 {
+       if(path.is_absolute()!=parent.is_absolute())
+               throw invalid_argument("FS::descendant_depth");
+
        Path::Iterator i = path.begin();
        Path::Iterator j = parent.begin();
        for(; (i!=path.end() && j!=parent.end() && *i==*j); ++i, ++j) ;
        Path::Iterator i = path.begin();
        Path::Iterator j = parent.begin();
        for(; (i!=path.end() && j!=parent.end() && *i==*j); ++i, ++j) ;