Skip to content

Commit

Permalink
Merge pull request #563 from ppisar/solv_xfopen_unsupported_error
Browse files Browse the repository at this point in the history
Report unsupported compression in solv_xfopen() with errno
  • Loading branch information
mlschroe authored May 16, 2024
2 parents 9c2b1a8 + fee6928 commit a898731
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions ext/solv_xfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>

#ifdef _WIN32
#include "fmemopen.c"
Expand Down Expand Up @@ -660,7 +661,10 @@ solv_xfopen(const char *fn, const char *mode)
char *suf;

if (!fn)
return 0;
{
errno = EINVAL;
return 0;
}
if (!mode)
mode = "r";
suf = strrchr(fn, '.');
Expand All @@ -669,7 +673,10 @@ solv_xfopen(const char *fn, const char *mode)
return mygzfopen(fn, mode);
#else
if (suf && !strcmp(suf, ".gz"))
return 0;
{
errno = ENOTSUP;
return 0;
}
#endif
#ifdef ENABLE_LZMA_COMPRESSION
if (suf && !strcmp(suf, ".xz"))
Expand All @@ -678,30 +685,45 @@ solv_xfopen(const char *fn, const char *mode)
return mylzfopen(fn, mode);
#else
if (suf && !strcmp(suf, ".xz"))
return 0;
{
errno = ENOTSUP;
return 0;
}
if (suf && !strcmp(suf, ".lzma"))
return 0;
{
errno = ENOTSUP;
return 0;
}
#endif
#ifdef ENABLE_BZIP2_COMPRESSION
if (suf && !strcmp(suf, ".bz2"))
return mybzfopen(fn, mode);
#else
if (suf && !strcmp(suf, ".bz2"))
return 0;
{
errno = ENOTSUP;
return 0;
}
#endif
#ifdef ENABLE_ZSTD_COMPRESSION
if (suf && !strcmp(suf, ".zst"))
return myzstdfopen(fn, mode);
#else
if (suf && !strcmp(suf, ".zst"))
return 0;
{
errno = ENOTSUP;
return 0;
}
#endif
#ifdef ENABLE_ZCHUNK_COMPRESSION
if (suf && !strcmp(suf, ".zck"))
return myzchunkfopen(fn, mode);
#else
if (suf && !strcmp(suf, ".zck"))
return 0;
{
errno = ENOTSUP;
return 0;
}
#endif
return fopen(fn, mode);
}
Expand Down

0 comments on commit a898731

Please sign in to comment.