You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2020/08/05 11:39:15 UTC

[incubator-nuttx] branch master updated: libc: Change index/rindex from macro to function

This is an automated email from the ASF dual-hosted git repository.

davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c67eac  libc: Change index/rindex from macro to function
5c67eac is described below

commit 5c67eac27f142c378b0a632b37bbdf1ff07e66b4
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Aug 5 18:26:39 2020 +0800

    libc: Change index/rindex from macro to function
    
    to avoid the confliction with the same name variable
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/strings.h             |  5 +++--
 libs/libc/string/Make.defs    |  1 +
 libs/libc/string/lib_index.c  | 38 ++++++++++++++++++++++++++++++++++++++
 libs/libc/string/lib_rindex.c | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/include/strings.h b/include/strings.h
index a2ce037..21b519c 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -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);
 
diff --git a/libs/libc/string/Make.defs b/libs/libc/string/Make.defs
index 8dc4263..c3df1b4 100644
--- a/libs/libc/string/Make.defs
+++ b/libs/libc/string/Make.defs
@@ -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)
diff --git a/libs/libc/string/lib_index.c b/libs/libc/string/lib_index.c
new file mode 100644
index 0000000..9056b5f
--- /dev/null
+++ b/libs/libc/string/lib_index.c
@@ -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);
+}
diff --git a/libs/libc/string/lib_rindex.c b/libs/libc/string/lib_rindex.c
new file mode 100644
index 0000000..9be145e
--- /dev/null
+++ b/libs/libc/string/lib_rindex.c
@@ -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);
+}