]> git.alsa-project.org Git - alsa-utils.git/commitdiff
axfer: minor code arrangement in a point of stdio detection
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 11 Mar 2021 05:21:33 +0000 (14:21 +0900)
committerJaroslav Kysela <perex@perex.cz>
Thu, 11 Mar 2021 08:28:12 +0000 (09:28 +0100)
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>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
axfer/container.c

index 8733ff76439d356412c99893b4ddeaa92455b3b0..fb35eba32df75c3cfb8164d0d5974a9bd7f765d5 100644 (file)
@@ -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);