Jestem w trakcie pisania swojego ls -l. Moj problem: program wyswietla złych wlascicieli pliku. np root zamiast mnie albo ja zamiast innego uzytkownika.
#include <dirent.h>
#include <pwd.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
void ls(char *);
int main(int argc, char *argv[]){
ls(argv[1]);
return 0;
}
void ls(char *path){
DIR *dire=opendir(path);
if(!dire){
printf("Nie ma takiego katalogu\n");
return;
}
struct dirent *dp;
struct stat buf;
struct passwd *pwd;
while((dp = readdir(dire)) != NULL){
if(dp->d_name[0] == '.')
continue;
printf("%s", dp->d_name);
stat(dp->d_name, &buf);
pwd = getpwuid(buf.st_uid);
printf(" %d ", buf.st_uid);
printf(" %s\n", pwd->pw_name);
}
closedir(dire);
}