]> git.sur5r.net Git - openldap/blob - include/ac/string.h
Import latest from devel
[openldap] / include / ac / string.h
1 /* Generic string.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted only
8  * as authorized by the OpenLDAP Public License.  A copy of this
9  * license is available at http://www.OpenLDAP.org/license.html or
10  * in file LICENSE in the top-level directory of the distribution.
11  */
12
13 #ifndef _AC_STRING_H
14 #define _AC_STRING_H
15
16 #ifdef STDC_HEADERS
17 #       include <string.h>
18
19 #else
20 #       ifdef HAVE_STRING_H
21 #               include <string.h>
22 #       elif HAVE_STRINGS_H
23 #               include <strings.h>
24 #       endif
25
26 #       ifdef HAVE_MEMORY_H
27 #               include <memory.h>
28 #       endif
29
30 #       ifndef HAVE_STRRCHR
31 #               undef strchr
32 #               define strchr index
33 #               undef strrchr
34 #               define strrchr rindex
35 #       endif
36
37 #       ifndef HAVE_MEMCPY
38 #               undef memcpy
39 #               define memcpy(d, s, n)          ((void) bcopy ((s), (d), (n)))
40 #               undef memmove
41 #               define memmove(d, s, n)         ((void) bcopy ((s), (d), (n)))
42 #       endif
43 #endif
44
45 /* use ldap_pvt_strtok instead of strtok or strtok_r! */
46 LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str, const char *delim,
47                                            char **pos ));
48
49 #ifndef HAVE_STRDUP
50         /* strdup() is missing, declare our own version */
51 #       undef strdup
52 #       define strdup(s) ber_strdup(s)
53 #else
54         /* some systems fail to declare strdup */
55         LDAP_LIBC_F(char *) (strdup)();
56 #endif
57
58 /*
59  * some systems fail to declare strcasecmp() and strncasecmp()
60  * we need them declared so we can obtain pointers to them
61  */
62
63 /* In Mingw32, strcasecmp is not in the C library, so we don't LIBC_F it */
64 int (strcasecmp)();
65 int (strncasecmp)();
66
67 #ifndef SAFEMEMCPY
68 #       if defined( HAVE_MEMMOVE )
69 #               define SAFEMEMCPY( d, s, n )    memmove((d), (s), (n))
70 #       elif defined( HAVE_BCOPY )
71 #               define SAFEMEMCPY( d, s, n )    bcopy((s), (d), (n))
72 #       else
73                 /* nothing left but memcpy() */
74 #               define SAFEMEMCPY( d, s, n )    memcpy((d), (s), (n))
75 #       endif
76 #endif
77
78 #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
79 #define AC_FMEMCPY( d, s, n ) do { \
80                 if((n) == 1) *((char*)(d)) = *((char*)(s)); \
81                 else AC_MEMCPY( (d), (s), (n) ); \
82         } while(0)
83
84 #endif /* _AC_STRING_H */