Implemented a program in c for fifo..pls help

Euphoria
@euphoria-dEbOBg โ€ข Oct 27, 2024

I have implemented below program in c.
While debugging its giving error on Open, Read commands as "identifier "open" not defined" and
Error 5 error LNK2019: unresolved external symbol _mkfifo referenced in function _main
Error 6 error LNK1120: 1 unresolved externals
Please help asap.. ๐Ÿ˜”

#include<errno.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include<Windows.h>
#define FIFO "/root/test/test"

int    mkfifo( char *,int mode_t);

int main(int argc, char** argv)
{
    char buf_r[100];
    int fd;
    int nread;
    if((mkfifo(FIFO, O_CREAT) < 0) && (errno != EEXIST))
    {
            printf("can not create FIFO\n");
            exit(1);
    }

    printf("Prepare read data\n");
    fd = Open(FIFO, O_RDONLY);
    if(fd == -1)
    {
            exit(1);
    }

    while(1)
    {
            if((nread = Read(fd, buf_r, 100)) == -1)
            {
                    if(errno == EAGAIN) printf("No data\n");
            }

            if(buf_r[0]=='Q') break;

            buf_r[nread]=0;
            printf("data is๏ผš%s\n", buf_r);
            Sleep(1);
    }

} 

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Vishal Sharma

    @vishal-pysGmK • Jun 27, 2015

    I think this program is supposed to be executed in unix box not on windows. I strongly feel that you are using windows (Just saw the headers, haven't gone through the program yet)

    Update
    Yup, it should be executed in unix box. I'll let you try this code in linux and get back with the results