Implement strings.h macros as inline functions when possible for better C++ compatibility.
This commit is contained in:
parent
22a8c2178d
commit
cb7c5f9921
@ -44,19 +44,6 @@
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Pre-processor Definitions
|
||||
//***************************************************************************
|
||||
|
||||
// Remove macros defined in strings.h. The index() definition, in
|
||||
// particular, can cause naming collision problems.
|
||||
|
||||
#undef bcmp
|
||||
#undef bcopy
|
||||
#undef bzero
|
||||
#undef index
|
||||
#undef rindex
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
@ -100,6 +87,11 @@ namespace std
|
||||
|
||||
// Declared in legacy strings.h
|
||||
|
||||
using ::bcmp;
|
||||
using ::bcopy;
|
||||
using ::bzero;
|
||||
using ::index;
|
||||
using ::rindex;
|
||||
using ::ffs;
|
||||
using ::strcasecmp;
|
||||
using ::strncasecmp;
|
||||
|
@ -47,24 +47,28 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_HAVE_INLINE) && !defined(__cplusplus)
|
||||
/* Compatibility definitions
|
||||
*
|
||||
* Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
|
||||
* Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
|
||||
*/
|
||||
|
||||
#define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
|
||||
#define bcopy(b1,b2,len) (void)memmove(b2,b1,len)
|
||||
# define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
|
||||
# define bcopy(b1,b2,len) (void)memmove(b2,b1,len)
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_BZERO
|
||||
# define bzero(s,n) (void)memset(s,0,n)
|
||||
#endif
|
||||
# ifndef CONFIG_LIBC_ARCH_BZERO
|
||||
# define bzero(s,n) (void)memset(s,0,n)
|
||||
# endif
|
||||
|
||||
#define index(s,c) strchr(s,c)
|
||||
#define rindex(s,c) strrchr(s,c)
|
||||
# define index(s,c) strchr(s,c)
|
||||
# define rindex(s,c) strrchr(s,c)
|
||||
|
||||
#endif /* !CONFIG_HAVE_INLINE && !__cplusplus */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
@ -76,9 +80,51 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
int ffs(int j);
|
||||
int strcasecmp(FAR const char *, FAR const char *);
|
||||
int strncasecmp(FAR const char *, FAR const char *, size_t);
|
||||
#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
|
||||
/* Compatibility inline functions.
|
||||
*
|
||||
* Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
|
||||
* Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
|
||||
*/
|
||||
|
||||
static inline int bcmp(FAR const void *b1, FAR const void *b2, size_t len)
|
||||
{
|
||||
return memcmp(b1, b2, len);
|
||||
}
|
||||
|
||||
static inline void bcopy(FAR const void *b1, FAR void *b2, size_t len)
|
||||
{
|
||||
(void)memmove(b1, b2, len);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_BZERO
|
||||
static inline void bzero(FAR void *s, size_t len)
|
||||
{
|
||||
(void)memset(s, 0, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline FAR char *index(FAR const char *s, int c)
|
||||
{
|
||||
return strchr(s, c);
|
||||
}
|
||||
|
||||
static inline FAR char *rindex(FAR const char *s, int c)
|
||||
{
|
||||
return strrchr(s, c);
|
||||
}
|
||||
#endif /* CONFIG_HAVE_INLINE || __cplusplus */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_LIBC_ARCH_BZERO
|
||||
void bzero(FAR void *s, size_t len);
|
||||
#endif
|
||||
int ffs(int j);
|
||||
int strcasecmp(FAR const char *, FAR const char *);
|
||||
int strncasecmp(FAR const char *, FAR const char *, size_t);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
@ -150,7 +150,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex)
|
||||
|
||||
ret = pthread_takesemaphore((FAR sem_t *)&mutex->sem);
|
||||
|
||||
/* If we succussfully obtained the semaphore, then indicate
|
||||
/* If we successfully obtained the semaphore, then indicate
|
||||
* that we own it.
|
||||
*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user