From patchwork Sat Nov 5 21:27:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emmanuel Vadot X-Patchwork-Id: 691604 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3tBBcl4xJ2z9t0X for ; Sun, 6 Nov 2016 08:27:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bidouilliste.com header.i=@bidouilliste.com header.b="eO1u0vw9"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 161544BA29; Sat, 5 Nov 2016 22:27:34 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xn5MyJpdV_kb; Sat, 5 Nov 2016 22:27:33 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 83D354B98B; Sat, 5 Nov 2016 22:27:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7462A4B98B for ; Sat, 5 Nov 2016 22:27:31 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tcdnv5fL1qd1 for ; Sat, 5 Nov 2016 22:27:31 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.blih.net (mail.blih.net [212.83.177.182]) by theia.denx.de (Postfix) with ESMTPS id 1CF484B77D for ; Sat, 5 Nov 2016 22:27:26 +0100 (CET) Received: from mail.blih.net (mail.blih.net [212.83.177.182]) by mail.blih.net (OpenSMTPD) with ESMTP id 628ee309 for ; Sat, 5 Nov 2016 22:27:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bidouilliste.com; h=from :to:cc:subject:date:message-id; s=mail; bh=b2ywt1UUAIKOMo8gPo6aN X9twYU=; b=eO1u0vw9I1z4hCsmCEzwZo59AMriBSeg92sby1+U+T2jPWeXvGydD 9t0gHz8nwx8+xuoj0dvL+TG5eLqEdYhoMscDGOifauZY5YIlloB7hARBk/tvko04 OsIopUXZOh8Fn06ohROG17IH/AjtmwYOkf+8RXx+EMUipgKsrsvx0Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=bidouilliste.com; h=from:to :cc:subject:date:message-id; q=dns; s=mail; b=jYWd7f6JizGiJVhCk8 yRid56CaaDtG917eVwmwu70mV7Els4PAW6vX+Q1IKP2oUarOvuV0Ix8g6TXQ9F+V +mukT1KlT+j95alZW+kYb2UV552BDgK19yeoCeuzp05xgqIeSkp3mVVeqWvy2uxC hkGRvAUaaK8X+IBz3ePxwmr2c= Received: from knuckles.blih.net (ip-54.net-82-216-203.roubaix.rev.numericable.fr [82.216.203.54]) by mail.blih.net (OpenSMTPD) with ESMTPSA id 8be1d541 TLS version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO for ; Sat, 5 Nov 2016 22:27:24 +0100 (CET) Received: from elbarto (uid 1001) (envelope-from manu@bidouilliste.com) id 386a40 by knuckles.blih.net (DragonFly Mail Agent v0.11); Sat, 05 Nov 2016 22:27:24 +0100 From: Emmanuel Vadot To: sjg@chromium.org, bmeng.cn@gmail.com, sgalabov@gmail.com Date: Sat, 5 Nov 2016 22:27:20 +0100 Message-Id: <20161105212720.91569-1-manu@bidouilliste.com> X-Mailer: git-send-email 2.9.2 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] api: Use hashtable function for API_env_enum X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Since the env is an hashtable, use the hashtable function for the API_ENV_ENUM api call. Signed-off-by: Emmanuel Vadot --- api/api.c | 60 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/api/api.c b/api/api.c index 8a1433a..c368511 100644 --- a/api/api.c +++ b/api/api.c @@ -495,45 +495,47 @@ static int API_env_set(va_list ap) */ static int API_env_enum(va_list ap) { - int i, n; - char *last, **next; + int i, buflen; + char *last, **next, *s; + ENTRY *match, search; + static char *var; last = (char *)va_arg(ap, unsigned long); if ((next = (char **)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - if (last == NULL) - /* start over */ - *next = ((char *)env_get_addr(0)); - else { - *next = last; - - for (i = 0; env_get_char(i) != '\0'; i = n + 1) { - for (n = i; env_get_char(n) != '\0'; ++n) { - if (n >= CONFIG_ENV_SIZE) { - /* XXX shouldn't we set *next = NULL?? */ - return 0; - } - } - - if (envmatch((uchar *)last, i) < 0) - continue; - - /* try to get next name */ - i = n + 1; - if (env_get_char(i) == '\0') { - /* no more left */ - *next = NULL; - return 0; - } - - *next = ((char *)env_get_addr(i)); - return 0; + if (last == NULL) { + var = NULL; + i = 0; + } else { + var = strdup(last); + s = strchr(var, '='); + if (s != NULL) + *s = 0; + search.key = var; + i = hsearch_r(search, FIND, &match, &env_htab, 0); + if (i == 0) { + i = API_EINVAL; + goto done; } } + /* match the next entry after i */ + i = hmatch_r("", i, &match, &env_htab); + if (i == 0) + goto done; + buflen = strlen(match->key) + strlen(match->data) + 2; + var = realloc(var, buflen); + snprintf(var, buflen, "%s=%s", match->key, match->data); + *next = var; return 0; + +done: + free(var); + var = NULL; + *next = NULL; + return i; } /*