[glib] GOption: stop calling getopt()
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GOption: stop calling getopt()
- Date: Mon, 20 Oct 2014 12:35:10 +0000 (UTC)
commit 817f82da6c92d8a2ef0e0582037fd2bbd248798c
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Oct 20 14:28:10 2014 +0200
GOption: stop calling getopt()
We called getopt() to try to find out of the platform on which we are
running defaults to strict POSIX-style argument handling (ie: flags
following the first filename are considered as further filenames rather
than flags).
This is the default case on BSDs, for example. It is also the case on
GNU systems with the POSIXLY_CORRECT environment variable set.
Unfortunately many of our tools rely on being able to accept commandline
arguments in the non-strict ordering and the code for making these calls
is spread widely (for example in Makefile fragments invoking some of our
build tools).
For this reason we need to revert the getopt() check and only enable
strict POSIX mode in the case that the application explicitly opts into
it using the _set_strict_posix() API.
This also fixs a failure to build on Windows due to missing getopt().
https://bugzilla.gnome.org/show_bug.cgi?id=723160
glib/goption.c | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)
---
diff --git a/glib/goption.c b/glib/goption.c
index 019f54f..b9b23ba 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -183,7 +183,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
-#include <unistd.h>
#if defined __OpenBSD__
#include <unistd.h>
@@ -360,14 +359,7 @@ g_option_context_new (const gchar *parameter_string)
context = g_new0 (GOptionContext, 1);
context->parameter_string = g_strdup (parameter_string);
- {
- const char *argv[] = { "./a", "a", "-a", NULL };
- /* Check to see if getopt will parse the "-a" or not. If it finds
- * no arguments then we are in strict POSIX mode.
- */
- optind = 1;
- context->strict_posix = getopt (3, (char **) argv, "a") != 'a';
- }
+ context->strict_posix = FALSE;
context->help_enabled = TRUE;
context->ignore_unknown = FALSE;
@@ -499,6 +491,8 @@ g_option_context_get_ignore_unknown_options (GOptionContext *context)
*
* Sets strict POSIX mode.
*
+ * By default, this mode is disabled.
+ *
* In strict POSIX mode, the first non-argument parameter encountered
* (eg: filename) terminates argument processing. Remaining arguments
* are treated as non-options and are not attempted to be parsed.
@@ -510,9 +504,6 @@ g_option_context_get_ignore_unknown_options (GOptionContext *context)
* will list "foo" in long mode. In strict POSIX style, this will list
* the files named "foo" and "-l".
*
- * The default is system-dependent. In particular, on some systems, it
- * may be modified by the POSIXLY_CORRECT environment variable.
- *
* It may be useful to force strict POSIX mode when creating "verb
* style" command line tools. For example, the "gsettings" command line
* tool supports the global option "--schemadir" as well as many
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]