Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com From: "Mikael" Subject: Shouldn't getopt_long() return : here? Date: Sun, 24 Apr 2005 20:42:07 +0200 Lines: 81 Message-ID: X-Complaints-To: usenet AT sea DOT gmane DOT org X-Gmane-NNTP-Posting-Host: 180.184.204.213.sol.worldonline.se X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-RFC2646: Format=Flowed; Original X-IsSubscribed: yes Hello, consider this C program and its accompanying test script: #include #include static void handle_args(int, char **); int main(int argc, char **argv) { handle_args(argc, argv); return 0; } #define REQUIRES_ARGUMENT 1 static void handle_args(int argc, char **argv) { const struct option long_options[] = { {"option_with_argument", REQUIRES_ARGUMENT, NULL, 0}, {NULL, 0, NULL, 0}, }; const char *short_options = ""; int c = 0; while((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch(c) { case ':': { printf("Missing parameter.\n"); break; } case '?': { printf("Unknown option.\n"); break; } } } } #!/bin/bash echo "Testing with parameter --option_with_argument=4711" ./getopt_long_problem --option_with_argument=4711 echo -e "\nTesting with parameter --option_with_argument" ./getopt_long_problem --option_with_argument echo -e "\nTesting with parameter --unknown_option" ./getopt_long_problem --unknown_option The output when I run the script is: $ ./probtest.sh Testing with parameter --option_with_argument=4711 Testing with parameter --option_with_argument getopt_long_problem: option requires an argument -- option_with_argument Unknown option. Testing with parameter --unknown_option getopt_long_problem: unknown option -- unknown_option Unknown option. As you can see, getopt_long() returns '?' for the case where the option requires arguments and none was supplied, I was under the impression that it should return ':' for that case and '?' for unknown options (it prints the correct diagnostic, though). Is this a bug in the implementation of getopt_long() that Cygwin comes with or are the docs I have read simply not applicable to Cygwins implementation? / Mikael -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/