xattr: comments v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 13 Jan 2019 16:44:11 +0100
branchv_0
changeset 3 62eac7ab4cf4
parent 2 f07ed604a0ab
child 4 d44ed75822e7
xattr: comments
src/FilesystemCommand.h
--- a/src/FilesystemCommand.h	Sun Jan 13 03:13:07 2019 +0100
+++ b/src/FilesystemCommand.h	Sun Jan 13 16:44:11 2019 +0100
@@ -87,10 +87,13 @@
 
 	string_t getXattr(const fs::path& file, const string_t& attributeName) {
 		// TODO: review, test on multiple platforms
+		// TODO: improve documentation in xattr.h in glibc
+		// TODO: check XATTR_NAME_MAX in limits.h and if it is reasonably small on our system, allocate buffer for it instead of reading twice
+		// TODO: avoid race condition (another process might change the attribute between reading its length and its value)
 		ssize_t length = getxattr(file.c_str(), convertor.to_bytes(attributeName).c_str(), nullptr, 0);
 		if (length > 0) {
 			std::vector<char> buffer(length + 1);
-			getxattr(file.c_str(), convertor.to_bytes(attributeName).c_str(), buffer.data(), length);
+			getxattr(file.c_str(), convertor.to_bytes(attributeName).c_str(), buffer.data(), buffer.size());
 			return convertor.from_bytes(buffer.data());
 		} else {
 			return L"";