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: 59947 Delivered-To: patches@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2280701lbb; Mon, 18 Jan 2016 16:26:40 -0800 (PST) X-Received: by 10.202.177.193 with SMTP id a184mr18788450oif.86.1453163200739; Mon, 18 Jan 2016 16:26:40 -0800 (PST) Return-Path: Received: from mail-oi0-x235.google.com (mail-oi0-x235.google.com. [2607:f8b0:4003:c06::235]) by mx.google.com with ESMTPS id 135si29013055oib.124.2016.01.18.16.26.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jan 2016 16:26:40 -0800 (PST) Received-SPF: pass (google.com: domain of al.stone@linaro.org designates 2607:f8b0:4003:c06::235 as permitted sender) client-ip=2607:f8b0:4003:c06::235; Authentication-Results: mx.google.com; spf=pass (google.com: domain of al.stone@linaro.org designates 2607:f8b0:4003:c06::235 as permitted sender) smtp.mailfrom=al.stone@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-oi0-x235.google.com with SMTP id k206so185286807oia.1 for ; Mon, 18 Jan 2016 16:26:40 -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=OU/PlWvPbtllLOrf3XBQv5UrQANM+zzskiVo1rs3Qm6HP1zUk+Y4mOhXAnxbN/QAfl xkBb6ZNZ9gx1RoiNRncwUefJdc68U6hSaaP0LlkLvvF3pouh7D1Q7Vh8grvEIGRAoxjK mkrpg4e+fR6YIj0iWR51SvtYYuWDPg/gcFWYHyoykLDXzqJqOStwyILDwJ/i7V0WXO2r DQ4ggbUaoNNS4zDeAgHQtoimgkBFeX26Lk8XD7OY3GG5V+vN9jmgLUrsvQyGWfjIg30N HwH9xp8M4bb3gnu4+KBfw3yCyu0F1mu2N7ak3pP4JdJRgJG8N5MHJBomkF2qWtR8jCyD lzPw== X-Gm-Message-State: ALoCoQnFltv7VLYBtrnRLxtTGO6TT513YdNW/wBjxfOLVLQrYtNGfNv2/yzHW5iDBbYgrFvNs7d6rXvaXmCs4QvQLRU4ctT+HA== X-Received: by 10.202.86.204 with SMTP id k195mr20493176oib.89.1453163200429; Mon, 18 Jan 2016 16:26:40 -0800 (PST) Return-Path: 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 Cc: linaro-acpi@lists.linaro.org, patches@linaro.org, Al Stone 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> Add in some helper functions to make it easier to use the enum for fwts_architecture. Signed-off-by: Al Stone --- 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 -- 2.5.0 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; +}