From a0f9da20a2f2925ec093c575426a677b982370b0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 4 Apr 2021 13:47:39 -0600 Subject: [PATCH] getopt(): Update comments about missing functionality Per the Linux man page, "By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end." This behavior, however, is not implemented in the NuttX getopt() logic. --- libs/libc/unistd/lib_getopt.c | 5 ++++- libs/libc/unistd/lib_getopt_common.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/libc/unistd/lib_getopt.c b/libs/libc/unistd/lib_getopt.c index 8fdff8a4f9..bdd34564c2 100644 --- a/libs/libc/unistd/lib_getopt.c +++ b/libs/libc/unistd/lib_getopt.c @@ -64,7 +64,10 @@ * -1 is returned. As a result, your command line parsing loops * must call getopt() repeatedly and continue to parse if other * errors are returned ('?' or ':') until getopt() finally returns -1. - * (You can also set optind to -1 to force a reset). + * (You can also set optind to -1 to force a reset). + * 4. Standard getopt() permutes the contents of argv as it scans, so that + * eventually all the nonoptions are at the end. This implementation + * does not do this. * * Returned Value: * If an option was successfully found, then getopt() returns the option diff --git a/libs/libc/unistd/lib_getopt_common.c b/libs/libc/unistd/lib_getopt_common.c index 5c89b49ca5..750a596f73 100644 --- a/libs/libc/unistd/lib_getopt_common.c +++ b/libs/libc/unistd/lib_getopt_common.c @@ -327,6 +327,9 @@ errout: * must call getopt() repeatedly and continue to parse if other * errors are returned ('?' or ':') until getopt() finally returns -1. * (You can also set optind to -1 to force a reset). + * 4. Standard getopt() permutes the contents of argv as it scans, so that + * eventually all the nonoptions are at the end. This implementation + * does not do this. * * Returned Value: * If an option was successfully found, then getopt() returns the option