System Software Lab Programs ( UNIX Programs ) – 3b
// June 2nd, 2009 // Educational, Engineering, Unix and System Software Lab
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
[Click Here to get other programs by email ]
………………………………………………………………………………………………………………………….
PART -B
………………………………………………………………………………………………………………………….
Problem Definition : C program that accepts valid file names as command line arguments and for each of the arguments, prints the type of the file (Regular file, Directory file, Character special file, Block special file, Symbolic link etc.)
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc,char *argv[])
{
int i;
struct stat buf;
for(i=1;i<=argc;i++)
{
printf(“%s”,argv[i]);
if(lstat(argv[i],&buf)==-1)
{
printf(“nlstat error..n”);
continue;
}
if(S_ISREG(buf.st_mode))
printf(“nRegular filen”);
else if(S_ISDIR(buf.st_mode))
printf(“nDirectory filen”);
else if(S_ISCHR(buf.st_mode))
printf(“nCharacter special filen”);
else if(S_ISBLK(buf.st_mode))
printf(“nBlock special filen”);
else if(S_ISLNK(buf.st_mode))
printf(“nSymbolic link filen”);
else
printf(“nUnknown filen”);
return 0;
}
}



