je voulais crée un petite programme en C sous unix qui simule la commande find avec ces option ("-perm","-name","-size").j'ai trouver des probléme pour parcourir les sous repertoire même dans certain cas pour l'identifier .
voici mon code pour l'option -perm :
#include<stdio.h>
#include<dirent.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/stat.h>
#include<ctype.h>
#include<errno.h>
#include<stdlib.h>
#include<sys/types.h>
void option_perm(char *perm,char *rep,int DIR)
{
int perm1=0;
int test=0;
int DIR1;
struct dirent *dir,*dir1;
struct stat *st;
if(isdigit(perm[0]))
{
perm1=atoi(perm);
if(perm1>=0&&perm1<=777)
{
st=malloc(sizeof(struct stat));
dir=malloc(sizeof(struct dirent));
dir1=malloc(sizeof(struct dirent));
while((dir=readdir(DIR))>0)
{
test=0;
stat(dir->d_name,st);
if(st->st_mode & S_IRUSR)
test+=400;
if(st->st_mode & S_IWUSR)
test+=200;
if(st->st_mode & S_IXUSR)
test+=100;
if(st->st_mode & S_IRGRP)
test+=40;
if(st->st_mode & S_IWGRP)
test+=20;
if(st->st_mode & S_IXGRP)
test+=10;
if(st->st_mode & S_IROTH)
test+=4;
if(st->st_mode & S_IWOTH)
test+=2;
if(st->st_mode & S_IXOTH)
test+=1;
if(perm1==test)
{
printf("%s/%s\n",rep,dir->d_name);
}
if(strcmp(dir->d_name,"..")!=0)
{
if(S_ISDIR(st->st_mode)==1)
{
if((DIR1=opendir(dir->d_name))>0)
{
option_perm(perm,dir->d_name,DIR1);
}
}
}
}
}
else
perror("erreur");
}
else
perror("erreur");
}
int main(int argc,char *argv[])
{
int DIR;
if((DIR=opendir(argv[1]))>0)
option_perm(argv[2],argv[1],DIR);
else
perror(argv[1]);
return 0;
}
si il existe un personne qui peux m'aide ,il me donne une solution est merci.