---
src/filearch.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/filearch.c b/src/filearch.c
index df65c98..2016115 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -59,8 +59,9 @@ cleanup_magic_t_free (void *ptr)
# endif
COMPILE_REGEXP (re_file_elf,
- "ELF.*(?:executable|shared object|relocatable), (.+?),", 0)
-COMPILE_REGEXP (re_elf_ppc64, "64.*PowerPC", 0)
+ "ELF.*(MSB|LSB).*(?:executable|shared object|relocatable),
(.+?),", 0)
+COMPILE_REGEXP (re_elf_ppc64, "MSB.*64.*PowerPC", 0)
+COMPILE_REGEXP (re_elf_ppc64le, "LSB.*64.*PowerPC", 0)
/* Convert output from 'file' command on ELF files to the canonical
* architecture string. Caller must free the result.
@@ -87,6 +88,8 @@ canonical_elf_arch (guestfs_h *g, const char *elf_arch)
r = "ia64";
else if (match (g, elf_arch, re_elf_ppc64))
r = "ppc64";
+ else if (match (g, elf_arch, re_elf_ppc64le))
+ r = "ppc64le";
else if (strstr (elf_arch, "PowerPC"))
r = "ppc";
else if (strstr (elf_arch, "ARM aarch64"))
@@ -315,6 +318,7 @@ guestfs_impl_file_architecture (guestfs_h *g, const char *path)
{
CLEANUP_FREE char *file = NULL;
CLEANUP_FREE char *elf_arch = NULL;
+ CLEANUP_FREE char *endianness = NULL;
char *ret = NULL;
/* Get the output of the "file" command. Note that because this
@@ -324,8 +328,12 @@ guestfs_impl_file_architecture (guestfs_h *g, const char *path)
if (file == NULL)
return NULL;
- if ((elf_arch = match1 (g, file, re_file_elf)) != NULL)
- ret = canonical_elf_arch (g, elf_arch);
+ if ((match2 (g, file, re_file_elf, &endianness, &elf_arch)) != 0) {
+ size_t sz = strlen(elf_arch) + strlen(endianness) + 2;
+ CLEANUP_FREE char *end_elf_arch = safe_malloc(g, sz);
+ snprintf(end_elf_arch, sz, "%s %s", endianness, elf_arch);
+ ret = canonical_elf_arch (g, end_elf_arch);
+ }
else if (strstr (file, "PE32 executable"))
ret = safe_strdup (g, "i386");
else if (strstr (file, "PE32+ executable"))
--
1.9.3