void my_double_ls(char *dirname)
{
struct dirent *d;
struct stat statbuf;
DIR *dp;
if ((dp = opendir(dirname)) == NULL)
exit(1);
while ((d = readdir(dp)) != NULL)
{
if (d->d_ino != 0)
{
d->d_name[d->d_namlen] = 0;
if (stat(d->d_name, &statbuf) == -1)
{
printf("%s %d %d %d\n", d->d_name, S_ISDIR(statbuf.st_mode), S_ISREG(statbuf.st_mode), d->d_namlen);
}
else
{
if (S_ISDIR(statbuf.st_mode))
{
printf("%s *\n", d->d_name);
}
else
{
printf("%s\n", d->d_name);
}
}
}
}
closedir(dp);
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("wrong argument numbers\n");
exit(1);
}
my_double_ls(argv[1]);
return 0;
}
I've written like that but when i insert file name
and check with stat function
all stat's return value of name of d(dirent) were -1 and
S_ISDIR was always true for even if txt file exist
what is wrong with that?