foggia2004

fifo write

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#define MYFIFO    "/tmp/myfifo"

int main(int argc, char *argv[])
{
    int fd;
    char buf_w[50];

    fd=open(MYFIFO,O_WRONLY|O_NONBLOCK,0);
    if(fd==-1)
    {
        printf("Open the FIFO is fail!\n");
        if(errno==ENXIO)
            printf("There is no Read FIFO!\n");
        exit(0);
    }
    memset(buf_w,0,sizeof(buf_w));
    strcpy(buf_w,argv[1]);
    if(write(fd,buf_w,50)<0)
    {
        printf("Write data to FIFO fail!\n");
    }
    else
    {
        printf("Write data are: %s\n",buf_w);
    }
    
    return 0;
}

 

posted on 2016-05-20 14:54  foggia2004  阅读(146)  评论(0)    收藏  举报

导航