UNIXworkcode

/* * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * Version 2, December 2004 * * Copyright (C) 2016 Olaf Wintermann <olaf.wintermann@gmail.com> * * Everyone is permitted to copy and distribute verbatim or modified * copies of this license document, and changing it is allowed as long * as the name is changed. * * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION * * 0. You just DO WHAT THE FUCK YOU WANT TO. */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> /* * Solaris Extended Attributes Example * * get attribute content */ int main(int argc, char **argv) { if(argc < 3) { fprintf(stderr, "Usage: %s <file> <attribute>\n", argv[0]); return -1; } int file = open(argv[1], O_RDONLY); if(file == -1) { fprintf(stderr, "Cannot open file ''%s'': ", argv[1]); perror(NULL); return -1; } int attr = openat(file, argv[2], O_RDONLY|O_XATTR); if(attr == -1) { fprintf(stderr, "Cannot open attribute ''%s'': ", argv[2]); perror(NULL); return -1; } char buf[1024]; ssize_t r = 0; while((r = read(attr, buf, 1024)) > 0) { write(STDOUT_FILENO, buf, r); } return 0; }