#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
//判断参数够不够
if (argc < 1) {
fprintf(stderr, "Usage:...\n");
exit(1);
}
//打开一个文件,没有就创建,权限600
int fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0600);
//把pos直接拉到5G的位置,如果不加ll,会溢出报错
lseek(fd, 5ll*1024ll*1024ll*1024ll-1, SEEK_SET);
//执行一次系统调用
write(fd, "", 1);
//关闭文件
close(fd);
//退出程序
exit(0);
}
制作一个5GB的空洞文件
最新推荐文章于 2025-05-22 09:18:59 发布