Skip to content

Instantly share code, notes, and snippets.

@natsutan
Created May 28, 2012 00:37
Show Gist options
  • Save natsutan/2816543 to your computer and use it in GitHub Desktop.
Save natsutan/2816543 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<io.h>
int main(void)
{
int fd0, fd1, fd2;
int fds[2];
int r;
FILE *fp;
int i;
fp = fopen("out.txt", "w");
close(0);
close(1);
close(2);
fd0 = open("NUL", O_RDONLY);
fd1 = open("NUL", O_WRONLY);
fd2 = open("NUL", O_WRONLY);
fprintf(fp, "fd0 = %d, fd1 = %d, fd2 = %d\n", fd0, fd1, fd2);
//create pipe 3 times
for(i = 0;i < 3;i++) {
r = _pipe(fds, 512, 0);
if (r != 0) {
fprintf(fp, "error pipe returns %d\n", r);
} else {
fprintf(fp, "pipe(%d,%d)\n", fds[0], fds[1]);
}
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment