Skip to content

Commit 93159d9

Browse files
committed
Make zchunkopen a bit easier to understand
1 parent 312a1d5 commit 93159d9

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

ext/solv_xfopen.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ static void *zchunkopen(const char *path, const char *mode, int fd)
598598
{
599599
FILE *fp;
600600
void *f;
601-
int tmpfd;
602601
if ((!path && fd < 0) || (path && fd >= 0))
603602
return 0;
604603
if (strcmp(mode, "r") != 0)
@@ -612,17 +611,20 @@ static void *zchunkopen(const char *path, const char *mode, int fd)
612611
f = solv_zchunk_open(fp, 1);
613612
if (!f)
614613
{
615-
/* When 0 is returned, fd passed by user must not be closed! */
616-
/* Dup (save) the original fd to a temporary variable and then back. */
617-
/* It is ugly and thread unsafe hack (non atomical sequence fclose dup2). */
618-
if (!path)
619-
tmpfd = dup(fd);
620-
fclose(fp);
621614
if (!path)
622615
{
616+
/* The fd passed by user must not be closed! */
617+
/* Dup (save) the original fd to a temporary variable and then back. */
618+
/* It is ugly and thread unsafe hack (non atomical sequence fclose dup2). */
619+
int tmpfd = dup(fd);
620+
fclose(fp);
623621
dup2(tmpfd, fd);
624622
close(tmpfd);
625623
}
624+
else
625+
{
626+
fclose(fp);
627+
}
626628
}
627629
return cookieopen(f, mode, (ssize_t (*)(void *, char *, size_t))solv_zchunk_read, 0, (int (*)(void *))solv_zchunk_close);
628630
}

0 commit comments

Comments
 (0)