]> git.sur5r.net Git - openldap/blob - include/ac/string.h
Notice updates
[openldap] / include / ac / string.h
1 /* Generic string.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #ifndef _AC_STRING_H
17 #define _AC_STRING_H
18
19 #ifdef STDC_HEADERS
20 #       include <string.h>
21
22 #else
23 #       ifdef HAVE_STRING_H
24 #               include <string.h>
25 #       endif
26 #       if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
27 #               include <strings.h>
28 #       endif
29
30 #       ifdef HAVE_MEMORY_H
31 #               include <memory.h>
32 #       endif
33
34 #       ifndef HAVE_STRRCHR
35 #               undef strchr
36 #               define strchr index
37 #               undef strrchr
38 #               define strrchr rindex
39 #       endif
40
41 #       ifndef HAVE_MEMCPY
42 #               undef memcpy
43 #               define memcpy(d, s, n)          ((void) bcopy ((s), (d), (n)))
44 #               undef memmove
45 #               define memmove(d, s, n)         ((void) bcopy ((s), (d), (n)))
46 #       endif
47 #endif
48
49 /* use ldap_pvt_strtok instead of strtok or strtok_r! */
50 LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
51         const char *delim, char **pos ));
52
53 #ifndef HAVE_STRDUP
54         /* strdup() is missing, declare our own version */
55 #       undef strdup
56 #       define strdup(s) ber_strdup(s)
57 #elif !defined(_WIN32)
58         /* some systems fail to declare strdup */
59         /* Windows does not require this declaration */
60         LDAP_LIBC_F(char *) (strdup)();
61 #endif
62
63 /*
64  * some systems fail to declare strcasecmp() and strncasecmp()
65  * we need them declared so we can obtain pointers to them
66  */
67
68 /* we don't want these declared for Windows or Mingw */
69 #ifndef _WIN32
70 int (strcasecmp)();
71 int (strncasecmp)();
72 #endif
73
74 #ifndef SAFEMEMCPY
75 #       if defined( HAVE_MEMMOVE )
76 #               define SAFEMEMCPY( d, s, n )    memmove((d), (s), (n))
77 #       elif defined( HAVE_BCOPY )
78 #               define SAFEMEMCPY( d, s, n )    bcopy((s), (d), (n))
79 #       else
80                 /* nothing left but memcpy() */
81 #               define SAFEMEMCPY( d, s, n )    memcpy((d), (s), (n))
82 #       endif
83 #endif
84
85 #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
86 #define AC_FMEMCPY( d, s, n ) do { \
87                 if((n) == 1) *((char*)(d)) = *((char*)(s)); \
88                 else AC_MEMCPY( (d), (s), (n) ); \
89         } while(0)
90
91 #endif /* _AC_STRING_H */