/* * Copyright 2022, Jaidyn Levesque * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include char* get_xattr(const char* path, const char* attr, int* error_code) { ssize_t value_length = getxattr(path, attr, NULL, 0); if (value_length == -1) { *error_code = errno; return NULL; } char* value = (char*) malloc(value_length); ssize_t new_length = getxattr(path, attr, value, value_length); *error_code = (new_length == -1) ? errno : 0; return value; } int set_xattr(const char* path, const char* attr, const char* value, int* error_code) { int retcode = lsetxattr(path, attr, value, strlen(value), 0); *error_code = (retcode == 0) ? 0 : errno; return retcode; } char* list_xattr(const char* path, ssize_t* size, int* error_code) { ssize_t value_size = llistxattr(path, NULL, 0); if (value_size == -1) { *error_code = errno; return NULL; } char* value = (char*) malloc(value_size); *size = llistxattr(path, value, value_size); *error_code = (*size == -1) ? errno : 0; return value; } int remove_xattr(const char* path, const char* attr) { if (lremovexattr(path, attr) == -1) return errno; else return 0; }