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 file\n”);
else if(S_ISDIR(buf.st_mode))
printf(“\nDirectory file\n”);
else if(S_ISCHR(buf.st_mode))
printf(“\nCharacter special file\n”);
else if(S_ISBLK(buf.st_mode))
printf(“\nBlock special file\n”);
else if(S_ISLNK(buf.st_mode))
printf(“\nSymbolic link file\n”);
else
printf(“\nUnknown file\n”);
return 0;
}
}
[Click Here to get other programs by email ]
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:
Top Commentators
Abhijeet (1)
Balachandra (1)
blaaze (1)
Guest Guestington (1)
julious (1)




