public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Tyler Erickson" <tyler.erickson@seagate.com>
To: devel@edk2.groups.io
Cc: Tyler Erickson <tyler.j.erickson@seagate.com>
Subject: [PATCH] StdLib: Add getopt_long support
Date: Thu,  8 Apr 2021 14:03:46 -0600	[thread overview]
Message-ID: <f85e58283544321780c5f25b2cf3106714ae979d.1617746395.git.tyler.j.erickson@seagate.com> (raw)

From: Tyler Erickson <tyler.j.erickson@seagate.com>

Adding getopt_long support using the implementation in OpenBSD.

Signed-off-by: Tyler Erickson <tyler.j.erickson@seagate.com>
---
 StdLib/Include/unistd.h   |  6 ------
 StdLib/LibC/LibC.inf      |  1 +
 StdLib/LibC/Uefi/Uefi.inf |  1 +
 StdLib/LibC/Uefi/compat.c | 43 +--------------------------------------
 4 files changed, 3 insertions(+), 48 deletions(-)

diff --git a/StdLib/Include/unistd.h b/StdLib/Include/unistd.h
index b2fd923..ca43c0b 100644
--- a/StdLib/Include/unistd.h
+++ b/StdLib/Include/unistd.h
@@ -37,9 +37,6 @@ int             dup(int);
 int             rename(const char *, const char *);
 
 /* Functions implemented for compatibility. */
-int             getopt(int, char * const [], const char *);
-extern   char  *optarg;     /* getopt(3) external variables */
-extern   int    optind;
 pid_t           getpgrp(void);
 pid_t           tcgetpgrp(int);
 char           *getpass(const char *);
@@ -156,9 +153,6 @@ long            sysconf(int);
 int             tcsetpgrp(int, pid_t);
 __aconst char  *ttyname(int);
 
-extern   int    opterr;
-extern   int    optopt;
-extern   int    optreset;
 extern   char  *suboptarg;
 
 int             setegid(gid_t);
diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
index 5bb2053..6b6fa73 100644
--- a/StdLib/LibC/LibC.inf
+++ b/StdLib/LibC/LibC.inf
@@ -106,6 +106,7 @@
   LibStdLib
   LibStdio
   LibString
+  LibErr
   DevConsole
 
 ################################################################
diff --git a/StdLib/LibC/Uefi/Uefi.inf b/StdLib/LibC/Uefi/Uefi.inf
index 1982dd9..817c985 100644
--- a/StdLib/LibC/Uefi/Uefi.inf
+++ b/StdLib/LibC/Uefi/Uefi.inf
@@ -31,6 +31,7 @@
   Xform.c
   compat.c
   StubFunctions.c
+  getopt_long.c
 
 [Packages]
   StdLib/StdLib.dec
diff --git a/StdLib/LibC/Uefi/compat.c b/StdLib/LibC/Uefi/compat.c
index 251863f..cb20e9c 100644
--- a/StdLib/LibC/Uefi/compat.c
+++ b/StdLib/LibC/Uefi/compat.c
@@ -95,48 +95,7 @@
 #include  <string.h>
 #include  <fcntl.h>
 #include  <sys/syslimits.h>
-
-#ifndef HAVE_GETOPT
-char *optarg;
-int optind = 1;
-int
-getopt(int argc, char **argv, char *args)
-{
-        size_t n;
-  size_t nlen = strlen(args);
-        char cmd;
-        char rv;
-
-        if (argv[optind] && *argv[optind] == '-') {
-                cmd = *(argv[optind] + 1);
-
-                for (n = 0; n < nlen; n++) {
-                        if (args[n] == ':')
-        continue;
-                        if (args[n] == cmd) {
-                                rv = *(argv[optind] + 1);
-                                if (args[n+1] == ':') {
-          if (*(argv[optind] + 2) != '\0') {
-                                          optarg = argv[optind] + 2;
-            optind += 1;
-          } else {
-                                          optarg = argv[optind + 1];
-                                          optind += 2;
-          }
-                                        if (!optarg)
-             optarg="";
-                                        return rv;
-                                } else {
-                                        optarg = NULL;
-                                        optind += 1;
-                                        return rv;
-                                }
-                        }
-                }
-        }
-        return -1;
-}
-#endif
+#include  <getopt.h>
 
 #define ISPATHSEPARATOR(x) ((x == '/') || (x == '\\'))
 
-- 
2.25.1


                 reply	other threads:[~2021-04-08 20:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-list 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=f85e58283544321780c5f25b2cf3106714ae979d.1617746395.git.tyler.j.erickson@seagate.com \
    --to=devel@edk2.groups.io \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox