Skip to content
Advertisement

I read more than I write in file

I have a file, partitioned in fixed sized blocks. I am copying a test_file.txt into the 3rd block of the file. I read and copied 18 bytes.

Then I am trying to copy from the file that very same .txt file I just imported to a newly created .txt, but I am writing 256 bytes to the new file. Moreover, when I try to read it, it is full of garbage.

The first function is used to import the .txt and the second one to export it.

JavaScript

Output:

JavaScript

What I am doing wrong?

Advertisement

Answer

I would replace

write(mfs_desc, buffer, s->block_size);

with

write(mfs_desc, buffer, nread);

Advertisement