From patchwork Tue Jan 19 00:26:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Stone X-Patchwork-Id: 569713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 91BB21402C0; Tue, 19 Jan 2016 11:26:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=ckqW3jrv; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1aLK8F-00022s-0d; Tue, 19 Jan 2016 00:26:47 +0000 Received: from mail-oi0-f52.google.com ([209.85.218.52]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.76) (envelope-from ) id 1aLK89-00021D-GZ for fwts-devel@lists.ubuntu.com; Tue, 19 Jan 2016 00:26:41 +0000 Received: by mail-oi0-f52.google.com with SMTP id p187so166091453oia.2 for ; Mon, 18 Jan 2016 16:26:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n/Y1vsusmaQ7lsYCVzZZnGcPyOpJn9vIzGcdlu61+Jg=; b=ckqW3jrvxoZK49CSK4fAOZdCUJPjQVWqso3qy4L9GaLNSB532oNu5qTKR3RvDJg/wX Pra++2L9S9KeelGONlZwOxRsSBjrTJvpef/uzNV7ti4mbI9RnPza/aNIKgEDc+oIaBGd b+GOIXu7rpU98Ns+PqBqlug4jAuvIgABwg+UQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n/Y1vsusmaQ7lsYCVzZZnGcPyOpJn9vIzGcdlu61+Jg=; b=P3tiJ0zpOdT/FmNxVgKbq5llIQkSW4tkWfTsUCthdTpx11NnpN/YoXk2KBsVv2xMM9 5HWom/AB9DYxoM359s5FGsDFFVG/dV+CT0BBvggdfeRalN4vQZQAAcSMQdMZCwUNRsDe eKGi6vi5sO1eZzFaAqX2VXvyfTrfM+tN/d+3Rh4Z4lK0pFpIaSk9ZW5MZCLnY/unUvDA CM3aVUO21+cOtSG9HV7Lax+HwJul+yM5inl7r5nv4XZkfuelyt7klhXT797RhuIHBWUv NKasVjYusJR97Zf2S5vE27cD0xIGwMrg950cBABiBn8ufEKKQaUHQVjz4UPS284Ms0RB iBzw== X-Gm-Message-State: ALoCoQkdoyUQNR/nGVDGpnCPjpNHY83Jt9OMJ9JG/ygqL+qJ9yKcSBxh66rrAD2YRKYuE/hIliVa3HR0jS0iog4AmvrP34wf/w== X-Received: by 10.202.86.204 with SMTP id k195mr20493176oib.89.1453163200429; Mon, 18 Jan 2016 16:26:40 -0800 (PST) Received: from fidelio.ahs3 (c-50-134-239-249.hsd1.co.comcast.net. [50.134.239.249]) by smtp.googlemail.com with ESMTPSA id y9sm14289969obg.4.2016.01.18.16.26.38 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jan 2016 16:26:39 -0800 (PST) From: Al Stone To: fwts-devel@lists.ubuntu.com Subject: [PATCH v3 2/6] Define some utility functions for using the fwts_architecture enum Date: Mon, 18 Jan 2016 17:26:11 -0700 Message-Id: <1453163175-5801-3-git-send-email-al.stone@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453163175-5801-1-git-send-email-al.stone@linaro.org> References: <1453163175-5801-1-git-send-email-al.stone@linaro.org> Cc: patches@linaro.org, linaro-acpi@lists.linaro.org X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com Add in some helper functions to make it easier to use the enum for fwts_architecture. Signed-off-by: Al Stone Acked-by: Alex Hung --- src/lib/include/fwts_arch.h | 4 +++ src/lib/src/Makefile.am | 1 + src/lib/src/fwts_arch.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/lib/src/fwts_arch.c diff --git a/src/lib/include/fwts_arch.h b/src/lib/include/fwts_arch.h index 3fc03fc..a950ea7 100644 --- a/src/lib/include/fwts_arch.h +++ b/src/lib/include/fwts_arch.h @@ -34,4 +34,8 @@ typedef enum { FWTS_ARCH_OTHER } fwts_architecture; +extern fwts_architecture fwts_arch_get_host(void); +extern fwts_architecture fwts_arch_get_arch(const char *name); +extern const char *fwts_arch_names(void); + #endif diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am index c16f129..5d63804 100644 --- a/src/lib/src/Makefile.am +++ b/src/lib/src/Makefile.am @@ -28,6 +28,7 @@ libfwts_la_SOURCES = \ fwts_acpi.c \ fwts_acpid.c \ fwts_alloc.c \ + fwts_arch.c \ fwts_args.c \ fwts_backtrace.c \ fwts_battery.c \ diff --git a/src/lib/src/fwts_arch.c b/src/lib/src/fwts_arch.c new file mode 100644 index 0000000..558458c --- /dev/null +++ b/src/lib/src/fwts_arch.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016, Al Stone + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include + +#include "fwts.h" + +struct fwts_arch_info { + fwts_architecture arch; + char *name; +}; + +static const struct fwts_arch_info arch_info[] = { + { FWTS_ARCH_X86, "x86" }, + { FWTS_ARCH_X86, "x86_32" }, + { FWTS_ARCH_X86, "x86_64" }, + { FWTS_ARCH_IA64, "ia64" }, + { FWTS_ARCH_ARM64, "arm64" }, + { FWTS_ARCH_ARM64, "aarch64" }, + { FWTS_ARCH_OTHER, "other" } +}; + +static char *arch_names; + +static fwts_architecture __fwts_arch_get_arch(const char *name) +{ + const struct fwts_arch_info *ptr; + + for (ptr = arch_info; ptr->arch != FWTS_ARCH_OTHER; ptr++) + if (!strcmp(ptr->name, name)) + return ptr->arch; + + return FWTS_ARCH_OTHER; +} + +fwts_architecture fwts_arch_get_host(void) +{ + struct utsname buf; + + if (uname(&buf)) + return FWTS_ARCH_OTHER; + + return __fwts_arch_get_arch(buf.machine); +} + +fwts_architecture fwts_arch_get_arch(const char *name) +{ + return __fwts_arch_get_arch(name); +} + +const char *fwts_arch_names(void) +{ + const struct fwts_arch_info *ptr; + size_t len; + + if (arch_names) + return arch_names; + + for (ptr = arch_info, len = 0; ptr->arch != FWTS_ARCH_OTHER; ptr++) + len += strlen(ptr->name) + 1; + + arch_names = calloc(len, 1); + if (arch_names) { + for (ptr = arch_info; ptr->arch != FWTS_ARCH_OTHER; ptr++) { + strcat(arch_names, ptr->name); + strcat(arch_names, " "); + } + } + + return arch_names; +}