在日食中使用管道

Using pipe in Eclipse

本文关键字:管道      更新时间:2023-10-16

我正在尝试在eclipse中编译我的代码

,但它不会编译我的管道使用。

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <signal.h>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <sys/wait.h>

using namespace std;
int OpenPipeRead(string sinterface)
{
int ret_val,errno;
string lpipename="",lpipepath="";
lpipepath = mconfig[C_PIPEPATH];
lpipename.append(lpipepath);                    //Its not empty only when there is argument for parallal telepath_sniff instances.
lpipename.append(mconfig[C_PIPENAME]);
if(strcmp(sinterface.c_str(), "") != 0)
    lpipename.append("_" + sinterface);             
printf("Trying to open Pipe for readingn");
syslog(LOG_INFO, "Try to open Pipe for readingn"); 
/* Create the named - pipe */
ret_val = mkfifo(lpipename.c_str(), 0666);
if ((ret_val == -1) && (errno != EEXIST)) {
    perror("Error creating the named pipe");
    syslog(LOG_ERR, "Error creating the named pipe");           
    exit(1);
}       
if((pipehandler = open(lpipename.c_str(), O_RDWR)) < 1)     /* Open the pipe for reading and writing , in append mode */
{
    perror("Failed to open pipe file");
    syslog(LOG_ERR, "Failed to open pipe file");
    exit(1);
}
printf("Pipe opened.n");
syslog(LOG_INFO, "Pipe opened.n");

}

int main(){
    OpenPipeRead("arg");
}

错误是:

../src/main.cpp:325:错误:在此范围中未声明" eexist"../src/main.cpp:330:错误:在此范围中未声明'o_rdwr'../src/main.cpp:330:错误:在此范围中未声明"打开"

它确实在Eclipse之外编译

我需要与Eclipse一起编译的任何包含或标志?

谢谢

eexist宏是在asm-generic/errno-base.h中定义的,而o_rdwr flag在fcntl.h。

中定义

add:

#include <asm-generic/errno-base.h>
#include <fcntl.h>

到包含OpenPipEread定义的文件,并应编译。