#include #include #include #include #include #include int main(int argc,char ** argv) { const char * path=(argc>1 ? argv[1] : "."); DIR * dir=opendir(path); struct dirent * entry; if(!dir) { fprintf(stderr,"Can't open directory %s !\n",path); return(1); } do { entry=readdir(dir); if(entry) { struct stat infos; char buffer[0x100]; strcpy(buffer,path); strcat(buffer,"/"); strcat(buffer,entry->d_name); if(lstat(buffer,&infos)!=-1) { if(S_ISBLK(infos.st_mode)) strcat(buffer,": BLOCK DEVICE"); else if(S_ISCHR(infos.st_mode)) strcat(buffer,": CHARACTER DEVICE"); else if(S_ISDIR(infos.st_mode)) strcat(buffer,": DIRECTORY"); else if(S_ISFIFO(infos.st_mode)) strcat(buffer,": FIFO"); else if(S_ISLNK(infos.st_mode)) strcat(buffer,": SYMBOLIC LINK"); else if(S_ISREG(infos.st_mode)) strcat(buffer,": REGULAR FILE"); else if(S_ISSOCK(infos.st_mode)) strcat(buffer,": SOCKET"); else strcat(buffer,": ???"); } else strcat(buffer,": ???"); fprintf(stderr,"%s\n",buffer); } } while(entry); closedir(dir); return(0); }