poniedziałek, 29 listopada 2021

Copying to Multiple Files (C++)

 


#include <iostream>

#include <string.h>

#include <fcntl.h>

#include <unistd.h>

#include <stdlib.h>

#include <stdio.h>

#include <sys/types.h>

#include <sys/sendfile.h>

#include <sys/stat.h>


using namespace std;



class copy_File

{

private:

string rname;

string *names;

int s;

int *files_W;

off_t temp_Off;

public:

copy_File(int s1,string* mNames, string rName)

{

int i;

s=s1;

names=new string[s];

for(i=0;i<s;i++)

names[i]=mNames[i];

rname=rName;

files_W=new int [s];

temp_Off=0;

}

~copy_File()

{

delete files_W;

delete names;

}

void send_F()

{

int file_R,i;

struct stat buff_Fil;

file_R=open(rname.c_str(),O_RDONLY);

fstat(file_R,&buff_Fil);

for(i=0;i<s;i++)

{

files_W[i]=open(names[i].c_str(),O_WRONLY | O_CREAT,buff_Fil.st_mode);

sendfile(files_W[i],file_R,&temp_Off,buff_Fil.st_size);

}

close(file_R);

for(i=0;i<s;i++)

close(files_W[i]);

}

};

 





int main(int argc, char **argv)

{

string read_Name="chromo.cxx";

string weeks[7]={"Monday","Tuesday","Wednesday","Thursday","Friday",

"Saturday","Sunday"};

copy_File m_File(7,weeks,read_Name);

m_File.send_F();

return 0;

}


Brak komentarzy:

Prześlij komentarz