Hello,
I am near to to finish the develop of the 'file services' of my OS. As I said in a previous message I wrote this functions:
fopen(): Open a file to read/write
lseek(): Set the file pointer in some place
fread(): Read N bytes from the file begining at the file pointer
fwrite(): Write N bytes to the file begining at the file pointer
fclose(): Close the file
The fopen() function can open the file for read, write or read/write modes.
The file pointer is set to zero when the file is open.
With the lseek() function the file pointer can be moved to any position inside the file, or to the EOF position. Then if I can append data to the file I just move the pointer to the EOF mark a write the data a like to append.
After each read/write operation the file pointer is moved forward the number of bytes read or written.
My problem is with the fclose() function:
If the file was open for 'write' then the file can result shorter or longer than it was when it was open. But, how can I determine where set the EOF mark?
I think to write a set_EOF() function, but I see that this is not a standar function. Maybe there is other way to do it?
Any idea?
Thank you very much!
pepito
FIle services: FIle close
RE:FIle services: FIle close
You should be able to calculate this as your apps write to the file.
Every time an application writes to a file, you simply check if the current position in the file, plus the size of the write, extends past the current file size. If it does, update the file size.
There should never be a reason for an explicit set_EOF() function.
Cheers,
Jeff
Every time an application writes to a file, you simply check if the current position in the file, plus the size of the write, extends past the current file size. If it does, update the file size.
There should never be a reason for an explicit set_EOF() function.
Cheers,
Jeff