## ftruncate

#### OS/161 Reference Manual

### Name

ftruncate - set size of a file

### Library

Standard C Library (libc, -lc)

### Synopsis

#include <unistd.h>
int
ftruncate(int fd, off_t filesize);

### Description

ftruncate forcibly sets the size of the file referred to by fd to filesize. If this expands the file, the new data appears as if it is zero-filled. If this shrinks the file, the excess data is discarded.

The file must be open for write.

### Return Values

On success, ftruncate returns 0. On error, -1 is returned, and errno is set according to the error encountered.

### Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other errors not mentioned here.

> EBADF | fd is not a valid file handle, or it is not open for writing.
> EIO | A hard I/O error occurred.
> EFAULT | buf points to an invalid address.