代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
int main() {
const char *filename = "/mnt/file";
int buf_size = 100 * 1024 * 1024; // 读100M
char *buffer = malloc(buf_size);
ssize_t bytes_read;
// 打开文件
int fd = open(filename, O_RDONLY, 0644);
if (fd == -1) {
perror("无法打开文件");
return 1;
}
printf("文件已打开 (fd=%d)\n", fd);
// 读取并显示文件前4096字节
lseek(fd, 0, SEEK_SET);
bytes_read = read(fd, buffer, buf_size - 1);
if (bytes_read > 0) {
buffer[bytes_read] = '\0';
printf("读了 %zd 字节:\n", bytes_read);
}
// 无限循环等待
while (1) {
sleep(1);
}
// 这行代码永远不会执行
close(fd);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。