string.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Generic string.h */
  2. /* $OpenLDAP$ */
  3. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  4. *
  5. * Copyright 1998-2022 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. #ifndef _AC_STRING_H
  17. #define _AC_STRING_H
  18. #ifdef STDC_HEADERS
  19. # include <string.h>
  20. #else
  21. # ifdef HAVE_STRING_H
  22. # include <string.h>
  23. # endif
  24. # if defined(HAVE_STRINGS_H) && (!defined(HAVE_STRING_H) || defined(BOTH_STRINGS_H))
  25. # include <strings.h>
  26. # endif
  27. # ifdef HAVE_MEMORY_H
  28. # include <memory.h>
  29. # endif
  30. # ifndef HAVE_STRRCHR
  31. # undef strchr
  32. # define strchr index
  33. # undef strrchr
  34. # define strrchr rindex
  35. # endif
  36. # ifndef HAVE_MEMCPY
  37. # undef memcpy
  38. # define memcpy(d, s, n) ((void) bcopy ((s), (d), (n)))
  39. # undef memmove
  40. # define memmove(d, s, n) ((void) bcopy ((s), (d), (n)))
  41. # endif
  42. #endif
  43. /* use ldap_pvt_strtok instead of strtok or strtok_r! */
  44. LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
  45. const char *delim, char **pos ));
  46. #ifndef HAVE_STRDUP
  47. /* strdup() is missing, declare our own version */
  48. # undef strdup
  49. # define strdup(s) ber_strdup(s)
  50. #elif !defined(_WIN32)
  51. /* some systems fail to declare strdup */
  52. /* Windows does not require this declaration */
  53. LDAP_LIBC_F(char *) (strdup)();
  54. #endif
  55. /*
  56. * some systems fail to declare strcasecmp() and strncasecmp()
  57. * we need them declared so we can obtain pointers to them
  58. */
  59. /* we don't want these declared for Windows or Mingw */
  60. #ifndef _WIN32
  61. int (strcasecmp)();
  62. int (strncasecmp)();
  63. #endif
  64. #ifndef SAFEMEMCPY
  65. # if defined( HAVE_MEMMOVE )
  66. # define SAFEMEMCPY( d, s, n ) memmove((d), (s), (n))
  67. # elif defined( HAVE_BCOPY )
  68. # define SAFEMEMCPY( d, s, n ) bcopy((s), (d), (n))
  69. # else
  70. /* nothing left but memcpy() */
  71. # define SAFEMEMCPY( d, s, n ) memcpy((d), (s), (n))
  72. # endif
  73. #endif
  74. #define AC_MEMCPY( d, s, n ) (SAFEMEMCPY((d),(s),(n)))
  75. #define AC_FMEMCPY( d, s, n ) do { \
  76. if((n) == 1) *((char*)(d)) = *((char*)(s)); \
  77. else AC_MEMCPY( (d), (s), (n) ); \
  78. } while(0)
  79. #ifdef NEED_MEMCMP_REPLACEMENT
  80. int (lutil_memcmp)(const void *b1, const void *b2, size_t len);
  81. #define memcmp lutil_memcmp
  82. #endif
  83. void *(lutil_memrchr)(const void *b, int c, size_t n);
  84. /* GNU extension (glibc >= 2.1.91), only declared when defined(_GNU_SOURCE) */
  85. #if defined(HAVE_MEMRCHR) && defined(_GNU_SOURCE)
  86. #define lutil_memrchr(b, c, n) memrchr(b, c, n)
  87. #endif /* ! HAVE_MEMRCHR */
  88. #define STRLENOF(s) (sizeof(s)-1)
  89. #if defined( HAVE_NONPOSIX_STRERROR_R )
  90. # define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)))
  91. #elif defined( HAVE_STRERROR_R )
  92. # define AC_STRERROR_R(e,b,l) (strerror_r((e), (b), (l)) == 0 ? (b) : "Unknown error")
  93. #elif defined( HAVE_SYS_ERRLIST )
  94. # define AC_STRERROR_R(e,b,l) ((e) > -1 && (e) < sys_nerr \
  95. ? sys_errlist[(e)] : "Unknown error" )
  96. #elif defined( HAVE_STRERROR )
  97. # define AC_STRERROR_R(e,b,l) (strerror(e)) /* NOTE: may be NULL */
  98. #else
  99. # define AC_STRERROR_R(e,b,l) ("Unknown error")
  100. #endif
  101. #endif /* _AC_STRING_H */