您的位置:首页 > 运维架构 > Linux

Linux ftruncate函数

2013-06-23 23:23 183 查看
NAME
truncate, ftruncate - truncate a file to a specified length

SYNOPSIS
#include <unistd.h>
#include <sys/types.h>

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

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

truncate():
_BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L

ftruncate():
_BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
|| /* Since glibc 2.3.5: */ _POSIX_C_SOURCE >= 200112L

DESCRIPTION
The  truncate()  and ftruncate() functions cause the regular file named
by path or referenced by fd to be truncated  to  a  size  of  precisely
length bytes.

If  the  file  previously  was larger than this size, the extra data is
lost.  If the file previously was shorter,  it  is  extended,  and  the
extended part reads as null bytes ('\0').

The file offset is not changed.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: