8 #include <attr/xattr.h>
9 #include <attr/attributes.h>
15 int bkselect(char *path, int s)
26 if(attr_get(path, "bkselect", ab, &al, 0)) {
27 if(errno == ENOATTR) {
28 } else if(errno == EPERM) {
29 /* Ignore for now because of weird effects... */
30 } else if(errno == E2BIG) {
31 fprintf(stderr, "warning: bad bkselect value on %s", path);
38 if(!strcmp(ab, "y")) {
40 } else if(!strcmp(ab, "n")) {
43 fprintf(stderr, "warning: bad bkselect value on %s", path);
47 if((d = opendir(path)) == NULL) {
54 pb = malloc(pbl = pl + 2);
57 while((de = readdir(d)) != NULL) {
58 if(!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
60 if(strlen(de->d_name) + pl + 2 > pbl) {
61 pbl = strlen(de->d_name) + pl + 2;
62 pb = realloc(pb, pbl);
64 strcpy(pb + pl + 1, de->d_name);
69 if(S_ISDIR(sb.st_mode)) {
72 } else if(S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode)) {
87 fprintf(stderr, "usage: bkselect [-hsqo] [path...]\n");
90 int main(int argc, char **argv)
95 while((c = getopt(argc, argv, "hsqo")) >= 0) {
109 exit((c == 'h')?0:1);
112 if(argc - optind < 1) {
113 r = bkselect(".", s);
116 for(i = optind; i < argc; i++) {
117 if(bkselect(argv[i], s))
122 printf("%lli\n", tsize);