all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Elad Lahav <e2lahav@gmail.com>
To: emacs-devel@gnu.org
Subject: getopt() and POSIX
Date: Tue, 16 May 2023 13:59:29 -0400	[thread overview]
Message-ID: <CAJbg=FVb_m5FvVi0AhFTginMv-75eQHN_1jx5X-Z4tT5thM56Q@mail.gmail.com> (raw)

Hello,

The configure script attempts to determines whether getopt() is POSIX
compliant by compiling and running the following code:

#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int
main ()
{
  static char program[] = "program";
  static char ab[] = "-ab";
  char *argv[3] = { program, ab, NULL };
  if (getopt (2, argv, "ab:") != 'a')
    return 13;
  if (getopt (2, argv, "ab:") != '?')
    return 14;
  if (optopt != 'b')
    return 15;
  if (optind != 2)
    return 16;
  return 0;
}

This test fails on QNX for the last test point, which has optind set
to 3. However, as far as I can tell, this is what POSIX expects, and 2
is wrong:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html

"If the option was the last character in the string pointed to by an
element of argv, then optarg shall contain the next element of argv,
and optind shall be incremented by 2. If the resulting value of optind
is greater than argc, this indicates a missing option-argument, and
getopt() shall return an error indication."

In this case optind is 1 and incremented by 2, the argument is missing
and now optind is greater than argc (2), as expected.

None of this really matters much, except that the compliance failure
leads to an attempt to use rpl_getopt(), which fails due to unresolved
symbols (which is a separate issue).

Thoughts?

--Elad



             reply	other threads:[~2023-05-16 17:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 17:59 Elad Lahav [this message]
2023-05-16 18:27 ` getopt() and POSIX Eli Zaretskii
2023-05-17  1:15 ` Po Lu
2023-05-17  1:54   ` Elad Lahav
2023-05-17  2:02     ` Elad Lahav

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='CAJbg=FVb_m5FvVi0AhFTginMv-75eQHN_1jx5X-Z4tT5thM56Q@mail.gmail.com' \
    --to=e2lahav@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.