Fix: enlarge buffer when too small

This commit is contained in:
Bob Polis 2024-07-24 12:38:15 +02:00
parent cb8f1abca7
commit 3555c35457

View File

@ -53,12 +53,20 @@ static void process(const char* path) {
const char* tagname {"user.xdg.tags"};
std::vector<std::string> tags;
std::vector<char> 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, ",");
}