public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] StdLib: Add getopt_long support
@ 2021-04-08 20:03 Tyler Erickson
  0 siblings, 0 replies; only message in thread
From: Tyler Erickson @ 2021-04-08 20:03 UTC (permalink / raw)
  To: devel; +Cc: Tyler Erickson

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-08 20:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-08 20:03 [PATCH] StdLib: Add getopt_long support Tyler Erickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox