summaryrefslogtreecommitdiff
path: root/axfer
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2021-03-11 14:21:32 +0900
committerJaroslav Kysela <perex@perex.cz>2021-03-11 09:28:12 +0100
commitd81a0f93bc1b50d585b38f400949125e5d5e3915 (patch)
treedcc5f7509a1e3fb351bff1bccb2eee6819791c9a /axfer
parenteefc2c61cfda4325373e1fa2d3be1642c92eee83 (diff)
downloadalsa-utils-d81a0f93bc1b50d585b38f400949125e5d5e3915.tar.gz
axfer: minor code arrangement for container module in a point of nonblocking flag
In internal container module, any file descriptor is expected as non-blocking mode. Current implementation distinguish the case of standard input and output from the case to open actual file since O_NONBLOCK is used for the latter case. However, in both cases, fcntl(2) is available to set non-blocking mode to the file descriptor. This commit arranges to use fcntl(2) for both cases. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'axfer')
-rw-r--r--axfer/container.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/axfer/container.c b/axfer/container.c
index 566acd0..8733ff7 100644
--- a/axfer/container.c
+++ b/axfer/container.c
@@ -176,16 +176,17 @@ int container_parser_init(struct container_context *cntr,
"should be referred instead.\n");
return -EIO;
}
- err = set_nonblock_flag(cntr->fd);
- if (err < 0)
- return err;
cntr->stdio = true;
} else {
- cntr->fd = open(path, O_RDONLY | O_NONBLOCK);
+ cntr->fd = open(path, O_RDONLY);
if (cntr->fd < 0)
return -errno;
}
+ err = set_nonblock_flag(cntr->fd);
+ if (err < 0)
+ return err;
+
// 4 bytes are enough to detect supported containers.
err = container_recursive_read(cntr, cntr->magic, sizeof(cntr->magic));
if (err < 0)
@@ -260,17 +261,17 @@ int container_builder_init(struct container_context *cntr,
"should be referred instead.\n");
return -EIO;
}
- err = set_nonblock_flag(cntr->fd);
- if (err < 0)
- return err;
cntr->stdio = true;
} else {
- cntr->fd = open(path, O_RDWR | O_NONBLOCK | O_CREAT | O_TRUNC,
- 0644);
+ cntr->fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
if (cntr->fd < 0)
return -errno;
}
+ err = set_nonblock_flag(cntr->fd);
+ if (err < 0)
+ return err;
+
builder = builders[format];
// Allocate private data for the builder.