diff --git a/src/fs.cpp b/src/fs.cpp index 5cae7eae..50097980 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -170,31 +169,6 @@ namespace fs return (errno=ENOENT,-1); } - void - glob(const vector &patterns, - vector &strs) - { - int flags; - size_t veclen; - glob_t gbuf = {0}; - - veclen = patterns.size(); - if(veclen == 0) - return; - - flags = 0; - glob(patterns[0].c_str(),flags,NULL,&gbuf); - - flags = GLOB_APPEND; - for(size_t i = 1; i < veclen; i++) - glob(patterns[i].c_str(),flags,NULL,&gbuf); - - for(size_t i = 0; i < gbuf.gl_pathc; ++i) - strs.push_back(gbuf.gl_pathv[i]); - - globfree(&gbuf); - } - void realpathize(vector &strs) { diff --git a/src/fs.hpp b/src/fs.hpp index a5926b67..864d99a6 100644 --- a/src/fs.hpp +++ b/src/fs.hpp @@ -53,9 +53,6 @@ namespace fs const int fd, string &basepath); - void glob(const vector &patterns, - vector &strs); - void realpathize(vector &strs); int getfl(const int fd); diff --git a/src/fs_glob.cpp b/src/fs_glob.cpp new file mode 100644 index 00000000..421762bf --- /dev/null +++ b/src/fs_glob.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2018, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +#include +#include + +using std::string; +using std::vector; + +namespace fs +{ + void + glob(const vector &patterns_, + vector &strs_) + { + int flags; + size_t veclen; + glob_t gbuf = {0}; + + veclen = patterns_.size(); + if(veclen == 0) + return; + + flags = GLOB_NOCHECK; + ::glob(patterns_[0].c_str(),flags,NULL,&gbuf); + + flags = GLOB_APPEND|GLOB_NOCHECK; + for(size_t i = 1; i < veclen; i++) + ::glob(patterns_[i].c_str(),flags,NULL,&gbuf); + + for(size_t i = 0; i < gbuf.gl_pathc; ++i) + strs_.push_back(gbuf.gl_pathv[i]); + + ::globfree(&gbuf); + } +} diff --git a/src/fs_glob.hpp b/src/fs_glob.hpp new file mode 100644 index 00000000..6858c291 --- /dev/null +++ b/src/fs_glob.hpp @@ -0,0 +1,28 @@ +/* + Copyright (c) 2018, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include + +namespace fs +{ + using std::string; + using std::vector; + + void + glob(const vector &patterns_, + vector &strs_); +} diff --git a/src/option_parser.cpp b/src/option_parser.cpp index bb674b0d..93cac5ce 100644 --- a/src/option_parser.cpp +++ b/src/option_parser.cpp @@ -29,6 +29,7 @@ #include #include "config.hpp" +#include "fs_glob.hpp" #include "num.hpp" #include "policy.hpp" #include "str.hpp" diff --git a/src/setxattr.cpp b/src/setxattr.cpp index c9dc1038..e01fdffd 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -25,6 +25,7 @@ #include "config.hpp" #include "errno.hpp" #include "fs_base_setxattr.hpp" +#include "fs_glob.hpp" #include "fs_path.hpp" #include "num.hpp" #include "rv.hpp"