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