#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/sendfile.h>
#include <sys/types.h>
using namespace std;
void COPY(string* files1, string *files2, int how_Many)
{
int i;
struct stat* buf_Files;
int *from_F,*to_F;
off_t *set;
buf_Files=new struct stat[how_Many];
from_F=new int[how_Many];
to_F=new int[how_Many];
set=new off_t[how_Many];
for(i=0;i<how_Many;i++)
{
from_F[i]=open(files1[i].c_str(),O_RDONLY);
fstat(from_F[i],&buf_Files[i]);
to_F[i]=open(files2[i].c_str(),O_WRONLY | O_CREAT, buf_Files[i].st_mode);
sendfile(to_F[i],from_F[i],&set[i],buf_Files[i].st_size);
close(from_F[i]);
close(to_F[i]);
}
delete set;
delete to_F;
delete from_F;
delete buf_Files;
}
int main(int argc, char **argv)
{
string to_Files[5]={"home/file1","home/file2","home/file3","home/file4","home/file5"};
string from_Files[5]={"proc/zoneinfo","proc/vstat","proc/version","proc/uptime","proc/stat"};
COPY(from_Files,to_Files,5);
return 0;
}
Brak komentarzy:
Prześlij komentarz