Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis

bnoordhuis/dup.c Secret

Created October 2, 2012 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/0030933d015d1e77ae04 to your computer and use it in GitHub Desktop.
Save bnoordhuis/0030933d015d1e77ae04 to your computer and use it in GitHub Desktop.
dup() is per filedes, not per fd
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(void)
{
int fd = dup(0);
printf("O_NONBLOCK=%d\n", O_NONBLOCK & fcntl(0, F_GETFL));
fcntl(fd, F_SETFL, O_NONBLOCK | fcntl(fd, F_GETFL));
printf("O_NONBLOCK=%d\n", O_NONBLOCK & fcntl(0, F_GETFL));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment