- if (((dir == 0) || (stat (dir, &file_stat) == -1)
- || (!S_ISDIR (file_stat.st_mode))) && (idx != 0))
+ /* check dir existance and access rights for effective user/group IDs */
+ if ((dir == NULL)
+ ||
+ (faccessat ( /* ignored */ -1, dir, F_OK | R_OK | W_OK, AT_EACCESS)
+ < 0))