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 <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <fcntl.h> /* * Solaris Extended Attributes Example * * list all attributes */ int main(int argc, char **argv) { if(argc < 2) { fprintf(stderr, "Usage: %s <file>", 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 attrdir = openat(file, ".", O_RDONLY|O_XATTR); DIR *dir = fdopendir(attrdir); if(!dir) { perror("fdopendir"); return -1; } struct dirent *ent; while((ent = readdir(dir)) != NULL) { if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) { continue; } printf("%s\n", ent->d_name); } return 0; }