From patchwork Thu Oct 29 09:31:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7517781 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A1B779F37F for ; Thu, 29 Oct 2015 09:34:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE426208A1 for ; Thu, 29 Oct 2015 09:34:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1C6120772 for ; Thu, 29 Oct 2015 09:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756780AbbJ2JeA (ORCPT ); Thu, 29 Oct 2015 05:34:00 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:5639 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756377AbbJ2Jdm (ORCPT ); Thu, 29 Oct 2015 05:33:42 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="102430441" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Oct 2015 17:35:54 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t9T9X7Xi015836 for ; Thu, 29 Oct 2015 17:33:07 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Thu, 29 Oct 2015 17:33:40 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 6/6] btrfs-progs: Avoid use pointer in handle_options Date: Thu, 29 Oct 2015 17:31:48 +0800 Message-ID: <067592f9b350f23dbe4c255238bfebcc9e34964c.1446111097.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We use pointer of argc and argv in handle_options() because they are necessary in very old code which are not exist now. This patch move to use argc and argv directly in handle_options(), alone with following update: 1: rename handle_options() to check_options() to fit its function. 2: cleanup for condition in handle_options() to make line short. Signed-off-by: Zhao Lei --- btrfs.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/btrfs.c b/btrfs.c index 9416a29..f881c18 100644 --- a/btrfs.c +++ b/btrfs.c @@ -172,20 +172,22 @@ static int cmd_version(int argc, char **argv) return 0; } -static void handle_options(int *argc, char ***argv) +static void check_options(int argc, char **argv) { - if (*argc > 0) { - const char *arg = (*argv)[0]; - if (arg[0] != '-' || - !strcmp(arg, "--help") || - !strcmp(arg, "--version")) - return; - fprintf(stderr, "Unknown option: %s\n", arg); - fprintf(stderr, "usage: %s\n", - btrfs_cmd_group.usagestr[0]); - exit(129); - } - return; + if (argc == 0) + return; + + const char *arg = argv[0]; + + if (arg[0] != '-' || + !strcmp(arg, "--help") || + !strcmp(arg, "--version")) + return; + + fprintf(stderr, "Unknown option: %s\n", arg); + fprintf(stderr, "usage: %s\n", + btrfs_cmd_group.usagestr[0]); + exit(129); } static const struct cmd_group btrfs_cmd_group = { @@ -227,7 +229,7 @@ int main(int argc, char **argv) } else { argc--; argv++; - handle_options(&argc, &argv); + check_options(argc, argv); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2;