unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* getopt() and POSIX
@ 2023-05-16 17:59 Elad Lahav
  2023-05-16 18:27 ` Eli Zaretskii
  2023-05-17  1:15 ` Po Lu
  0 siblings, 2 replies; 5+ messages in thread
From: Elad Lahav @ 2023-05-16 17:59 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-17  2:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 17:59 getopt() and POSIX Elad Lahav
2023-05-16 18:27 ` Eli Zaretskii
2023-05-17  1:15 ` Po Lu
2023-05-17  1:54   ` Elad Lahav
2023-05-17  2:02     ` Elad Lahav

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).