ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Alexey Morsov <samurai@ricom.ru>
To: ALT Linux Community <community@altlinux.ru>
Subject: [Comm] segfault with getopt_long
Date: Mon, 14 Mar 2005 11:18:06 +0300
Message-ID: <423548BE.5080103@ricom.ru> (raw)

Привет,

пишу проггу на Си. Для обработки опций запуска использую <getopt.h>
и функцию getopt_long...
Все работает, НО! если дать неверную опцию в коротком виде (-e) то как 
и положенно выдается invalid option
А если дать неверную опцию в длинном виде (--eeee) то вылетает segfault
Из-за чего может быть такое?

======== Лист ==========
static struct option long_options[] = {
    {"start", 0, 0, 0},
    {"stop", 0, 0, 0},
    {"config", 1, 0, 0},
    {"log", 1, 0, 0},
    {"help", 0, 0, 0}
};

int main(int argc, char **argv)
{
    FILE *flog, *fpid;
    pid_t pid;
    struct passwd *pwd;
    char ver[6];
    int c, option_index=0;

    sscanf(VERSION, "%*[$]%*s %[0-9.] %*[$]", ver);
    printf("trafficd %s (c) Morsov, 2005. Distributed under GPL 
license\n\n", ver);

    c = getopt_long(argc, argv, "dsc:l:h", long_options, &option_index);

    if (c == -1) {
       print_help();
       exit(0);
    }

    switch (c) {
       case 0:
          printf ("option %s", long_options[option_index].name);
          if (optarg)
             printf (" with arg %s", optarg);
          printf ("\n");
          exit(0);
       case 'd':
          printf("option d\n");
          exit(0);
       case 's':
          printf("option s\n");
          exit(0);
       case 'c':
          printf("option c with arg = '%s'\n", optarg);
          exit(0);
       case 'l':
          printf("optarg l with arg = '%s'\n", optarg);
          exit(0);
       case 'h':
          print_help();
          exit(0);
    }

    return(0);
}

========================


-- 
Всего наилучшего,
Системный Администратор ЗАО "ИК "РИКОМ-ТРАСТ"
Алексей Морсов
ICQ: 196766290
Jabber: Samurai@jabber.pibhe.com
http://www.ricom.ru
http://www.fondmarket.ru


             reply	other threads:[~2005-03-14  8:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-14  8:18 Alexey Morsov [this message]
2005-03-14  9:05 ` Alexey I. Froloff
2005-03-14  9:30   ` Alexey Morsov
2005-03-14 11:52   ` Alexey Morsov
2005-03-14 11:59     ` Alexey I. Froloff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=423548BE.5080103@ricom.ru \
    --to=samurai@ricom.ru \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git