mmaptest.c

来自「full package of jaffs file system」· C语言 代码 · 共 66 行

C
66
字号
// mmaptest.c// Used to test mmap writing (ie yaffs_writepage)//// Written by James McKenzie//#include <fcntl.h>#include <unistd.h>#include <stdio.h>#include <sys/mman.h>#include <string.h>#include <errno.h>intmain (int argc, char *argv[]){  int fd;  off_t size = 0;  void *map;  size = 6291456;  (void) unlink ("testfile");  fd = open ("testfile", O_RDWR | O_CREAT | O_TRUNC, 0666);  if (fd < 0)    {      perror ("open");      return -1;    }  if (lseek (fd, size, SEEK_SET) != size)    {      perror ("lseek");      return -1;    }  if (write (fd, "", 1) != 1)    {      perror ("write");      return -1;    }  size++;  map = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);  if (map == MAP_FAILED)    {      perror ("mmap");      return -1;    }  memset (map, 1 + (*(unsigned char *) map), size);  errno = 0;  printf ("msync(map,8536,MS_SYNC) returns %d (errno=%d [%s])\n",          msync (map, 8536, MS_SYNC), errno, strerror (errno));  (void) munmap (map, size);  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?