Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ truncate(2) — GL2 W2.5r1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

open(2)

TRUNCATE(2)  —  Silicon Graphics

NAME

truncate, ftruncate − truncate a file to a specified length

SYNOPSIS

truncate (path, length)
char *path;
long length;

ftruncate (fd, length)
int fd;
long length;

DESCRIPTION

Truncate causes the file named by path or referenced by fd to be truncated to at most length bytes in size.  If the file previously was larger than this size, the extra data is lost.  With ftruncate, the file must be open for writing. If length is negative, the file is truncated to zero. 

Truncate succeeds unless:

The pathname was too long.  ­[ENOENT]

A component of the path prefix of path is not a directory.  ­[ENOTDIR]

The named file does not exist.  ­[ENOENT]

A component of the path prefix denies search permission.  ­[EACCES]

The named file is a directory.  ­[EISDIR]

The named file resides on a read-only file system.  ­[EROFS]

The file is a pure procedure (shared text) file that is being executed.  ­[ETXTBSY]

Path points outside the process’s allocated address space.  ­[EFAULT]

Ftruncate succeeds unless:

The fd is not a valid descriptor.  ­[EBADF]

RETURN VALUE

A value of 0 is returned if the call succeeds.  If the call fails a −1 is returned, and the global variable errno specifies the error. 

SEE ALSO

open(2)

ASSEMBLER

moveq#31,D0| truncate
movlpath,A0
movllength,D1
trap#0

Carry bit set on failure and cleared on success.
moveq#32,D0| ftruncate
movlfd,A0
movllength,D1
trap#0

Carry bit set on failure and cleared on success.

BUGS

Partial blocks discarded as the result of truncation are not zero filled; this can result in holes in files which do not read as zero. 

These calls should be generalized to allow ranges of bytes in a file to be discarded. 

Version 2.5r1  —  October 29, 1986

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026