wfifo.c

来自「ARM Linux2.4 进程间通信 非常好」· C语言 代码 · 共 50 行

C
50
字号
/*********************************************************************
* File:		wfifo.c
* Author:	Embest	J.Zhao	2005.2.17
* Desc:		write FIFO,with read program rfifo.c
* History:
*********************************************************************/

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <asm/limits.h>

int main(void)
{
	int nFd;						/* FIFO */
	int nLen;						/* FIFO read bytes len */
	char szBuf[PIPE_BUF];			/* FIFO buf */
	
	mode_t mode = 666;			/* FIFO  */
	
	/* creat FIFO */
	if ((nFd = mkfifo("/var/ff", mode)) < 0)
	{
		printf("creat fifo error\n");
		exit(-1);
	}
	
/* open FIFO write port */
	if ((nFd = open("/var/ff", O_WRONLY)) < 0)
	{
		printf("open the fifo write error\n");
		exit(-1);
	}
	
	/* 写fifo */
	nLen = sprintf(szBuf, "wfifo send the message");
	if (write(nFd, szBuf, nLen + 1) < 0)
	{
		printf("open the fifo write error\n");
		close(nFd);
		exit(-1);
	}
	close(nFd);
	
	return 0;
}

⌨️ 快捷键说明

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