Home » NO IDEA » File copying using the system call

File copying using the system call

Blog Stats

  • 13,912 hits
April 2013
M T W T F S S
« Mar   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

#include <syscall.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <stdio.h>
int main(int argc,char * argv[])
{
int fd;
fd=open(argv[1],O_CREAT | O_RDONLY);
if(fd==-1)
{
printf("error opening the file");
}
void *buf = (char*) malloc(120);
int count=read(fd,buf,120);
printf("count : %d",count);
printf("%s",buf);
close(fd);
int f1;
f1=open(argv[2],O_CREAT | O_WRONLY);
if(f1==-1)
{
printf("error opening the file");
}
int c;
while(count=read(fd,buf,120)>0)
{
c=write(f1,buf,120);
}
if(c==-1)
{
printf("error writing to the file");
}
close(f1);
}

Advertisements

2 Comments

  1. Amritha says:

    i think you should include the header to prevent any warnings from being shown. also in line 16 ‘buf’ has been declared as void* but when you print it, you are using character control format. that is also shown as a warning when executed. hope you will make the necessary changes to the program…

  2. Amritha says:

    include stdlib.h… one warning will surely be removed..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: