Use
opendir()
and
readdir()
to get the directory information, then check ownership and permissions. If permissions are restricted check if the user is the owner or a member of the group that has access.
See
here[
^] for the Linux man pages, containing further information.