1c.c

来自「liunx下的shell实现;进程、线程同步的实现;I/O系统调用的比较(mma」· C语言 代码 · 共 44 行

C
44
字号
#include <stdio.h>#include <stdlib.h>#include <sys/mman.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define PERMS 0600int main(){int src,i=0;char *sm,temp;struct stat statbuf;size_t fz;src=open("text",O_RDWR);if(src<0){printf("can't open this file\n");return 1;}if(fstat(src,&statbuf)<0){printf("fstat failed!\n");return 1;}fz=statbuf.st_size;sm=mmap(0,fz,PROT_WRITE|PROT_READ,MAP_SHARED,src,0);if(MAP_FAILED==sm){printf("map failed!\n");return 1;}for(i=0;i<fz/2;i++){temp=*(sm+i);*(sm+i)=*(sm+fz-1-i);*(sm+fz-1-i)=temp;}msync(sm,fz,MS_SYNC);close(src);return 1;}

⌨️ 快捷键说明

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