I'm trying to create a named pipe in C, but have not had any success.
Here is my code:
pid_t pid = getpid() ;
char * pipeNameo = malloc( sizeof(char) * 100 ) ;
len = 0 ;
//len += sprintf( pipeNameo + len, "%s", "/Users/Davidb/Desktop/") ; // tried various paths
len += sprintf( pipeNameo + len, "%ld", (long)pid) ;
len += sprintf( pipeNameo + len, "%s", "_") ;
len += sprintf( pipeNameo + len, "%d", i) ; // it is in a loop, i starts at 0 and increments
len += sprintf( pipeNameo + len, "%s", "o") ;
printf("pipeNameo : %s\n", pipeNameo ) ;
val = mkfifo(pipeNameo, 0666) ;
printf("Did named pipe succeed: %d\n", val) ;
So after running this, I check the directory, and there is no file being made. Here is some sample output:
OUTPUT, when loop runs twice
pipeNameo : /Users/Davidb/Desktop/1152_0o
Did named pipe succeed: 0
pipeNameo : /Users/Davidb/Desktop/1152_1o
Did named pipe succeed: 0
Please help :)
UPDATE Ok I see that the ls -l worked for when the path was set to my Desktop! But it doesn't work when I try and set it to the current directory (where the main.c is stored). I tried adding "/." and "/" before the pipe Name, neither worked.