From patchwork Sat Jan 24 15:07:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 432415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2C4B3140291 for ; Sun, 25 Jan 2015 02:21:03 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 88A5C28BE03; Sat, 24 Jan 2015 16:17:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 1E0AC28BDD8 for ; Sat, 24 Jan 2015 16:16:36 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sat, 24 Jan 2015 16:16:31 +0100 (CET) Received: by mail-pa0-f48.google.com with SMTP id ey11so3017941pad.7 for ; Sat, 24 Jan 2015 07:18:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L0byL6ct1k70MUOMstLSXAcwiEkdHGag/jh7xtZfdTI=; b=n8BsEpWVDptBQ2Eh5o7RLewGd/0HKRzR/OlTDyD8O8jZAEx8RmPUGgAeZY5kbnK+8B dFx4O1KZVToOR+TVyc0NiJOOW5EZ/BR5U+Pu2uXyJF5iH8mhui8BhwMPqQNMhW+ENzig qEjsQVeRN3TyzVgrFer8GRBquz/xpeotEuINUteaJ+oW4vCVaH2ARhN9he4l5BrQyIII b4qG+GyLWr/e3r+CRMNYS8vOMckkcYIJVt7zQzxyT2T/2hRQ5EtS7PynpGxaIv64uFOH OEWpHHLny585xE2qtlqJB55d3F9x5PjdB/Mppa4uJcgbKWJcYJAgbHK5nenQ7wO5yO6w SVyQ== X-Received: by 10.70.137.238 with SMTP id ql14mr20417106pdb.94.1422112726689; Sat, 24 Jan 2015 07:18:46 -0800 (PST) Received: from debian.corp.sankuai.com ([103.29.140.56]) by mx.google.com with ESMTPSA id oi5sm5089119pbb.7.2015.01.24.07.18.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jan 2015 07:18:45 -0800 (PST) From: Yousong Zhou To: nbd@openwrt.org Date: Sat, 24 Jan 2015 23:07:53 +0800 Message-Id: <1422112073-24903-5-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1422112073-24903-1-git-send-email-yszhou4tech@gmail.com> References: <1422112073-24903-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH 4/4] Add a few notes on the return value of uci_lookup_ptr(). X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" While at it, use UCI_OK instead of literal integer 0 for return value of uci_lookup_ptr(). Signed-off-by: Yousong Zhou --- list.c | 5 +++-- uci.h | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/list.c b/list.c index 0d00f81..321861c 100644 --- a/list.c +++ b/list.c @@ -431,11 +431,12 @@ uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str, bool ext complete: ptr->flags |= UCI_LOOKUP_COMPLETE; abort: - return 0; + return UCI_OK; notfound: UCI_THROW(ctx, UCI_ERR_NOTFOUND); - return 0; + /* not a chance here */ + return UCI_ERR_NOTFOUND; } __private struct uci_element * diff --git a/uci.h b/uci.h index b31d007..abba660 100644 --- a/uci.h +++ b/uci.h @@ -154,6 +154,13 @@ extern int uci_unload(struct uci_context *ctx, struct uci_package *p); * Note: uci_lookup_ptr will automatically load a config package if necessary * @str must not be constant, as it will be modified and used for the strings inside @ptr, * thus it must also be available as long as @ptr is in use. + * + * This function returns UCI_ERR_NOTFOUND if the package specified in the tuple + * string cannot be found. Otherwise it will return UCI_OK. + * + * Note that failures in looking up other parts, if they are also specfied, + * including section and option, will also have a return value UCI_OK but with + * ptr->flags * UCI_LOOKUP_COMPLETE not set. */ extern int uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str, bool extended);