]> git.sur5r.net Git - openldap/blob - include/ac/string.h
Update copyright notices
[openldap] / include / ac / string.h
1 /* Generic string.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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,
48         const char *delim, 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 #elif !defined(_WIN32)
55         /* some systems fail to declare strdup */
56         /* Windows does not require this declaration */
57         LDAP_LIBC_F(char *) (strdup)();
58 #endif
59
60 /*
61  * some systems fail to declare strcasecmp() and strncasecmp()
62  * we need them declared so we can obtain pointers to them
63  */
64
65 /* we don't want these declared for Windows or Mingw */
66 #ifndef _WIN32
67 int (strcasecmp)();
68 int (strncasecmp)();
69 #endif
70
71 #ifndef SAFEMEMCPY
72 #       if defined( HAVE_MEMMOVE )
73 #               define SAFEMEMCPY( d, s, n )    memmove((d), (s), (n))
74 #       elif defined( HAVE_BCOPY )
75 #               define SAFEMEMCPY( d, s, n )    bcopy((s), (d), (n))
76 #       else
77                 /* nothing left but memcpy() */
78 #               define SAFEMEMCPY( d, s, n )    memcpy((d), (s), (n))
79 #       endif
80 #endif
81
82 #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
83 #define AC_FMEMCPY( d, s, n ) do { \
84                 if((n) == 1) *((char*)(d)) = *((char*)(s)); \
85                 else AC_MEMCPY( (d), (s), (n) ); \
86         } while(0)
87
88 #endif /* _AC_STRING_H */