C 开放式管道警告
在ubuntu 12.04 LTS(64位)上编译makefile时遇到以下错误:C 开放式管道警告,c,makefile,pipe,fifo,C,Makefile,Pipe,Fifo,在ubuntu 12.04 LTS(64位)上编译makefile时遇到以下错误: fifo.c: In function ‘OpenPipe’: fifo.c:28:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat] fifo.c:31:16: warning: cast to pointer from integer of different s
fifo.c: In function ‘OpenPipe’:
fifo.c:28:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
fifo.c:31:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:33:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:35:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:43:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:45:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c: In function ‘ClosePipe’:
fifo.c:132:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
以下是fifo.c:
#include "fifo.h"
#include "out_pipe.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "stdio.h"
#include <string.h>
#include "typedefs.h"
#include <sys/time.h>
#include <unistd.h>
#include "gps_sc_def.h" /* must be first */
#include "clnt_buf_def.h"
#include "s_filter.h"
//create and open pipe. If pipe exists or can not open, return -1, else 0
extern char PIPE;
extern eve_buf1 evebuf1;
extern eve_buf2 evebuf2;
extern eve_buf3 evebuf3;
short int PIPE_COUNTER=0, PIPE_PRESC_FACTOR=1;
int OpenPipe()
{
char text[64], text1[64];
**28: fprintf(stderr, "Start open Pipe: %s \n",fifo1);**
sprintf(text,"Can't create fifo ");
**31 : strcat(text, (char *)fifo0);**
sprintf(text1,"Can't create fifo ");
**33: strcat(text1, (char *)fifo1);**
**35: if((mknod((char *)fifo1, S_IFIFO | PERMS,0) < 0)&&(errno != EEXIST))**
{
perror(text1);
return -1;
}
sprintf(text1,"Can't open write fifo ");
**43 :strcat(text1,(char *) fifo1);**
**45 :if((Write = open((char *)fifo1, O_WRONLY)) == -1)**
{
perror(text1);
return -1;
}
fprintf(stderr, "Pipe opened\n");
return 0;
}
//write to pipe. if everything is OK return 0, else -1
long write2pipe(void)
{
ssize_t size2wr=0, sizeofeve=sizeof(evebuf1.nev)+sizeof(evebuf1.sec)+
sizeof(evebuf1.nsec)+sizeof(evebuf1.ireg)+sizeof(evebuf1.nsca)+
sizeof(evebuf1.nadc)+sizeof(evebuf1.ntdc)+sizeof(evebuf1.npcs);
short i,j, *p2short;
long buf[512], *p2long;
// if ((PIPE_COUNTER % PIPE_PRESC_FACTOR) != 0) return 0;
memcpy(buf,&evebuf1.nev, sizeofeve);
size2wr += sizeofeve;
/* fprintf(stderr,"sizeofeve %d\n", sizeofeve);
fprintf(stderr,"nsca %d\n", evebuf1.nsca);
fprintf(stderr,"nadc %d\n", evebuf1.nadc);
fprintf(stderr,"ntdc %d\n", evebuf1.ntdc);
fprintf(stderr,"npcs %d\n", evebuf1.npcs);
fprintf(stderr,"n_event %d\n", evebuf2.n_event); */
p2long = buf+sizeofeve/4;
p2short =(short*)(buf)+sizeofeve/2;
if(evebuf1.nsca != 0)
{
for(i=0;i<evebuf1.nsca;i++)
{
p2long[i] = evebuf3.sca[i];
//if(i<3)fprintf(stderr,"sca \t\t %d %x\n", i, evebuf3.sca[i]);
}
size2wr += 4*evebuf1.nsca;
if(write(Write,&buf, size2wr) != size2wr)
perror("wrong size\n");
return 0;
}
else
{
for(i=0;i<evebuf1.nadc;i++)
{
p2short[i] = evebuf3.adc[i];
//fprintf(stderr,"adc \t\t %x\n", evebuf3.adc[i]);
}
size2wr += 2*evebuf1.nadc;
p2short += evebuf1.nadc;
for(i=0;i<evebuf1.ntdc;i++)
{
p2short[i] = evebuf3.tdc[i];
//fprintf(stderr,"tdc \t\t %x\n", evebuf3.tdc[i]);
}
size2wr += 2*evebuf1.ntdc;
p2short += evebuf1.ntdc;
for(i=0;i<evebuf1.npcs;i++)
{
p2short[i] = evebuf3.pcos[i];
//fprintf(stderr,"\t\t %x\n", evebuf3.pcos[i]);
}
size2wr += 2*evebuf1.npcs;
if(size2wr)
if(write(Write,&buf, size2wr) != size2wr)
perror("wrong size\n");
return 0;
}
}
//close and delete pipe. 0 --- OK, -1 crash
int ClosePipe(){
close(Write);
fclose(Read);
if(unlink((char *)fifo1)<0){
perror("Can't unlink fifo");
return -1;
}
return 0;
}
#包括“fifo.h”
#包括“out_pipe.h”
#包括
#包括
#包括
#包括“stdio.h”
#包括
#包括“typedefs.h”
#包括
#包括
#包括“gps_sc_def.h”/*必须在第一位*/
#包括“clnt_buf_def.h”
#包括“s_filter.h”
//创建并打开管道。如果管道存在或无法打开,则返回-1,否则返回0
外焦管;
外部伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙;
外部伊芙•伊芙•伊芙•伊芙•伊芙•伊芙•伊芙;
外部伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙·伊芙;
短整数管道计数器=0,管道压力系数=1;
int OpenPipe()
{
字符文本[64],文本1[64];
**28:fprintf(标准,“启动开放管道:%s\n”,fifo1)**
sprintf(文本,“无法创建fifo”);
**31:strcat(文本,(字符*)fifo0)**
sprintf(text1,“无法创建fifo”);
**33:strcat(text1,(char*)fifo1)**
**35:if((mknod((char*)fifo1,S|IFIFO | PERMS,0)<0)和&(errno!=EEXIST))**
{
佩罗尔(text1);
返回-1;
}
sprintf(text1,“无法打开写入fifo”);
**43:strcat(text1,(char*)fifo1)**
**45:if((写入=打开((字符*)fifo1,O_WRONLY))=-1)**
{
佩罗尔(text1);
返回-1;
}
fprintf(标准“管道打开”);
返回0;
}
//写信给管道。如果一切正常,则返回0,否则返回-1
长写管道(空)
{
ssize_t size2wr=0,sizeofevebuf1.nev=sizeof+sizeof(evebuf1.sec)+
sizeof(evebuf1.nsec)+sizeof(evebuf1.ireg)+sizeof(evebuf1.nsca)+
sizeof(evebuf1.nadc)+sizeof(evebuf1.ntdc)+sizeof(evebuf1.npcs);
短i,j,*p2短;
长buf[512],*p2long;
//如果((管道计数器%管道压力系数)!=0)返回0;
memcpy(buf和evebuf1.nev、sizeofeve);
size2wr+=SizeOffe;
/*fprintf(标准,“sizeofeve%d\n”,sizeofeve);
fprintf(标准,“nsca%d\n”,evebuf1.nsca);
fprintf(标准,“nadc%d\n”,evebuf1.nadc);
fprintf(stderr,“ntdc%d\n”,evebuf1.ntdc);
fprintf(stderr,“npcs%d\n”,evebuf1.npcs);
fprintf(标准,“n_事件%d\n”,evebuf2.n_事件)*/
p2long=buf+sizeofeve/4;
p2short=(short*)(buf)+sizeofeve/2;
如果(evebuf1.nsca!=0)
{
对于(i=0;i我希望如果您查看(可能在fifo.h中),您会发现fifo0
和fifo1
被定义为int
,而您的程序显然希望它们是char*
或char[]
。您可能需要的是这样的东西:
char fifo0[] = "/home/bayat/fifo0";
char fifo1[] = "/home/bayat/fifo1";
我认为你的.Profile文件在这里没有任何影响。
第一个警告是很清楚的。改变标签,这里有一个零排C++代码。FIFO1是一个全局变量。你不能访问C程序中的环境变量。你需要把它们定义为C变量,如果需要,使用<代码> GETEN()<代码>加上代码> StrucPy。()
或其他复制函数,在运行时从环境变量初始化C变量。