versadac  1
versadac - Scalable Recorder Firmware
string.h
1 /* Generic string.h */
2 /* $OpenLDAP: pkg/ldap/include/ac/string.h,v 1.51.2.3 2008/02/11 23:26:40 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2008 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 
17 #ifndef _AC_STRING_H
18 #define _AC_STRING_H
19 
20 #ifdef STDC_HEADERS
21 # include <string.h>
22 
23 #else
24 # ifdef HAVE_STRING_H
25 # include <string.h>
26 # endif
27 # if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
28 # include <strings.h>
29 # endif
30 
31 # ifdef HAVE_MEMORY_H
32 # include <memory.h>
33 # endif
34 
35 # ifndef HAVE_STRRCHR
36 # undef strchr
37 # define strchr index
38 # undef strrchr
39 # define strrchr rindex
40 # endif
41 
42 # 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)))
47 # endif
48 #endif
49 
50 /* use ldap_pvt_strtok instead of strtok or strtok_r! */
51 LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
52  const char *delim, char **pos ));
53 
54 #ifndef HAVE_STRDUP
55  /* strdup() is missing, declare our own version */
56 # undef strdup
57 # define strdup(s) ber_strdup(s)
58 #elif !defined(_WIN32)
59  /* some systems fail to declare strdup */
60  /* Windows does not require this declaration */
61  LDAP_LIBC_F(char *) (strdup)();
62 #endif
63 
64 /*
65  * some systems fail to declare strcasecmp() and strncasecmp()
66  * we need them declared so we can obtain pointers to them
67  */
68 
69 /* we don't want these declared for Windows or Mingw */
70 #ifndef _WIN32
71 int (strcasecmp)();
72 int (strncasecmp)();
73 #endif
74 
75 #ifndef SAFEMEMCPY
76 # if defined( HAVE_MEMMOVE )
77 # define SAFEMEMCPY( d, s, n ) memmove((d), (s), (n))
78 # elif defined( HAVE_BCOPY )
79 # define SAFEMEMCPY( d, s, n ) bcopy((s), (d), (n))
80 # else
81  /* nothing left but memcpy() */
82 # define SAFEMEMCPY( d, s, n ) memcpy((d), (s), (n))
83 # endif
84 #endif
85 
86 #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
87 #define AC_FMEMCPY( d, s, n ) do { \
88  if((n) == 1) *((char*)(d)) = *((char*)(s)); \
89  else AC_MEMCPY( (d), (s), (n) ); \
90  } while(0)
91 
92 #ifdef NEED_MEMCMP_REPLACEMENT
93  int (lutil_memcmp)(const void *b1, const void *b2, size_t len);
94 #define memcmp lutil_memcmp
95 #endif
96 
97 /* GNU extension (glibc >= 2.1.91), only declared when defined(_GNU_SOURCE) */
98 #ifndef HAVE_MEMRCHR
99 #undef memrchr
100 #define memrchr lutil_memrchr
101 #endif /* ! HAVE_MEMRCHR */
102 void * memrchr(const void *b, int c, size_t len);
103 
104 #define STRLENOF(s) (sizeof(s)-1)
105 
106 #if defined( HAVE_NONPOSIX_STRERROR_R )
107 # define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)))
108 #elif defined( HAVE_STRERROR_R )
109 # define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)) == 0 ? (b) : "Unknown error")
110 #elif defined( HAVE_SYS_ERRLIST )
111 # define AC_STRERROR_R(e,b,l) ((e) > -1 && (e) < sys_nerr \
112  ? sys_errlist[(e)] : "Unknown error" )
113 #elif defined( HAVE_STRERROR )
114 # define AC_STRERROR_R(e,b,l) (strerror(e)) /* NOTE: may be NULL */
115 #else
116 # define AC_STRERROR_R(e,b,l) ("Unknown error")
117 #endif
118 
119 #endif /* _AC_STRING_H */