diff options
author | Timm Bäder <tbaeder@redhat.com> | 2021-01-08 09:13:26 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-01-29 21:34:53 +0100 |
commit | 04e19e8a449beefad8a451bdd9a55afa8ab61456 (patch) | |
tree | 15dd0a4435b855422d7b71892891af99b43bb90e | |
parent | f91424e7a59e1fed5e46a7a32f5074411626731d (diff) | |
download | elfutils-04e19e8a449beefad8a451bdd9a55afa8ab61456.tar.gz |
zstrptr: Pull print_string() into file scope
Get rid of a nested function this way.
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
-rw-r--r-- | tests/ChangeLog | 6 | ||||
-rw-r--r-- | tests/zstrptr.c | 43 |
2 files changed, 28 insertions, 21 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 4688b50a..3e5b630a 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2021-01-06 Timm Bäder <tbaeder@redhat.com> + + * zstrptr.c (main): Lift print_strings function up to ... + (print_strings): ... here. New file scope function taking + Elf_Scn*, Elf* and ndx as arguments. + 2020-12-20 Dmitry V. Levin <ldv@altlinux.org> * .gitignore: New file. diff --git a/tests/zstrptr.c b/tests/zstrptr.c index 6d8e19f7..9fb42e28 100644 --- a/tests/zstrptr.c +++ b/tests/zstrptr.c @@ -30,6 +30,26 @@ #include ELFUTILS_HEADER(elf) #include <gelf.h> +static void +print_strings (Elf_Scn *scn, Elf *elf, size_t ndx) +{ + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + + printf ("Strings in section %zd (%s):\n", ndx, + ((shdr->sh_flags & SHF_COMPRESSED) != 0 + ? "compressed" : "uncompressed")); + + size_t off = 0; + const char *str = elf_strptr (elf, ndx, off); + while (str != NULL) + { + printf ("[%zx] '%s'\n", off, str); + off += strlen (str) + 1; + str = elf_strptr (elf, ndx, off); + } +} + int main (int argc, char *argv[]) { @@ -79,38 +99,19 @@ main (int argc, char *argv[]) exit (1); } - void print_strings (void) - { - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); - - printf ("Strings in section %zd (%s):\n", ndx, - ((shdr->sh_flags & SHF_COMPRESSED) != 0 - ? "compressed" : "uncompressed")); - - size_t off = 0; - const char *str = elf_strptr (elf, ndx, off); - while (str != NULL) - { - printf ("[%zx] '%s'\n", off, str); - off += strlen (str) + 1; - str = elf_strptr (elf, ndx, off); - } - } - if (elf_compress (scn, ELFCOMPRESS_ZLIB, 0) < 0) { printf ("Couldn't compress section %zd: %s\n", ndx, elf_errmsg (-1)); exit (1); } - print_strings (); + print_strings (scn, elf, ndx); if (elf_compress (scn, 0, 0) < 0) { printf ("Couldn't decompress section %zd: %s\n", ndx, elf_errmsg (-1)); exit (1); } - print_strings (); + print_strings (scn, elf, ndx); if (elf_end (elf) != 0) { |