Created
September 11, 2017 08:15
Star
You must be signed in to star a gist
リダイレクトを分割したいが、うまくいかない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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