Linux服务器编程之:truncate()函数+案例说明
来源:互联网 发布:数据字典是用来定义 编辑:程序博客网 时间:2024/05/22 05:06
1.依赖头文件
#include<unistd.h>
#include<sys/types.h>
2.函数定义:
int truncate(const char *path,off_t length);
int ftruncate(int fd,off_t length);
函数说明:
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.
翻译:truncate()和ftruncate()函数导致一个名称为path或者被文件描述符fd引用的常规文件被截断成一个大小精为length字节的文件。
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').
翻译:如果先前的文件大于这个大小,额外的数据丢失。如果先前的文件小于当前定义的大小,那么,这个文件将会被扩展,扩展的部分将补以null,也就是‘\0’
If the size changed, then the st_ctime and st_mtime fields (respec‐
tively, time of last status change and time of last modification; see
stat(2)) for the file are updated, and the set-user-ID and set-group-ID
permission bits may be cleared.
翻译:如果大小发生变化,那么这个st_ctime(访问时间)和st_mtime()修改时间将会被更新。
With ftruncate(), the file must be open for writing; with truncate(),
the file must be writable.
翻译:使用ftruncate(),这个文件必须被打开用以写操作。使用truncate函数的文件必须能够被写
3.案例说明:
- Linux服务器编程之:truncate()函数+案例说明
- Linux服务器编程之:link()函数,ln命令,symlink,readlink,案例说明
- Linux服务器编程之:link()函数,ln命令,symlink,readlink,案例说明
- Linux服务器编程之:utime()函数
- Linux服务器编程——Linux系统编程(2)之I/O函数
- 9Linux服务器编程之:mkdir()函数和rmdir()函数
- linux编程常用函数说明
- linux编程 select函数说明
- Linux服务器编程之:chown()函数,chown命令
- linux下c编程系统调用之有名管道FIFO函数的使用及案例
- linux socket编程主要函数功能说明
- Linux网络编程入门必备函数说明
- Linux网络编程入门必备函数说明
- linux服务器编程之select
- linux网络编程之服务器
- 10Linux服务器编程之:opendir()函数,readdir()函数,rewinddir()函数,telldir()函数和seekdir()函数,closedir()函数
- 《Linux网络编程》综合案例web服务器shttpd
- linux网络编程之用一张图片说明套接口常用函数
- hdu 5015 233 Matrix 2014 ACM/ICPC Asia Regional Xi'an Online 矩阵快速幂
- 猫推荐算法大赛Top 9团队
- Openstack icehouse ubuntu 部署 - 虚拟机网络配置(GRE配置版本)
- HDU 5009 Paint Pearls(西安网络赛C题)
- Java深入 - Java Socket和NIO
- Linux服务器编程之:truncate()函数+案例说明
- Java集合框架的知识总结(1)
- 【转】数学专业的数学与计算机专业的数学的比较
- Distributed transactions with multiple databases, Spring Boot, Spring Data JPA and Atomikos
- OO and Procedural
- HDU 5007 Post Robot(字符串寻找)
- HDU 1089 A+B for Input-Output Practice (I)
- SVN服务器客户端搭建版本控制
- 连连看