]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdwelf: Make dwelf_elf_begin return NULL only when there is an error.
authorMark Wielaard <mark@klomp.org>
Sun, 11 Aug 2019 22:43:22 +0000 (00:43 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 13 Aug 2019 10:16:18 +0000 (12:16 +0200)
commit7ea82243ec3e556518116c51b528c3a4eb6d16f3
tree3b5b4b83db7c1c248cabb934e77166a99c1c0e5b
parentd37f6ea7e3e544e27b6067405a6b5ab0a31a99c8
libdwelf: Make dwelf_elf_begin return NULL only when there is an error.

dwelf_elf_begin was slightly different from elf_begin in case the file
turned out to not be an ELF file. elf_begin would return an Elf handle
with ELF_K_NONE. But dwelf_elf_begin would return NULL. This made it
impossible to tell the difference between a file or decompression error
and a (decompressed) file not being an ELF file.

Since dwelf_elf_begin could still return different kinds of ELF files
(ELF_K_ELF or ELF_K_AR - and theoretically ELF_K_COFF) this was not
really useful anyway. So make it so that dwelf_elf_begin always returns
an Elf handle unless there was a real error reading or decompressing
the file. Otherwise return NULL to make clear there was a real error.

Make sure that the decompression function returns DWFL_E_BADELF only
when the file isn't compressed. In which case the Elf handle won't
be replaced and can be returned (as ELF_K_NONE).

Add a new version to dwelf_elf_begin so programs can rely on it
returning NULL only for real errors.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/libdw.map
libdwelf/ChangeLog
libdwelf/dwelf_elf_begin.c
libdwelf/libdwelf.h
libdwfl/ChangeLog
libdwfl/gzip.c
libdwfl/open.c