sorry for my bad English.I'm new to Linux system programming and new to C programming as well.
I'm copying one file to another, but after copy they differ in size. For example, the original file is 112640 bytes long and its copy is 10240 bytes (10kb) smaller, only 102400 bytes.
The code for copying is
curr_size = 0;
fdesc_output = open(path, O_RDWR|O_CREAT|O_TRUNC, 0777);
fdesc_extra_file = open(path2, O_WRONLY|O_CREAT|O_TRUNC,0777);
int lseek_position = lseek(fdesc_output,0,SEEK_SET); // return to the beginning of file
while (curr_size < desired_filesize) { //desired filesize is 100kb
size_t result = read(fdesc_output, buffer, buffer_size);
if (result < 0) {
perror ("Error reading file: ");
exit(1);
}
curr_size+=result;
write(fdesc_extra_file, buffer, buffer_size);
}