block scheme of the copying a file

Can anyone show a block scheme of the algorithm when copying а file in oprationg system?
Are you wanting it flowcharted? I can't do that for you but here's a simple file copy routine in C++.


void copyFile(std::string fname1, std::string fname2, unsigned long long size)
{
std::ifstream ifs(fname1, std::ios::in | std::ios::binary);
std::ofstream ofs(fname2, std::ios::out | std::ios::binary | std::ios::trunc);

if (!ifs.is_open())
{
cout << "\nCan't open file " << fname1 << " for input!" << endl;
return;
}

if (!ofs.is_open())
{
cout << "\nCan't open file " << fname2 << " for output!" << endl;
return;
}

char buf[4096];
int chunk;

while (size)
{
chunk = (size < 4096) ? size : 4096;

ifs.read(buf, chunk);
ofs.write(buf, chunk);

size -= chunk;
}

ifs.close();
ofs.close();
}


I left out minor details like checking whether the reads and writes succeed, but that should mostly get it done for you. Cheers.
Topic archived. No new replies allowed.