From patchwork Sun Mar 21 19:20:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 48225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by ozlabs.org (Postfix) with ESMTP id 02559B7CEF for ; Mon, 22 Mar 2010 06:20:37 +1100 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 1426BAD223; Sun, 21 Mar 2010 13:20:37 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=3.8 tests=AWL, BAYES_00, NO_MORE_FUNN, SPF_PASS autolearn=no version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from cdptpa-omtalb.mail.rr.com (cdptpa-omtalb.mail.rr.com [75.180.132.120]) by lists.samba.org (Postfix) with ESMTP id B5358AD0A7 for ; Sun, 21 Mar 2010 13:20:29 -0600 (MDT) X-Authority-Analysis: v=1.0 c=1 a=MMeGi5ruze8A:10 a=20KFwNOVAAAA:8 a=fF78UtU2RCceHLCr6ZsA:9 a=y2wXuHgIcmJbe3exV-Y_Gl8SsfEA:4 a=jEp0ucaQiEUA:10 X-Cloudmark-Score: 0 X-Originating-IP: 71.70.153.3 Received: from [71.70.153.3] ([71.70.153.3:53420] helo=mail.poochiereds.net) by cdptpa-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 14/AF-07392-B7176AB4; Sun, 21 Mar 2010 19:20:27 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id 7307858055; Sun, 21 Mar 2010 15:20:27 -0400 (EDT) From: Jeff Layton To: linux-cifs-client@lists.samba.org Date: Sun, 21 Mar 2010 15:20:20 -0400 Message-Id: <1269199227-21446-4-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: Subject: [linux-cifs-client] [PATCH 03/10] mount.cifs: simplify command-line option parsing X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org Let getopt_long do the work of parsing options, then check what's left. Signed-off-by: Jeff Layton --- mount.cifs.c | 36 ++++++++---------------------------- 1 files changed, 8 insertions(+), 28 deletions(-) diff --git a/mount.cifs.c b/mount.cifs.c index e00375e..9281761 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -1208,33 +1208,6 @@ int main(int argc, char ** argv) if(thisprogram == NULL) thisprogram = "mount.cifs"; - if(argc > 2) { - dev_name = argv[1]; - share_name = strndup(argv[1], MAX_UNC_LEN); - if (share_name == NULL) { - fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM)); - exit(EX_SYSERR); - } - mountpoint = argv[2]; - } else if (argc == 2) { - if ((strcmp(argv[1], "-V") == 0) || - (strcmp(argv[1], "--version") == 0)) - { - print_cifs_mount_version(); - exit(0); - } - - if ((strcmp(argv[1], "-h") == 0) || - (strcmp(argv[1], "-?") == 0) || - (strcmp(argv[1], "--help") == 0)) - mount_cifs_usage(stdout); - - mount_cifs_usage(stderr); - } else { - mount_cifs_usage(stderr); - } - - /* add sharename in opts string as unc= parm */ while ((c = getopt_long (argc, argv, "afFhilL:no:O:rsSU:vVwt:", longopts, NULL)) != -1) { @@ -1366,9 +1339,16 @@ int main(int argc, char ** argv) } } - if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) { + if(argc < 3 || argv[optind] == NULL || argv[optind + 1] == NULL) mount_cifs_usage(stderr); + + dev_name = argv[optind]; + share_name = strndup(argv[optind], MAX_UNC_LEN); + if (share_name == NULL) { + fprintf(stderr, "%s: %s", thisprogram, strerror(ENOMEM)); + exit(EX_SYSERR); } + mountpoint = argv[optind + 1]; /* make sure mountpoint is legit */ rc = chdir(mountpoint);