diff --git a/src/main.cpp b/src/main.cpp index e2370ca..24cd4ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,12 +53,20 @@ static void process(const char* path) { const char* tagname {"user.xdg.tags"}; std::vector tags; std::vector buf(1024); - ssize_t sz = getxattr(path, tagname, buf.data(), buf.size()); - if (sz == -1) { - if (errno != ENODATA) { - throw_if_min1(sz); + ssize_t sz = 0; + do { + sz = getxattr(path, tagname, buf.data(), buf.size()); + if (sz == -1) { + if (errno == ERANGE) { + buf.resize(buf.size() * 2); + } else if (errno == ENODATA) { + break; + } else { + throw_if_min1(-1); + } } - } else { + } while (sz == -1 && errno == ERANGE); + if (sz > 0) { std::string val(buf.data(), sz); tags = sc::split(val, ","); }