文件系统:目录与文件

This commit is contained in:
lzy
2024-04-30 20:41:19 +08:00
parent ba9f2e37a7
commit 5399da7488
11 changed files with 776 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
{
if (argc < 2)
{
fprintf(stderr, "Usage:...\n");
exit(1);
}
int fd;
fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd < 0)
{
perror("open()");
exit(1);
}
// 生成一个5G的文件
// !!! 整数溢出
lseek(fd, 5LL * 1024LL * 1024LL * 1024LL - 1LL, SEEK_SET);
// 写入尾0
write(fd, "", 1);
close(fd);
exit(0);
}