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.
Linux ftruncate函数
最新推荐文章于 2025-04-24 13:03:15 发布
本文详细介绍了Linux系统中用于调整文件大小的两个关键函数:truncate和ftruncate。阐述了它们的功能、使用方法、参数需求及特性测试宏要求,深入分析了文件被截断时的行为变化,包括文件大小调整后的数据丢失或填充情况,以及函数在不同版本的glibc中的适应性。
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

2865

被折叠的 条评论
为什么被折叠?



