summaryrefslogtreecommitdiff
path: root/kexec/phys_arch.c
diff options
context:
space:
mode:
authorJamey Sharp <jamey@thetovacompany.com>2008-05-15 22:42:10 -0700
committerSimon Horman <horms@verge.net.au>2008-05-21 16:29:56 +1000
commit7c3109cb6c5e1834bb3b6f788c9dcaa0ddbdf090 (patch)
treeafe65be035cbb3bc3377b5b9113d3d91e6e49b41 /kexec/phys_arch.c
parent01cc79edacf626472e3d505b60ac86f7150efa84 (diff)
Factor uname-based native architecture detection into a common function.
This code was copy-pasted into every architecture and was basically identical. Besides producing a nice net reduction in code, this factors a portability challenge into a single function that can be easily replaced at build-time. Signed-off-by: Jamey Sharp <jamey@thetovacompany.com> Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'kexec/phys_arch.c')
-rw-r--r--kexec/phys_arch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/kexec/phys_arch.c b/kexec/phys_arch.c
new file mode 100644
index 0000000..ff8c28b
--- /dev/null
+++ b/kexec/phys_arch.c
@@ -0,0 +1,23 @@
+#include "kexec.h"
+#include <errno.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+long physical_arch(void)
+{
+ struct utsname utsname;
+ int i, result = uname(&utsname);
+ if (result < 0) {
+ fprintf(stderr, "uname failed: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ for (i = 0; arches[i].machine; ++i)
+ if (strcmp(utsname.machine, arches[i].machine) == 0)
+ return arches[i].arch;
+
+ fprintf(stderr, "Unsupported machine type: %s\n",
+ utsname.machine);
+ return -1;
+}