开管警告

时间:2014-09-05 02:46:04

标签: 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 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;
}

顺便说一句,我在.profile中添加了以下行:

export fifo0 = / home / bayat / fifo0

export fifo1 = / home / bayat / fifo1

请帮我解决。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我希望如果你看起来(可能在fifo.h中),当你的程序清楚地期望它们是{{1}时,你会发现fifo0fifo1被定义为int }或char *。可能你需要的是这样的东西:

char[]

我不认为你的.profile文件在这里有任何影响。