Skip to content

Commit

Permalink
Handle Posix getopt
Browse files Browse the repository at this point in the history
The GNU implementation of `getopt` permute the contents of argv as it scans,
so that eventually all the nonoptions are at the end. This doesn't happen
in FreeBSD and in MacOSX, where the BSD implementation is used.

This behaviour of the GNU implementation of `getopt` was hiding a bug since
the `optind` was initialized to zero, causing the first string of argv (the
executable name) to be interpreted as the name of the file to edit.

By default `optind` is initialized to `1` by the system (see [1] for more info
and for a better explanation of the issue).

[1]: https://linux.die.net/man/3/getopt
  • Loading branch information
leonardoce authored and adsr committed Apr 25, 2017
1 parent f8d30f8 commit 4a49979
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ static int _editor_init_from_args(editor_t* editor, int argc, char** argv) {

cur_kmap = NULL;
cur_syntax = NULL;
optind = 0;
optind = 1;
while (rv == MLE_OK && (c = getopt(argc, argv, "ha:b:c:H:i:K:k:l:M:m:Nn:p:S:s:t:vw:x:y:z:")) != -1) {
switch (c) {
case 'h':
Expand Down

0 comments on commit 4a49979

Please sign in to comment.