|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Changes the size of a file. This is a version of _chsize with security enhancements as described in .
File descriptor referring to an open file.
New length of the file in bytes.
_chsize_s returns the value 0 if the file size is successfully changed. A nonzero return value indicates an error: the return value is EACCES if the specified file is locked against access, EBADF if the specified file is read-only or the descriptor is invalid, ENOSPC if no space is left on the device, or EINVAL if size is less than zero. errno is set to the same value.
For more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.
The _chsize_s function extends or truncates the file associated with fd to the length specified by size. The file must be open in a mode that permits writing. Null characters ('\0') are appended if the file is extended. If the file is truncated, all data from the end of the shortened file to the original length of the file is lost.
_chsize_s takes a 64-bit integer as the file size, and therefore can handle file sizes greater than 4 GB. _chsize is limited to 32-bit file sizes.
This function validates its parameters. If fd is not a valid file descriptor or size is less than zero, the invalid parameter handler is invoked, as described in .
|Routine||Required header||Optional header||Compatibility|
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003
For more compatibility information, see Compatibility in the Introduction.