Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 8

truncate()

Truncate a file to a specified length

Synopsis:

#include <unistd.h>

int truncate( const char* path,
              off_t length );

Arguments:

path
The path name of the file that you want to truncate.
length
The new size of the file.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The truncate() function causes the regular file named by path to have a size of length bytes.

The effect of truncate() on other types of files is unspecified. If the file previously was larger than length, the extra data is lost. If it was previously shorter than length, bytes between the old and new lengths are read as zeroes. The process must have write permission for the file.

If the request would cause the file size to exceed the soft file size limit for the process, the request fails and the implementation generates the SIGXFSZ signal for the process.

This function doesn't modify the file offset for any open file descriptions associated with the file. On successful completion, if the file size is changed, truncate() marks for update the st_ctime and st_mtime fields of the file, and if the file is a regular file, the S_ISUID and S_ISGID bits of the file mode may be cleared.

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

EACCES
A component of the path prefix denies search permission, or write permission is denied on the file.
EFAULT
The path argument points outside the process's allocated address space.
EFBIG
The length argument was greater than the maximum file size.
EINTR
A signal was caught during execution.
EINVAL
The length argument is invalid, or the path argument isn't an ordinary file.
EIO
An I/O error occurred while reading from or writing to a filesystem.
EISDIR
The named file is a directory.
ELOOP
Too many symbolic links were encountered in resolving path.
EMFILE
The maximum number of file descriptors available to the process has been reached.
EMULTIHOP
Components of path require hopping to multiple remote machines and filesystem type doesn't allow it.
ENAMETOOLONG
The length of the specified pathname exceeds PATH_MAX bytes, or the length of a component of the pathname exceeds NAME_MAX bytes.
ENFILE
Additional space couldn't be allocated for the system file table.
ENOENT
A component of path doesn't name an existing file or path is an empty string.
ENOLINK
The path argument points to a remote machine and the link to that machine is no longer active.
ENOTDIR
A component of the path prefix of path isn't a directory.
EROFS
The named file resides on a read-only filesystem.

Classification:

POSIX 1003.1 XSI

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

chmod(), fcntl(), ftruncate(), open()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 229

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/truncate.html on line 229