天嵌 ARM开发社区

 找回密码
 注册
查看: 1802|回复: 2

关于mkfifo的问题?创建之后移植打开不了?

[复制链接]
wind 发表于 2010-8-8 23:06:01 | 显示全部楼层 |阅读模式
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#define FIFO_SERVER "/tmp/stepmoto_fifo"
#define msleep(n) usleep(1000*n)
main(int argc,char** argv)

{

        int fdf=0;
        char w_buf1[100];
        char w_buf2[100];
        int i;
        int nwrite;       
//        unlink(FIFO_SERVER); //删除文件
        if((mkfifo(FIFO_SERVER,O_CREAT|O_EXCL)<0)&&(errno!=EEXIST))
                printf("cannot create fifoserver\n");

        /*打开管道*/
        fdf=open(FIFO_SERVER,O_WRONLY|O_NONBLOCK,0);//只写,非阻塞
        printf("fdf=%d\n",fdf);
       
        if(argc==1)
        {
                printf("Please send something\n");
                exit(-1);
        }
       
        //打印参数
        printf("argv[1]=%s\n",argv[1]);
        strcpy(w_buf1, argv[1]);
        printf("write %s to the FIFO\n",w_buf1);       
        nwrite=write(fdf,w_buf1,100);
        printf("nwrite=%d\n",nwrite);
               
        printf("argv[2]=%s\n",argv[2]);               
        strcpy(w_buf2, argv[2]);
        printf("write %s to the FIFO\n",w_buf2);
       
        unlink(FIFO_SERVER); //删除文件
}       
不知为何移植打开不了    FIFO_SERVER 这个管道文件,open的参数一直是-1,错在哪里呢?请教一下。mkfifo能成功创建管道文件,但就打开不了。请大家帮帮忙!指点下迷津。
 楼主| wind 发表于 2010-8-8 23:08:17 | 显示全部楼层
open的返回值fdf一直是-1
 楼主| wind 发表于 2010-8-8 23:09:53 | 显示全部楼层
搞了一天,试了好几种方法,总是出错.哪位大虾指点下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-27 21:02 , Processed in 1.028360 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表