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()函数+案例说明相关推荐

  1. linux读取文件修改时间函数,Linux服务器编程之utime()函数修改文件存取时间

    Linux服务器编程之utime()函数修改文件存取时间 C语言utime()函数:修改文件的存取时间和更改时间 头文件: #include #include 定义函数: int utime(cons ...

  2. linux网络编程之Listen函数参数介绍

    1.listen()函数介绍 listen函数使用主动连接套接口变为被连接套接口,使得一个进程可以接受其它进程的请求,从而成为一个服务器进程.在TCP服务器编程中listen函数把进程变为一个服务器, ...

  3. Linux服务器编程之:link()函数,ln命令,symlink,readlink,案例说明

    1 link()依赖头文件 #include<unistd.h> 2函数定义 int link(const char *oldpath,const char *newpath); 函数说明 ...

  4. Linux服务器编程之:chown()函数,chown命令

    1.依赖的头文件 #include<unistd.h> 2.函数定义: //通过传入path的方式,改变和文件的拥有关系,如果他是一个符号链接,则跟踪它 int chown(const c ...

  5. linux chown 函数用噶,Linux服务器编程之:chown()函数,chown命令

    1.依赖的头文件 #include 2.函数定义: //通过传入path的方式,改变和文件的拥有关系,如果他是一个符号链接,则跟踪它 int chown(const char *path, uid_t ...

  6. Linux服务器编程之:utime()函数

    1.依赖的头文件 #include<sys/types.h> #include<utime.h> 2函数声明 int utime(const char *filename, c ...

  7. linux ioctl网络参数设置,Linux 网络编程之ioctl函数

    1.介绍 Linux网络程序与内核交互的方法是通过ioctl来实现的,ioctl与网络协议栈进行交互,可得到网络接口的信息,网卡设备的映射属性和配置网络接口.并且还能够查看,修改,删除ARP高速缓存的 ...

  8. Linux 应用编程之stat 函数

    Linux 下可以使用 stat 命令查看文件的属性,其实这个命令内部就是通过调用 stat()函数来获取文件属性的,stat 函数是 Linux 中的系统调用,用于获取文件相关的信息.(可通过&qu ...

  9. Linux应用编程之dup函数和dup2函数

    在 Linux 系统中,open 返回得到的文件描述符 fd 可以进行复制,复制成功之后可以得到一个新文件描述符,使用新的文件描述符和旧的文件描述符都可以对文件进行 IO 操作,复制得到的文件描述符和 ...

最新文章

  1. Python pandas用法
  2. 5分钟 NLP 系列: Word2Vec和Doc2Vec
  3. WPF usercontrol 自定义依赖属性
  4. java 新功能_Java 14的新功能
  5. query builder python-elasticsearch返回指定字段
  6. 去除网页上图片的虚框和a文字链接上的虚框
  7. 一个宝妈如何完成逆袭做到月入5万+,单品利润破20万的
  8. 2-PowerShell 对象,查询操作和格式化
  9. 张口就问“CCIE”月薪多少
  10. 全新自助任务平台WQ源码对接微信带分类信息线报完美运营驴赚网全量开源发布
  11. 北风的年终总结2021
  12. LeetCode 第35题 搜索插入位置 做题记录
  13. 为什么外包公司这么不受欢迎??
  14. 关于Render在不同情况的用法
  15. 大数据培训就业班毕业后通常可以从事哪些领域做哪些方面工作
  16. 近期爬虫学习体会以及爬豆瓣Top250源码实战
  17. 遇见你,是我幸福的开始
  18. VB操作EXCEL方法汇总
  19. Android ViewFlipper 用例
  20. 计算机虚拟化(HCIA)

热门文章

  1. VTK:采样函数用法实战
  2. wxWidgets:支持国际化
  3. boost::process::env相关的测试程序
  4. 使用 Boost.MPI 的 split() 操作对通信器的示例
  5. boost::mp11::mp_replace_at相关用法的测试程序
  6. boost::hana::cycle用法的测试程序
  7. boost::geometry::box_view用法的测试程序
  8. boost::fusion::set用法的测试程序
  9. boost::core模块实现分配构造throws
  10. Boost:实现了k-means聚类算法