libc: Change index/rindex from macro to function

to avoid the confliction with the same name variable

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-08-05 18:26:39 +08:00 committed by David Sidrane
parent 2eccc960a9
commit 5c67eac27f
4 changed files with 80 additions and 2 deletions

View File

@ -59,8 +59,6 @@
#define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
#define bcopy(b1,b2,len) (void)memmove(b2,b1,len)
#define bzero(s,n) (void)memset(s,0,n)
#define index(s,c) strchr(s,c)
#define rindex(s,c) strrchr(s,c)
/****************************************************************************
* Inline Functions
@ -91,6 +89,9 @@ int flsl(long j);
int flsll(long long j);
#endif
FAR char *index(FAR const char *s, int c);
FAR char *rindex(FAR const char *s, int c);
int strcasecmp(FAR const char *, FAR const char *);
int strncasecmp(FAR const char *, FAR const char *, size_t);

View File

@ -48,6 +48,7 @@ CSRCS += lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c
CSRCS += lib_strsep.c lib_strerrorr.c lib_explicit_bzero.c lib_strsignal.c
CSRCS += lib_anbstr2cstr.c lib_ancstr2bstr.c lib_bmem2cmem.c
CSRCS += lib_bstrnlen.c lib_cmem2bmem.c lib_nbstr2cstr.c lib_ncstr2bstr.c
CSRCS += lib_index.c lib_rindex.c
ifneq ($(CONFIG_LIBC_ARCH_MEMCPY),y)
ifeq ($(CONFIG_MEMCPY_VIK),y)

View File

@ -0,0 +1,38 @@
/****************************************************************************
* libs/libc/stdlib/lib_index.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 <strings.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: index
****************************************************************************/
FAR char *index(FAR const char *s, int c)
{
return strchr(s, c);
}

View File

@ -0,0 +1,38 @@
/****************************************************************************
* libs/libc/stdlib/lib_rindex.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 <strings.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: rindex
****************************************************************************/
FAR char *rindex(FAR const char *s, int c)
{
return strrchr(s, c);
}