#include #include #include #include #include #include ssize_t get(hid_t h, const char *name, char *buf, size_t len) { ssize_t ret = _sys_getxattr(h, name, buf, len, 0); if (ret < 0) { fprintf(stderr, "error when getting %s: %s\n", name, strerror(-ret)); } else { printf("%s: ", name); for (ssize_t i = 0; i < ret; i++) { if (isprint(buf[i])) { putchar(buf[i]); } else { printf("\\x%02x", (unsigned char)buf[i]); } } printf("\n"); } return ret; } int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: getxattr file [xattrs...]\n"); return 1; } hid_t h = camellia_open(argv[1], OPEN_READ); char buf[512]; if (h < 0) err(1, "open"); if (argc == 2) { ssize_t ret = get(h, "virt.index", buf, sizeof(buf)); if (ret < 0) return 1; if (0 < ret && buf[ret-1] != '\0') { fprintf(stderr, "index truncated\n"); } else { for (ssize_t i = 0; i < ret; i += strlen(buf+i) + 1) { char buf2[512]; get(h, buf+i, buf2, sizeof(buf2)); } } } else { for (int i = 2; i < argc; i++) { get(h, argv[i], buf, sizeof(buf)); } } }