📄 prg12_6.c
字号:
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define FILE "test.data"
#define SIZE 32768
int main(int argc,char **argv)
{
int fd,i;
char *ptr;
fd = open(FILE,O_RDWR | O_CREAT | O_TRUNC,FILE_MODE);
ptr = mmap(NULL,SIZE,PROT_READ | PROT_WRITE,MAP_SHARED,fd,0);
for (i=4096;i<=SIZE;i+=4096)
{
printf("setting file size to %d\n",i);
ftruncate(fd,i);
printf("ptr[%d]=%d\n",i-1,ptr[i-1]);
}
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -