#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能成功创建管道文件,但就打开不了。请大家帮帮忙!指点下迷津。 |