⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1c.c

📁 liunx下的shell实现;进程、线程同步的实现;I/O系统调用的比较(mmap)——操作系统的课程设计
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -