From patchwork Wed Aug 30 11:56:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Mitchell X-Patchwork-Id: 9929381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5EFFE6022E for ; Wed, 30 Aug 2017 11:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EBEB209CE for ; Wed, 30 Aug 2017 11:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43DAC284C4; Wed, 30 Aug 2017 11:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D69C6209CE for ; Wed, 30 Aug 2017 11:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbdH3L4d (ORCPT ); Wed, 30 Aug 2017 07:56:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45486 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751337AbdH3L4c (ORCPT ); Wed, 30 Aug 2017 07:56:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83ACC7EA93 for ; Wed, 30 Aug 2017 11:56:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83ACC7EA93 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jumitche@redhat.com Received: from jumitche.remote.csb (unknown [10.33.36.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF3C28E25D; Wed, 30 Aug 2017 11:56:31 +0000 (UTC) Message-ID: <1504094190.10850.8.camel@redhat.com> Subject: [PATCH 4/7] nfs-utils: Add get_str with default value From: Justin Mitchell To: Steve Dickson Cc: linux-nfs@vger.kernel.org Date: Wed, 30 Aug 2017 12:56:30 +0100 In-Reply-To: <1504093866.10850.1.camel@redhat.com> References: <1504093866.10850.1.camel@redhat.com> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 30 Aug 2017 11:56:32 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The similar config code in libnfsidmap had one additional feature of a get_str function with a default value option, include an equivalent function here to maintain compatibility. Signed-off-by: Justin Mitchell --- support/include/conffile.h | 1 + support/nfs/conffile.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/support/include/conffile.h b/support/include/conffile.h index 0e7fa8b..d4cb6b4 100644 --- a/support/include/conffile.h +++ b/support/include/conffile.h @@ -58,6 +58,7 @@ extern struct conf_list *conf_get_tag_list(const char *, const char *); extern int conf_get_num(const char *, const char *, int); extern _Bool conf_get_bool(const char *, const char *, _Bool); extern char *conf_get_str(const char *, const char *); +extern char *conf_get_str_with_def(const char *, const char *, char *); extern char *conf_get_section(const char *, const char *, const char *); extern void conf_init(const char *); extern void conf_cleanup(void); diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 9c0fad9..c97f82a 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -635,6 +635,17 @@ conf_get_str(const char *section, const char *tag) return conf_get_section(section, NULL, tag); } +/* Return the string value denoted by TAG in section SECTION, + * unless it is not set, in which case return def + */ +char * +conf_get_str_with_def(const char *section, const char *tag, char *def) +{ + char * result = conf_get_section(section, NULL, tag); + if (!result) return def; + return result; +} + /* * Find a section that may or may not have an argument */