[edk2-devel] [PATCH] StdLib: Add getopt_long support

Tyler Erickson via groups.io posted 1 patch 3 years ago
Failed in applying to current master (apply log)
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(-)
[edk2-devel] [PATCH] StdLib: Add getopt_long support
Posted by Tyler Erickson via groups.io 3 years ago
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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73888): https://edk2.groups.io/g/devel/message/73888
Mute This Topic: https://groups.io/mt/81958045/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-