Skip to content

Instantly share code, notes, and snippets.

@suchasplus
Created November 24, 2014 10:54
Show Gist options
  • Save suchasplus/b17e1ee73f28b29e2174 to your computer and use it in GitHub Desktop.
Save suchasplus/b17e1ee73f28b29e2174 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
char c = 'c';
int i;
const char *fifo = "/tmp/testforfifobuf";
fprintf(stdout, "Fifo Creation\n");
mkfifo(fifo, 0777);
struct stat _st;
int ret = stat(fifo, &_st);
if(ret != 0) {
fprintf(stdout, "Fifo Creation Failed, Exit!\n");
return -1;
}
fprintf(stdout, "Theoretical max size: %d\n", PIPE_BUF);
int fifo_fd = open(fifo, O_RDWR | O_NONBLOCK);
fprintf(stdout, "Writing in fifo\n");
for(i=0;; i++)
{
if( write(fifo_fd, &c, 1) == -1)
{
perror("Write");
_exit(1);
}
fprintf(stdout, "%d bytes written\n", i+1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment