CrazyEngineers
  • Implemented a program in c for fifo..pls help

    Euphoria

    Euphoria

    @euphoria-dEbOBg
    Updated: Oct 27, 2024
    Views: 1.3K
    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);
        }
    
    } 
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Vishal Sharma

    MemberJun 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
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register