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