Back to index

openldap  2.4.31
string.h
Go to the documentation of this file.
00001 /* Generic string.h */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #ifndef _AC_STRING_H
00018 #define _AC_STRING_H
00019 
00020 #ifdef STDC_HEADERS
00021 #      include <string.h>
00022 
00023 #else
00024 #      ifdef HAVE_STRING_H
00025 #             include <string.h>
00026 #      endif
00027 #      if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
00028 #             include <strings.h>
00029 #      endif
00030 
00031 #      ifdef HAVE_MEMORY_H
00032 #             include <memory.h>
00033 #      endif
00034 
00035 #      ifndef HAVE_STRRCHR
00036 #             undef strchr
00037 #             define strchr index
00038 #             undef strrchr
00039 #             define strrchr rindex
00040 #      endif
00041 
00042 #      ifndef HAVE_MEMCPY
00043 #             undef memcpy
00044 #             define memcpy(d, s, n)             ((void) bcopy ((s), (d), (n)))
00045 #             undef memmove
00046 #             define memmove(d, s, n)            ((void) bcopy ((s), (d), (n)))
00047 #      endif
00048 #endif
00049 
00050 /* use ldap_pvt_strtok instead of strtok or strtok_r! */
00051 LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
00052        const char *delim, char **pos ));
00053 
00054 #ifndef HAVE_STRDUP
00055        /* strdup() is missing, declare our own version */
00056 #      undef strdup
00057 #      define strdup(s) ber_strdup(s)
00058 #elif !defined(_WIN32)
00059        /* some systems fail to declare strdup */
00060        /* Windows does not require this declaration */
00061        LDAP_LIBC_F(char *) (strdup)();
00062 #endif
00063 
00064 /*
00065  * some systems fail to declare strcasecmp() and strncasecmp()
00066  * we need them declared so we can obtain pointers to them
00067  */
00068 
00069 /* we don't want these declared for Windows or Mingw */
00070 #ifndef _WIN32
00071 int (strcasecmp)();
00072 int (strncasecmp)();
00073 #endif
00074 
00075 #ifndef SAFEMEMCPY
00076 #      if defined( HAVE_MEMMOVE )
00077 #             define SAFEMEMCPY( d, s, n )       memmove((d), (s), (n))
00078 #      elif defined( HAVE_BCOPY )
00079 #             define SAFEMEMCPY( d, s, n )       bcopy((s), (d), (n))
00080 #      else
00081               /* nothing left but memcpy() */
00082 #             define SAFEMEMCPY( d, s, n )       memcpy((d), (s), (n))
00083 #      endif
00084 #endif
00085 
00086 #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
00087 #define AC_FMEMCPY( d, s, n ) do { \
00088               if((n) == 1) *((char*)(d)) = *((char*)(s)); \
00089               else AC_MEMCPY( (d), (s), (n) ); \
00090        } while(0)
00091 
00092 #ifdef NEED_MEMCMP_REPLACEMENT
00093        int (lutil_memcmp)(const void *b1, const void *b2, size_t len);
00094 #define memcmp lutil_memcmp
00095 #endif
00096 
00097 void *(lutil_memrchr)(const void *b, int c, size_t n);
00098 /* GNU extension (glibc >= 2.1.91), only declared when defined(_GNU_SOURCE) */
00099 #if defined(HAVE_MEMRCHR) && defined(_GNU_SOURCE)
00100 #define lutil_memrchr(b, c, n) memrchr(b, c, n)
00101 #endif /* ! HAVE_MEMRCHR */
00102 
00103 #define STRLENOF(s)  (sizeof(s)-1)
00104 
00105 #if defined( HAVE_NONPOSIX_STRERROR_R )
00106 #      define AC_STRERROR_R(e,b,l)        (strerror_r((e), (b), (l)))
00107 #elif defined( HAVE_STRERROR_R )
00108 #      define AC_STRERROR_R(e,b,l)        (strerror_r((e), (b), (l)) == 0 ? (b) : "Unknown error")
00109 #elif defined( HAVE_SYS_ERRLIST )
00110 #      define AC_STRERROR_R(e,b,l)        ((e) > -1 && (e) < sys_nerr \
00111                                                  ? sys_errlist[(e)] : "Unknown error" )
00112 #elif defined( HAVE_STRERROR )
00113 #      define AC_STRERROR_R(e,b,l)        (strerror(e)) /* NOTE: may be NULL */
00114 #else
00115 #      define AC_STRERROR_R(e,b,l)        ("Unknown error")
00116 #endif
00117 
00118 #endif /* _AC_STRING_H */