#ifdef DEBUG
char *sanitized_value = sanitize_value(value, value_size);
- debug_print("name=%s sanitized_value=%s value_size=%zu\n", name, sanitized_value, value_size);
+ debug_print("name='%s' name_size=%zu sanitized_value='%s' value_size=%zu\n", name, name_size, sanitized_value, value_size);
free(sanitized_value);
#endif
if (fwrite(&value_size, sizeof(size_t), 1, file) != 1) {
return -1;
}
- if (fwrite(value, value_size, 1, file) != 1) {
- return -1;
+ // write value content only if we have something to write.
+ if (value_size > 0) {
+ if (fwrite(value, value_size, 1, file) != 1) {
+ return -1;
+ }
}
return 0;
read_value = xattr.getxattr(self.randomFile, key)
self.assertEqual(value, read_value.decode(enc))
+ def test_xattr_set_empty(self):
+ enc = "utf-8"
+ key = "user.foo"
+ value = ""
+ xattr.setxattr(self.randomFile, key, bytes(value, enc))
+ read_value = xattr.getxattr(self.randomFile, key)
+ self.assertEqual(value, read_value.decode(enc))
+
def test_xattr_set_override(self):
enc = "utf-8"
key = "user.foo"