string.h 3.09 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
/* Generic string.h */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
 * Copyright 1998-2005 The OpenLDAP Foundation.
6
7
 * All rights reserved.
 *
8
9
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
Kurt Zeilenga's avatar
Kurt Zeilenga committed
10
11
12
13
14
 * Public License.
 *
 * A copy of this license is available in file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
15
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
16
17
18
19
20
21

#ifndef _AC_STRING_H
#define _AC_STRING_H

#ifdef STDC_HEADERS
#	include <string.h>
22

Kurt Zeilenga's avatar
Kurt Zeilenga committed
23
#else
24
25
#	ifdef HAVE_STRING_H
#		include <string.h>
26
#	endif
Howard Chu's avatar
Howard Chu committed
27
#	if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
28
29
30
#		include <strings.h>
#	endif

31
32
33
34
#	ifdef HAVE_MEMORY_H
#		include <memory.h>
#	endif

35
#	ifndef HAVE_STRRCHR
36
#		undef strchr
Kurt Zeilenga's avatar
Kurt Zeilenga committed
37
#		define strchr index
38
#		undef strrchr
Kurt Zeilenga's avatar
Kurt Zeilenga committed
39
40
41
42
#		define strrchr rindex
#	endif

#	ifndef HAVE_MEMCPY
43
#		undef memcpy
44
#		define memcpy(d, s, n)		((void) bcopy ((s), (d), (n)))
45
#		undef memmove
46
#		define memmove(d, s, n)		((void) bcopy ((s), (d), (n)))
Kurt Zeilenga's avatar
Kurt Zeilenga committed
47
#	endif
48
#endif
49

50
/* use ldap_pvt_strtok instead of strtok or strtok_r! */
51
52
LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
	const char *delim, char **pos ));
Kurt Zeilenga's avatar
Kurt Zeilenga committed
53

54
#ifndef HAVE_STRDUP
55
	/* strdup() is missing, declare our own version */
56
#	undef strdup
57
#	define strdup(s) ber_strdup(s)
Howard Chu's avatar
Howard Chu committed
58
#elif !defined(_WIN32)
59
	/* some systems fail to declare strdup */
Howard Chu's avatar
Howard Chu committed
60
	/* Windows does not require this declaration */
61
	LDAP_LIBC_F(char *) (strdup)();
Kurt Zeilenga's avatar
Kurt Zeilenga committed
62
63
#endif

64
65
/*
 * some systems fail to declare strcasecmp() and strncasecmp()
66
 * we need them declared so we can obtain pointers to them
67
 */
Howard Chu's avatar
Howard Chu committed
68

69
70
/* we don't want these declared for Windows or Mingw */
#ifndef _WIN32
Howard Chu's avatar
Howard Chu committed
71
72
int (strcasecmp)();
int (strncasecmp)();
73
#endif
74

Kurt Zeilenga's avatar
Kurt Zeilenga committed
75
76
77
#ifndef SAFEMEMCPY
#	if defined( HAVE_MEMMOVE )
#		define SAFEMEMCPY( d, s, n ) 	memmove((d), (s), (n))
78
#	elif defined( HAVE_BCOPY )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
79
#		define SAFEMEMCPY( d, s, n ) 	bcopy((s), (d), (n))
80
#	else
Kurt Zeilenga's avatar
Kurt Zeilenga committed
81
82
83
84
85
		/* nothing left but memcpy() */
#		define SAFEMEMCPY( d, s, n )	memcpy((d), (s), (n))
#	endif
#endif

86
87
88
89
90
91
#define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
#define AC_FMEMCPY( d, s, n ) do { \
		if((n) == 1) *((char*)(d)) = *((char*)(s)); \
		else AC_MEMCPY( (d), (s), (n) ); \
	} while(0)

Kurt Zeilenga's avatar
Kurt Zeilenga committed
92
93
94
95
96
#ifdef NEED_MEMCMP_REPLACEMENT
	int (lutil_memcmp)(const void *b1, const void *b2, size_t len);
#define memcmp lutil_memcmp
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
97
98
99
100
101
102
103
/* GNU extension (glibc >= 2.1.91), only declared when defined(_GNU_SOURCE) */
#ifndef HAVE_MEMRCHR
#undef memrchr
#define memrchr lutil_memrchr
#endif /* ! HAVE_MEMRCHR */
void * memrchr(const void *b, int c, size_t len);

Kurt Zeilenga's avatar
Kurt Zeilenga committed
104
105
#define STRLENOF(s)	(sizeof(s)-1)

Kurt Zeilenga's avatar
Kurt Zeilenga committed
106
107
108
#if defined( HAVE_NONPOSIX_STRERROR_R )
#	define AC_STRERROR_R(e,b,l)		(strerror_r((e), (b), (l)))
#elif defined( HAVE_STRERROR_R )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
109
#	define AC_STRERROR_R(e,b,l)		(strerror_r((e), (b), (l)) ? (b) : "")
Kurt Zeilenga's avatar
Kurt Zeilenga committed
110
111
#elif defined( HAVE_SYS_ERRLIST )
#	define AC_STRERROR_R(e,b,l)		((e) > -1 && (e) < sys_nerr \
Kurt Zeilenga's avatar
Kurt Zeilenga committed
112
										? sys_errlist[(e)] : "" )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
113
114
115
#elif defined( HAVE_STRERROR )
#	define AC_STRERROR_R(e,b,l)		(strerror(e))
#else
Kurt Zeilenga's avatar
Kurt Zeilenga committed
116
#	define AC_STRERROR_R(e,b,l)		("")
Kurt Zeilenga's avatar
Kurt Zeilenga committed
117
118
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
119
#endif /* _AC_STRING_H */