Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 791473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:50:32+00:00 2026-05-14T21:50:32+00:00

I am having trouble in creating named pipe in Android and the example below

  • 0

I am having trouble in creating named pipe in Android and the example below illustrates my dilemma:

res = mkfifo("/sdcard/fifo9000", S_IRWXO);
if (res != 0)
{
    LOG("Error while creating a pipe (return:%d, errno:%d)", res, errno);
}

The code always prints:

Error while creating a pipe (return:-1, errno:1)

I can’t figure out exactly why this fails. The application has android.permission.WRITE_EXTERNAL_STORAGE permissions. I can create normal files with exactly the same name in the same location, but pipe creation fails. The pipe in question should be accessible from multiple applications.

  1. I suspect that noone can create pipes in /sdcard. Where would it be the best location to do so?
  2. What mode mast should I set (2nd parameter)?
  3. Does application need any extra permissions?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:50:33+00:00Added an answer on May 14, 2026 at 9:50 pm

    Roosmaa’s answer is correct — mkfifo() just calls mknod() to create a special file, and FAT32 doesn’t support that.

    As an alternative you may want to consider using Linux’s “abstract namespace” UNIX-domain sockets. They should be roughly equivalent to a named pipe. You can access them by name, but they’re not part of the filesystem, so you don’t have to deal with various permission issues. Note the socket is bi-directional.

    Since it’s a socket, you may need INTERNET permission. Not sure about that.

    Here’s a quick bit of client/server sample code:

    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <stddef.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    
    /*
     * Create a UNIX-domain socket address in the Linux "abstract namespace".
     *
     * The socket code doesn't require null termination on the filename, but
     * we do it anyway so string functions work.
     */
    int makeAddr(const char* name, struct sockaddr_un* pAddr, socklen_t* pSockLen)
    {
        int nameLen = strlen(name);
        if (nameLen >= (int) sizeof(pAddr->sun_path) -1)  /* too long? */
            return -1;
        pAddr->sun_path[0] = '\0';  /* abstract namespace */
        strcpy(pAddr->sun_path+1, name);
        pAddr->sun_family = AF_LOCAL;
        *pSockLen = 1 + nameLen + offsetof(struct sockaddr_un, sun_path);
        return 0;
    }
    
    int main(int argc, char** argv)
    {
        static const char* message = "hello, world!";
        struct sockaddr_un sockAddr;
        socklen_t sockLen;
        int result = 1;
    
        if (argc != 2 || (argv[1][0] != 'c' && argv[1][0] != 's')) {
            printf("Usage: {c|s}\n");
            return 2;
        }
    
        if (makeAddr("com.whoever.xfer", &sockAddr, &sockLen) < 0)
            return 1;
        int fd = socket(AF_LOCAL, SOCK_STREAM, PF_UNIX);
        if (fd < 0) {
            perror("client socket()");
            return 1;
        }
    
        if (argv[1][0] == 'c') {
            printf("CLIENT %s\n", sockAddr.sun_path+1);
    
            if (connect(fd, (const struct sockaddr*) &sockAddr, sockLen) < 0) {
                perror("client connect()");
                goto bail;
            }
            if (write(fd, message, strlen(message)+1) < 0) {
                perror("client write()");
                goto bail;
            }
        } else if (argv[1][0] == 's') {
            printf("SERVER %s\n", sockAddr.sun_path+1);
            if (bind(fd, (const struct sockaddr*) &sockAddr, sockLen) < 0) {
                perror("server bind()");
                goto bail;
            }
            if (listen(fd, 5) < 0) {
                perror("server listen()");
                goto bail;
            }
            int clientSock = accept(fd, NULL, NULL);
            if (clientSock < 0) {
                perror("server accept");
                goto bail;
            }
            char buf[64];
            int count = read(clientSock, buf, sizeof(buf));
            close(clientSock);
            if (count < 0) {
                perror("server read");
                goto bail;
            }
            printf("GOT: '%s'\n", buf);
        }
        result = 0;
    
    bail:
        close(fd);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 457k
  • Answers 457k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer An executable JAR should work fine for a launcher on… May 15, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer I recently came across a rather elegant new solution for… May 15, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer You can reload the file with the appropriate encoding: :e… May 15, 2026 at 10:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.