czwartek, 6 lutego 2020

Copying files (C++ Linux)

#include <iostream>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/sendfile.h>
#include <sys/types.h>

#define size_F 10

using namespace std;

string proc_Date[size_F]={"/proc/dma","/proc/misc","/proc/meminfo","/proc/kcore","/proc/keys","/proc/iomen",
"/proc/slabinfo","/proc/version","/proc/zoneinfo","/proc/cpuinfo"};
string dest_Date[size_F]={"dma1","misc1","meminfo1","kcore1","keys1","iomen1","slabinfo1","version1","zoneinfo1",
"cpuinfo1"};

off_t *o_F;
int *r,*w;
struct stat* run_Stat;

int main(int argc, char **argv)
{
o_F=new off_t[size_F];
run_Stat=new struct stat[size_F];
r=new int[size_F];
w=new int[size_F];
for(int i=0;i<size_F;i++)
{
r[i]=open(proc_Date[i].c_str(),O_RDONLY);
fstat(r[i],&run_Stat[i]);
w[i]=open(dest_Date[i].c_str(),O_WRONLY | O_CREAT,run_Stat[i].st_size);
sendfile(w[i],r[i],&o_F[i],run_Stat[i].st_size);
close(r[i]);
close(w[i]);
}
delete w;
delete r;
delete run_Stat;
delete o_F;

return 0;
}

Brak komentarzy:

Prześlij komentarz