libc: Add opterr global variable
defined here: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
ac6b08c8e9
commit
af53bdb048
@ -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 */
|
||||
|
||||
|
@ -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 *"
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -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
|
||||
|
@ -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 */
|
||||
|
||||
|
45
libs/libc/unistd/lib_getopterrp.c
Normal file
45
libs/libc/unistd/lib_getopterrp.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user