// Open a target descriptor.
if (!strcmp(path, "-")) {
cntr->fd = fileno(stdin);
+ } else {
+ cntr->fd = open(path, O_RDONLY);
+ if (cntr->fd < 0)
+ return -errno;
+ }
+
+ cntr->stdio = (cntr->fd == fileno(stdin));
+ if (cntr->stdio) {
if (isatty(cntr->fd)) {
fprintf(stderr,
"A terminal is referred for standard input. "
"should be referred instead.\n");
return -EIO;
}
- cntr->stdio = true;
- } else {
- cntr->fd = open(path, O_RDONLY);
- if (cntr->fd < 0)
- return -errno;
}
err = set_nonblock_flag(cntr->fd);
return -EINVAL;
if (!strcmp(path, "-")) {
cntr->fd = fileno(stdout);
+ } else {
+ cntr->fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ if (cntr->fd < 0)
+ return -errno;
+ }
+
+ cntr->stdio = (cntr->fd == fileno(stdout));
+ if (cntr->stdio) {
if (isatty(cntr->fd)) {
fprintf(stderr,
"A terminal is referred for standard output. "
"should be referred instead.\n");
return -EIO;
}
- cntr->stdio = true;
- } else {
- cntr->fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
- if (cntr->fd < 0)
- return -errno;
}
err = set_nonblock_flag(cntr->fd);