bj a tous: voila une implémentation de ls -l en c qui n'est pas complète
il ya quelques erreurs au niveau l'affichage des droits d'accés.....
est ce qu'il ya qq1 qui peut m'aider j'en est vraiment besoin:
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
main(int argc, char *argv[])
{
DIR *rep_cour; //crée un pointeur de type repertoire
struct dirent *entree; // crée un structure entrée repertoire
struct stat info;
struct passwd *p;
struct group *g;
char user[3],group[3],other[3],username,grname;
//# p=getpwuid(info.st_uid);
//# g=getgrgid(info.st_gid);
//Byte us1=0100;
rep_cour = opendir(".");// met dans rep_cour ce qui est lu dans le repertoire courant
while (entree=readdir(rep_cour))// tant que il n'est pas arrivé a la fin du repertoire
{
if(entree->d_name[0] != '.')//test si le premier est un caractère.
{
stat(entree->d_name,&info);
user[0]=((info.st_mode && 0000000100000000) ? 'r' : '-');
user[1]=((info.st_mode && 0000000010000000) ? 'w' : '-');
user[2]=((info.st_mode && 0000000001000000) ? 'x' : '-');
group[0]=((info.st_mode && 0000000000100000) ? 'r' : '-');
group[1]=((info.st_mode && 0000000000010000) ? 'w' : '-');
group[2]=((info.st_mode && 0000000000001000) ? 'x' : '-');
other[0]=((info.st_mode && 0000000000000100) ? 'r' : '-');
other[1]=((info.st_mode && 0000000000000010) ? 'w' : '-');
other[2]=((info.st_mode && 0000000000000001) ? 'x' : '-');
//p = getpwnam( (int) info.st_uid);
//username = (int) p->pw_name;
//g = getgrnam( (int) info.st_gid);
//grname = (int) g->gr_name;
printf("%d %d %s %s %s %s\n", entree->d_ino,info.st_nlink,user,group,other,/*username,grname,*/entree->d_name);
}
}
return 0;
}
et si possible les couleurs pendant l'affichage.
merci d'avvvvvvvvvvvvvvvvvance..........;;