I'm trying to create a method that will do some system calls. It should display the owner of and octal code of each file. but somehow I cant get going. It displays the logged in user name as owner of each file
listContents(char * dir) {
struct dirent *direntp;
DIR *dirp;
if ((dirp = opendir(dir) ) == NULL)
{
perror ("Failed to open directory");
return 1;
}
while((direntp=readdir(dirp))!=NULL) {
struct stat fileInfo;
if (stat(direntp->d_name, &fileInfo) == 0);
{
struct passwd * pInfo = getpwuid(fileInfo.st_uid);
if(pInfo!=NULL)
{
printf("owner is : %s\toctal permisions is: %o\n", pInfo->pw_name, fileInfo.st_mode);
}
}
}
while ((closedir(dirp) == -1) && (errno == EINTR)) ;
return 0;
}