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() 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()函数