Created
September 11, 2017 08:22
-
-
Save hirokuma/23d9d9b23818a70dcfb7d7e5dcdef26a to your computer and use it in GitHub Desktop.
stderrならうまくいく
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, 0644); | |
close(2); | |
int fd2 = dup(fd); | |
fprintf(stdout, "fd=%d, fd2=%d\n", fd, fd2); | |
fprintf(stderr, "lp=%d, %s\n", lp, FNAME[lp]); | |
close(fd); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment