C language Truncate () function: Change file size
header file:
To define a function:
int truncate (const char * path, off_t length);
Function Description: Truncate () changes the file size specified by the parameter path to the size specified by the parameter length. If the original file size is larger than the parameter length, the portion of the excess is deleted.
Return value: Successful execution returns 0, failure returns-1, the reason for the error is in errno.
Error code:
1. The eaccess parameter path specifies a file that cannot be accessed.
2, Erofs to write the file exists in the read-only file system.
3, efault parameter The path pointer exceeds the accessible memory space.
4, einval parameter path contains illegal characters.
5, Enametoolong parameter path is too long.
6, enotdir parameter path path is not a directory.
7, the Eisdir parameter path points to a directory.
8, etxtbusy parameter path refers to the file as a shared program, and is being executed.
9, eloop parameter path has too many symbolic connection problems.
10, Eio I/O access errors.
C language Ftruncate () function: Change file size
header file:
To define a function:
int ftruncate (int fd, off_t length);
Function Description: ftruncate () changes the file size specified by the parameter fd to the size specified by the parameter length. The parameter fd is an open file descriptor and must be a file opened in write mode. If the original file size is larger than the parameter length, the portion of the excess is deleted.
Return value: Successful execution returns 0, failure returns-1, the reason for the error is in errno.
Error code:
1, EBADF parameter FD file descriptor is invalid or the file has been closed.
2, einval parameter FD is a socket is not a file, or the file is not opened in write mode.