openldap/include/ac/string.h

120 lines
3.2 KiB
C
Raw Normal View History

1998-10-25 09:41:42 +08:00
/* Generic string.h */
1999-08-30 16:08:00 +08:00
/* $OpenLDAP$ */
2003-11-26 12:16:36 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2006-01-04 07:11:52 +08:00
* Copyright 1998-2006 The OpenLDAP Foundation.
1998-12-29 03:51:35 +08:00
* All rights reserved.
*
2001-05-29 11:35:56 +08:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
2003-11-26 07:17:08 +08:00
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
1998-12-29 03:51:35 +08:00
*/
1998-10-25 09:41:42 +08:00
#ifndef _AC_STRING_H
#define _AC_STRING_H
#ifdef STDC_HEADERS
# include <string.h>
1998-10-25 09:41:42 +08:00
#else
# ifdef HAVE_STRING_H
# include <string.h>
# endif
2002-07-26 21:46:09 +08:00
# if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
# include <strings.h>
# endif
# ifdef HAVE_MEMORY_H
# include <memory.h>
# endif
# ifndef HAVE_STRRCHR
# undef strchr
1998-10-25 09:41:42 +08:00
# define strchr index
# undef strrchr
1998-10-25 09:41:42 +08:00
# define strrchr rindex
# endif
# ifndef HAVE_MEMCPY
# undef memcpy
# define memcpy(d, s, n) ((void) bcopy ((s), (d), (n)))
# undef memmove
# define memmove(d, s, n) ((void) bcopy ((s), (d), (n)))
1998-10-25 09:41:42 +08:00
# endif
#endif
/* use ldap_pvt_strtok instead of strtok or strtok_r! */
LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
const char *delim, char **pos ));
#ifndef HAVE_STRDUP
/* strdup() is missing, declare our own version */
# undef strdup
# define strdup(s) ber_strdup(s)
2001-12-07 12:03:25 +08:00
#elif !defined(_WIN32)
/* some systems fail to declare strdup */
2001-12-07 12:03:25 +08:00
/* Windows does not require this declaration */
LDAP_LIBC_F(char *) (strdup)();
1998-10-25 09:41:42 +08:00
#endif
/*
* some systems fail to declare strcasecmp() and strncasecmp()
* we need them declared so we can obtain pointers to them
*/
1999-11-28 07:40:08 +08:00
2001-12-18 06:40:10 +08:00
/* we don't want these declared for Windows or Mingw */
#ifndef _WIN32
1999-11-28 07:40:08 +08:00
int (strcasecmp)();
int (strncasecmp)();
2001-12-18 06:40:10 +08:00
#endif
1998-10-25 09:41:42 +08:00
#ifndef SAFEMEMCPY
# if defined( HAVE_MEMMOVE )
# define SAFEMEMCPY( d, s, n ) memmove((d), (s), (n))
# elif defined( HAVE_BCOPY )
1998-10-25 09:41:42 +08:00
# define SAFEMEMCPY( d, s, n ) bcopy((s), (d), (n))
# else
1998-10-25 09:41:42 +08:00
/* nothing left but memcpy() */
# define SAFEMEMCPY( d, s, n ) memcpy((d), (s), (n))
# endif
#endif
#define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
#define AC_FMEMCPY( d, s, n ) do { \
if((n) == 1) *((char*)(d)) = *((char*)(s)); \
else AC_MEMCPY( (d), (s), (n) ); \
} while(0)
#ifdef NEED_MEMCMP_REPLACEMENT
int (lutil_memcmp)(const void *b1, const void *b2, size_t len);
#define memcmp lutil_memcmp
#endif
/* GNU extension (glibc >= 2.1.91), only declared when defined(_GNU_SOURCE) */
#ifndef HAVE_MEMRCHR
#undef memrchr
#define memrchr lutil_memrchr
#endif /* ! HAVE_MEMRCHR */
void * memrchr(const void *b, int c, size_t len);
2004-04-07 08:41:57 +08:00
#define STRLENOF(s) (sizeof(s)-1)
2004-04-25 08:19:06 +08:00
#if defined( HAVE_NONPOSIX_STRERROR_R )
# define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)))
#elif defined( HAVE_STRERROR_R )
# define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)) == 0 ? (b) : "Unknown error")
2004-04-25 08:19:06 +08:00
#elif defined( HAVE_SYS_ERRLIST )
# define AC_STRERROR_R(e,b,l) ((e) > -1 && (e) < sys_nerr \
? sys_errlist[(e)] : "Unknown error" )
2004-04-25 08:19:06 +08:00
#elif defined( HAVE_STRERROR )
# define AC_STRERROR_R(e,b,l) (strerror(e)) /* NOTE: may be NULL */
2004-04-25 08:19:06 +08:00
#else
# define AC_STRERROR_R(e,b,l) ("Unknown error")
2004-04-25 08:19:06 +08:00
#endif
1998-10-25 09:41:42 +08:00
#endif /* _AC_STRING_H */