Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Implementing cat command using system calls.

--------------------------------------------------------------------------------

Description : this program will implement the cat command using systam calls

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
int main(int argc,char *argv[])
{
int f=0,n;
char l[80];
struct stat s;
if(argc!=2)
{
printf("Mismatch argument");
exit(1);
}
if(access(argv[1],F_OK))
{
printf("File Exist");
exit(1);
}
if(stat(argv[1],&s)<0)
{
printf("Stat ERROR");
exit(1);
}
if(S_ISREG(s.st_mode)<0)
{
printf("Not a Regular FILE");
exit(1);
}
if(geteuid()==s.st_uid)
if(s.st_mode & S_IRUSR)
f=1;
else if(getegid()==s.st_gid)
if(s.st_mode & S_IRGRP)
f=1;
else if(s.st_mode & S_IROTH)
f=1;
if(!f)
{
printf("Permission denied");
exit(1);
}
f=open(argv[1],O_RDONLY);
while((n=read(f,l,80))>0)
write(1,l,n);
}

 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG