SetEndOfFile Function
The SetEndOfFile function sets the specified end-of-file (EOF) position for the file that is associated with the specified file handle.
HANDLE hFile
);
Parameters
hFile- [in] Handle to the file.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The SetEndOfFile function truncates or extends the file to the specified EOF position. If the file is extended, the contents of the file between the old EOF position and the new EOF position are not defined. If the file is truncated, data beyond the new EOF position is lost.
The file handle must have been created with the GENERIC_WRITE access right.
To set the EOF position, you typically use CreateFile with GENERIC_WRITE and then call SetEndOfFile. If you want to extend the file, you might first call SetFilePointerEx to move the file pointer to the desired new EOF position, then call SetEndOfFile.
Requirements
| Interface | Basic file I/O |
|---|---|
| Header | Windows.h |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |