Skip to content

Instantly share code, notes, and snippets.

@hirokuma
Created September 11, 2017 08:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hirokuma/56916fe0f4528ad7d563d9dbe9fbbfe6 to your computer and use it in GitHub Desktop.
リダイレクトを分割したいが、うまくいかない
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main(void)
{
const char *FNAME[] = {
"1.txt", "2.txt", "3.txt"
};
for (int lp = 0; lp < 3; lp++) {
int fd = open(FNAME[lp], O_CREAT | O_WRONLY | O_SYNC | O_DSYNC, 0644);
close(1);
int fd2 = dup(fd);
fprintf(stderr, "fd=%d, fd2=%d\n", fd, fd2);
printf("lp=%d, %s\n", lp, FNAME[lp]);
fsync(1);
sync();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment