Linux服务器编程之:truncate()函数+案例说明

简介: 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()

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.案例说明:

 






目录
相关文章
|
14天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
17天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 &lt;&lt;EOF binary put file.txt quit EOF ```
28 4
|
1天前
|
存储 算法 数据挖掘
服务器数据恢复—昆腾存储StorNext文件系统数据恢复案例
服务器数据恢复环境: 昆腾某型号存储,8个存放数据的存储柜+1个存放元数据的存储柜。 元数据存储:8组RAID1阵列+1组RAID10阵列+4个全局热备硬盘。 数据存储:32组RAID5阵列,划分2个存储系统。 服务器故障: 数据存储的1个存储系统中的一组RAID5阵列中有2块硬盘先后出现故障离线,导致该RAID5阵列失效,整个存储系统崩溃不可用。
服务器数据恢复—昆腾存储StorNext文件系统数据恢复案例
|
4天前
|
网络协议 安全 Linux
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
|
10天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1228 8
|
16天前
|
Linux 开发者
Linux文件编程(open read write close函数)
通过这些函数,开发者可以在Linux环境下进行文件的读取、写入和管理。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
84 4