diff --git a/include/strings.h b/include/strings.h index a2ce037367..21b519cbde 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 8dc4263b68..c3df1b4fba 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 0000000000..9056b5f18a --- /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 + +/**************************************************************************** + * 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 0000000000..9be145e312 --- /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 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rindex + ****************************************************************************/ + +FAR char *rindex(FAR const char *s, int c) +{ + return strrchr(s, c); +}