/* Finding type of a file */

20/10/2010 22:57

/* program takes its commmand line arguments and prints the type of
file for each ommand line argument*/
#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
int main(int argc,char * argv[])
{
int I;
struct stat buf;
char *ptr;
for(I=1;I<argc;I++)
{

        printf("%s",argv[1]);
        if(lstat(argv[1],&buf)<0)
        {
//      err_ret("lstat error");
        continue;
        }
        if(S_ISREG(buf.st_mode))
        ptr="Regular";
        else if(S_ISDIR(buf.st_mode))
        ptr="Directory";
        else if(S_ISCHR(buf.st_mode))
        ptr="Block special";
        else if(S_ISFIFO(buf.st_mode))
        ptr="fifo";
        printf("%s\n",ptr);

}
exit(0);
}

Bookmark and Share

Done by Aarya