#include #include #include /* * compile: * gcc -W -Wall -O3 -pipe -o fxattr fxattr.c */ int main(int argc, char** argv) { ssize_t ret, pos, ret2; char buf[4096], buf2[4096]; char *src, *dst; if (argc < 2) { fprintf(stderr, "fxattr - show and copy extended attributes " "without dereferencing symbolic links\n\n" "usage:\n to show extended attributes:\n" " %s \n\n to copy extended attributes:\n" " %s \n", argv[0], argv[0]); return -1; } src = argv[1]; dst = argv[2]; ret = listxattr(src, buf, sizeof(buf), XATTR_NOFOLLOW); if (ret < 0) { perror("listxattr()"); return -1; } printf("%s:", src); for (pos = 0; pos < ret; pos += strlen(buf + pos) + 1) { ret2 = getxattr(src, buf + pos, buf2, sizeof(buf2), 0, XATTR_NOFOLLOW); if (ret2 < 0) { perror("getxattr()"); return -1; } printf(" %s(%li)", buf + pos, ret2); if (dst) { if (setxattr(dst, buf + pos, buf2, ret2, 0, XATTR_NOFOLLOW) < 0) { perror("setxattr()"); return -1; } } } puts(""); return 0; }