文件I/O系统调用与磁盘特殊文件操作详解
1. truncate和ftruncate系统调用
在文件操作中, truncate 和 ftruncate 系统调用有着独特的用途。 truncate 可通过文件路径来截断或扩展文件,而 ftruncate 则通过文件描述符实现相同功能。
- 函数原型
-
truncate:
-
#include <unistd.h>
int truncate(
const char *path,
/* pathname */
off_t length
/* new length */
);
/* Returns 0 on success or -1 on error (sets errno) */
- `ftruncate`:
#include <unistd.h>
int ftruncate(
int fd,
/* file descriptor */
off_t length
/* new length */
);
/* Returns 0 on success or -1 on error (sets er
truncate与磁盘文件操作解析
超级会员免费看
订阅专栏 解锁全文

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



