You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/11/21 13:01:20 UTC
[incubator-nuttx] 01/02: libc: Add opterr global variable
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit af53bdb048c50577e2f648aa8af5cfed31d25aa1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Nov 17 09:27:01 2020 -0800
libc: Add opterr global variable
defined here:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
include/unistd.h | 3 +++
libs/libc/libc.csv | 1 +
libs/libc/unistd/Make.defs | 6 +++---
libs/libc/unistd/lib_getopt.c | 1 +
libs/libc/unistd/lib_getopterrp.c | 45 +++++++++++++++++++++++++++++++++++++++
5 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/include/unistd.h b/include/unistd.h
index c4460eb..627eb1a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -296,10 +296,12 @@ extern "C"
#ifndef __NXFLAT__
EXTERN FAR char *optarg; /* Optional argument following option */
+EXTERN int opterr; /* Print error message */
EXTERN int optind; /* Index into argv */
EXTERN int optopt; /* Unrecognized option character */
#else
# define optarg (*(getoptargp()))
+# define opterr (*(getopterrp()))
# define optind (*(getoptindp()))
# define optopt (*(getoptoptp()))
#endif
@@ -389,6 +391,7 @@ int getopt(int argc, FAR char * const argv[], FAR const char *optstring);
*/
FAR char **getoptargp(void); /* Optional argument following option */
+FAR int *getopterrp(void); /* Print error message */
FAR int *getoptindp(void); /* Index into argv */
FAR int *getoptoptp(void); /* Unrecognized option character */
diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv
index de0d748..a5395ed 100644
--- a/libs/libc/libc.csv
+++ b/libs/libc/libc.csv
@@ -55,6 +55,7 @@
"gethostname","unistd.h","","int","FAR char *","size_t"
"getopt","unistd.h","","int","int","FAR char * const []|FAR char * const *","FAR const char *"
"getoptargp","unistd.h","","FAR char **"
+"getopterrp","unistd.h","","FAR int *"
"getoptindp","unistd.h","","FAR int *"
"getoptoptp","unistd.h","","FAR int *"
"gets","stdio.h","defined(CONFIG_FILE_STREAM)","FAR char *","FAR char *"
diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs
index 40410db..3955fe8 100644
--- a/libs/libc/unistd/Make.defs
+++ b/libs/libc/unistd/Make.defs
@@ -36,9 +36,9 @@
# Add the unistd C files to the build
CSRCS += lib_access.c lib_daemon.c lib_swab.c lib_pathconf.c lib_sysconf.c
-CSRCS += lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c
-CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_usleep.c
-CSRCS += lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
+CSRCS += lib_getopt.c lib_getoptargp.c lib_getopterrp.c lib_getoptindp.c
+CSRCS += lib_getoptoptp.c lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c
+CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
CSRCS += lib_setreuid.c lib_setregid.c
CSRCS += lib_getrusage.c lib_utimes.c
CSRCS += lib_setrlimit.c lib_getrlimit.c
diff --git a/libs/libc/unistd/lib_getopt.c b/libs/libc/unistd/lib_getopt.c
index 9450a57..56e1afe 100644
--- a/libs/libc/unistd/lib_getopt.c
+++ b/libs/libc/unistd/lib_getopt.c
@@ -52,6 +52,7 @@
****************************************************************************/
FAR char *optarg; /* Optional argument following option */
+int opterr = 0; /* Print error message */
int optind = 1; /* Index into argv */
int optopt = '?'; /* unrecognized option character */
diff --git a/libs/libc/unistd/lib_getopterrp.c b/libs/libc/unistd/lib_getopterrp.c
new file mode 100644
index 0000000..333e82b
--- /dev/null
+++ b/libs/libc/unistd/lib_getopterrp.c
@@ -0,0 +1,45 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getopterrp.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getopterrp
+ *
+ * Description:
+ * Returns a pointer to opterr. This function is only used for external
+ * modules that need to access the base, global variable, opterr.
+ *
+ ****************************************************************************/
+
+FAR int *getopterrp(void)
+{
+ return &opterr;
+}