#include #include #include #include #include #include #include #include #include #include #include #include //----------------------------------------------------------------------------- #if !defined(PLATFORM_WIN32) #include #include "acl.hpp" void do_xattr (char const *path) { std::cout << ", xattr: "; { std::cout << "{ "; std::string attr_list (1024, '\0'); { auto res = listxattr (path, attr_list.data (), attr_list.size ()); if (res < 0) cruft::posix::error::throw_code (); attr_list.resize (res); } std::string keybuffer (64, '\0'); std::string val (128, '\0'); cruft::view attr_view { attr_list.data (), attr_list.size () }; for (auto const &key: cruft::tokeniser (attr_view, '\0')) { keybuffer.resize (0); std::copy (std::begin (key), std::end (key), std::back_inserter (keybuffer)); while (true) { auto const res = getxattr (path, keybuffer.c_str (), val.data (), val.size ()); if (res < 0 && errno == E2BIG) { val = "___E2BIG"; break; } if (res < 0 && errno == ERANGE) { val.resize (val.size () * 2); continue; } if (res < 0) cruft::posix::error::throw_code (); val.resize (res); break; } std::cout << keybuffer << ": " << val << ", "; } std::cout << "}"; } } //----------------------------------------------------------------------------- void do_acl (char const *path) { std::cout << cruft::acl (path, ACL_TYPE_ACCESS) << '\n'; } #else void do_xattr (char const *) { } void do_acl (char const *) { } #endif /////////////////////////////////////////////////////////////////////////////// int main (int argc, char **argv) { if (argc < 2) { std::cerr << argv[0] << " ...\n"; return EXIT_FAILURE; } for (int i = 1; i < argc; ++i) { std::cout << "{ stat: "; char const *path = argv[i]; std::cout << cruft::posix::stat (path); do_xattr (path); do_acl (path); std::cout << '\n'; } }