]> git.alsa-project.org Git - alsa-utils.git/commitdiff
axfer: minor code arrangement in a point of opened file descriptor
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 11 Mar 2021 05:21:34 +0000 (14:21 +0900)
committerJaroslav Kysela <perex@perex.cz>
Thu, 11 Mar 2021 08:28:12 +0000 (09:28 +0100)
This commit arranges assignment to fd member after checking file
descriptor.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
axfer/container.c

index fb35eba32df75c3cfb8164d0d5974a9bd7f765d5..b4646b9addc4896961c8b1da075853ebef2823da 100644 (file)
@@ -151,6 +151,7 @@ int container_parser_init(struct container_context *cntr,
                [CONTAINER_FORMAT_AU] = &container_parser_au,
                [CONTAINER_FORMAT_VOC] = &container_parser_voc,
        };
+       int fd;
        const struct container_parser *parser;
        unsigned int size;
        int i;
@@ -168,12 +169,13 @@ int container_parser_init(struct container_context *cntr,
 
        // Open a target descriptor.
        if (!strcmp(path, "-")) {
-               cntr->fd = fileno(stdin);
+               fd = fileno(stdin);
        } else {
-               cntr->fd = open(path, O_RDONLY);
-               if (cntr->fd < 0)
+               fd = open(path, O_RDONLY);
+               if (fd < 0)
                        return -errno;
        }
+       cntr->fd = fd;
 
        cntr->stdio = (cntr->fd == fileno(stdin));
        if (cntr->stdio) {
@@ -239,6 +241,7 @@ int container_builder_init(struct container_context *cntr,
                [CONTAINER_FORMAT_VOC] = &container_builder_voc,
                [CONTAINER_FORMAT_RAW] = &container_builder_raw,
        };
+       int fd;
        const struct container_builder *builder;
        int err;
 
@@ -256,12 +259,13 @@ int container_builder_init(struct container_context *cntr,
        if (path == NULL || *path == '\0')
                return -EINVAL;
        if (!strcmp(path, "-")) {
-               cntr->fd = fileno(stdout);
+               fd = fileno(stdout);
        } else {
-               cntr->fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
-               if (cntr->fd < 0)
+               fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
+               if (fd < 0)
                        return -errno;
        }
+       cntr->fd = fd;
 
        cntr->stdio = (cntr->fd == fileno(stdout));
        if (cntr->stdio) {