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

📄 test8_8.txt

📁 Linux下的C语言编程
💻 TXT
字号:
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>

int write_buffer(int fd, const void *buf, int count);

int main(void)
{
	int outfile;
	char *mapped;
	char *ptr;
	int count;

	if(outfile=open("test.dat", O_RDWR|O_CREAT|O_TRUNC, 0640)==-1)
	{
		printf("COULDN’T OPEN THIS FILE!\n");
		exit(254);
	}

	lseek(outfile, 1000, SEEK_SET);
	if(write(outfile, "\0",1)==-1)
	{
		printf("ERROR, WRITE FAILED!\n");
		exit(254);
	}
	mapped=mmap(NULL, 1000, PROT_READ|PROT_WRITE,MAP_SHARED, outfile, 0);
	if(!mapped)
	{
		printf("ERROR, MMAP FAILED!\n");
		exit(254);
	}

	for(count=0; count<1000; count++)
	{
		if(*(mapped+count)>=97&&*(mapped+count)<=122)
			*(mapped+ count)-= 32;
	}

	msync(mapped, 1000, MS_SYNC);
	munmap(mapped,1000);

	if(!close(outfile))
	{
		printf("POSSIBLY SERIOUS ERROR,CLOSE FILE FAILED");
		exit(254);
	}
	return 0;
}

⌨️ 快捷键说明

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