diff mbox series

[alsa-utils,02/14] axfer: minor code arrangement in a point of stdio detection

Message ID 20210311052146.404003-3-o-takashi@sakamocchi.jp
State New
Headers show
Series axfer: reduce test time | expand

Commit Message

Takashi Sakamoto March 11, 2021, 5:21 a.m. UTC
Current implementation sets stdio member in a condition branch, however
it's convenient to set it always regardless of any condition.

This commit arranges assignment to the member.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 axfer/container.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/axfer/container.c b/axfer/container.c
index 8733ff7..fb35eba 100644
--- a/axfer/container.c
+++ b/axfer/container.c
@@ -169,6 +169,14 @@  int container_parser_init(struct container_context *cntr,
 	// 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. "
@@ -176,11 +184,6 @@  int container_parser_init(struct container_context *cntr,
 				"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);
@@ -254,6 +257,14 @@  int container_builder_init(struct container_context *cntr,
 		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. "
@@ -261,11 +272,6 @@  int container_builder_init(struct container_context *cntr,
 				"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);