FIle services: FIle close
Posted: Mon Feb 09, 2004 12:00 am
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
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