axfer: minor code arrangement in a point of opened file descriptor

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>
This commit is contained in:
Takashi Sakamoto 2021-03-11 14:21:34 +09:00 committed by Jaroslav Kysela
parent 81c93f6460
commit 85ab708f50

View file

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