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

📄 wfifo.c

📁 Linux网络编程FIFO源码。wfifo.c创建并打开文件
💻 C
字号:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int fd;
	int i = 0;
	char buff[4];
	int TT=S_IRWXU | S_IRWXG | S_IRWXO;
	printf("TT=%do\n",TT);
	printf("TT=%o\n",TT);
	
	printf("S_IRWXG=%o\n",S_IRWXG);
	printf("S_IRWXO=%o\n",S_IRWXO);
	
	//fd = open("test_fifo.txt", O_WRONLY|O_CREAT)
	//fd = open("test_fifo.txt", O_WRONLY|O_CREAT,S_IRWXU);//S_IRWXU: quanxian rwx------
	fd = open("test_fifo.txt", O_WRONLY|O_CREAT,S_IRWXU | S_IRWXG | S_IRWXO);
	printf("S_IRWXU=%o\n",S_IRWXU);
	
	if(fd < 0){
		printf("open error\n");
		exit(1);
	}

	while(1){
		sleep(1);
		sprintf(buff, "%d", ++i);
		if(write(fd, buff, sizeof(buff)) < 0){
			printf("write error\n");
		}else{
			printf("wrote [%s] ok\n", buff);
		}
	}

	close(fd);
	
	return 0;
}





⌨️ 快捷键说明

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