niedziela, 24 maja 2020

Sendfile (linux, g++)

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

#define size_F 7

using namespace std;

string base_Proc[size_F]={"/proc/cpuinfo","/proc/version","/proc/meminfo","/proc/partitions","/proc/keys","/proc/cgroups","/proc/devices"};
string my_Files[size_F]={"CPU","VERSION","MEMINFO","PARTITIONS","KEYS","CGROUPS","DEVICES"};
int file_R[size_F],file_W[size_F];
struct stat* info_S;
off_t *offset_F;

int main(int argc, char **argv)
{
  info_S=new struct stat[size_F];
  offset_F=new off_t[size_F];
  for(int i=0;i<size_F;i++)
  {
      file_R[i]=open(base_Proc[i].c_str(),O_RDONLY);
      fstat(file_R[i],&info_S[i]);
      file_W[i]=open(my_Files[i].c_str(),O_WRONLY | O_CREAT,info_S[i].st_mode);
      sendfile(file_W[i],file_R[i],&offset_F[i],info_S[i].st_size);
      close(file_R[i]);
      close(file_W[i]);
  }
  delete offset_F;
  delete info_S;   
   
    return 0;
}



Brak komentarzy:

Prześlij komentarz