Grazie per la spiegazione chiara e concisa, ma forse ho un senso per quell'espressione:
res=e il valore ottale che mi indica la somma di quali file voglio stampare, ad esempio se res=0500 (0400 + 0100) vuole dire che stamperò tutti i file che hanno settato uno di quei bit che generano la somma dei permessi in res, nel caso precedente R ed X.
esempio:
r=0400
x=0100
r = 000 100 000 000
x = 000 001 000 000
res = r+x = 000 101 000 000
res=0500
ho testato con una cosa del genere e la cosa funge bene:
codice:
while((dir=readdir(...
switch(res){
case 0100: if (res && (S_IXUSR & (int)buf.st_mode)) printf("X:%s\n", curr_entry->d_name); break;
case 0200: if (res && (S_IWUSR & (int)buf.st_mode)) printf("W:%s\n", curr_entry->d_name); break;
case 0300: if (res && ((S_IWUSR | S_IXUSR) & (int)buf.st_mode)) printf("W e X:%s\n", curr_entry->d_name); break;
case 0400: if (res && (S_IRUSR & (int)buf.st_mode)) printf("R:%s\n", curr_entry->d_name); break;
case 0500: if (res && ((S_IRUSR | S_IXUSR) & (int)buf.st_mode)) printf("R e X:%s\n", curr_entry->d_name); break;
case 0600: if (res && ((S_IRUSR | S_IWUSR) & (int)buf.st_mode)) printf("R e W:%s\n", curr_entry->d_name); break;
case 0700: if (res && ((S_IRUSR | S_IWUSR | S_IXUSR) & (int)buf.st_mode)) printf("R,W e X:%s\n", curr_entry->d_name); break;
}
con ((S_IRUSR | S_IXUSR) & (int)buf.st_mode))
fà in modo di settare a zero i bit del gruppo e other
con if (res && ((S_IRUSR | S_IXUSR) & (int)buf.st_mode)) printf("R e X:%s\n", curr_entry->d_name);
controlla che sia un file che ha uno di quei due permess (r o x)
o meglio:
files1(permesso 0100, x) = 000 001 000 000
res=000 101 000 000
000 101 000 000 &&
000 001 000 000
-----------------------
000 001 000 000
restituisce 1 e in effetti io cercavo file con permessi x, oppure permessi r oppure permessi r ed x
verificando:
files2(permesso 0200,w) = 000 010 000 000
000 101 000 000 &&
000 010 000 000
----------------------
000 000 000 000
e in effetti io cercavo solo file con permessi r o x o entrambi
ovviamente non avendo considerato la selezione con lo switch quell'espressione non aveva tanto senso