string.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJ_COMPAT_STRING_H__
  20. #define __PJ_COMPAT_STRING_H__
  21. /**
  22. * @file string.h
  23. * @brief Provides string manipulation functions found in ANSI string.h.
  24. */
  25. #if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H != 0
  26. # include <string.h>
  27. #else
  28. PJ_DECL(int) strcasecmp(const char *s1, const char *s2);
  29. PJ_DECL(int) strncasecmp(const char *s1, const char *s2, int len);
  30. #endif
  31. /* For sprintf family */
  32. #include <stdio.h>
  33. /* On WinCE, string stuffs are declared in stdlib.h */
  34. #if defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H!=0
  35. # include <stdlib.h>
  36. #endif
  37. #if defined(_MSC_VER)
  38. # define strcasecmp _stricmp
  39. # define strncasecmp _strnicmp
  40. /* snprintf() and vsnprintf() are available since Visual Studio 2015 */
  41. #if _MSC_VER < 1900
  42. # define snprintf _snprintf
  43. # define vsnprintf _vsnprintf
  44. #endif
  45. # define snwprintf _snwprintf
  46. # define wcsicmp _wcsicmp
  47. # define wcsnicmp _wcsnicmp
  48. #else
  49. # define stricmp strcasecmp
  50. # define strnicmp strncasecmp
  51. # if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
  52. # error "Implement Unicode string functions"
  53. # endif
  54. #endif
  55. #define pj_ansi_strcmp strcmp
  56. #define pj_ansi_strncmp strncmp
  57. #define pj_ansi_strlen strlen
  58. #if defined(PJ_BAN_STRCPY) && PJ_BAN_STRCPY
  59. /* Use pj_ansi_strxcpy() instead */
  60. # define strcpy error__strcpy_is_banned
  61. # define pj_ansi_strcpy error__strcpy_is_banned
  62. #else
  63. # define pj_ansi_strcpy strcpy
  64. #endif
  65. #if defined(PJ_BAN_STRNCPY) && PJ_BAN_STRNCPY
  66. /* Use pj_ansi_strxcpy() instead */
  67. # define strncpy error__strncpy_is_banned
  68. # define pj_ansi_strncpy error__strncpy_is_banned
  69. #else
  70. # define pj_ansi_strncpy strncpy
  71. #endif
  72. #if defined(PJ_BAN_STRCAT) && PJ_BAN_STRCAT
  73. /* Use pj_ansi_strxcat() instead */
  74. # define strcat error__strcat_is_banned
  75. # define pj_ansi_strcat error__strcat_is_banned
  76. #else
  77. # define pj_ansi_strcat strcat
  78. #endif
  79. #define pj_ansi_strstr strstr
  80. #define pj_ansi_strchr strchr
  81. #define pj_ansi_strcasecmp strcasecmp
  82. #define pj_ansi_stricmp strcasecmp
  83. #define pj_ansi_strncasecmp strncasecmp
  84. #define pj_ansi_strnicmp strncasecmp
  85. #if defined(PJ_BAN_SPRINTF) && PJ_BAN_SPRINTF
  86. /* Use pj_ansi_snprintf() instead */
  87. # define sprintf error__sprintf_is_banned
  88. # define pj_ansi_sprintf error__sprintf_is_banned
  89. #else
  90. # define pj_ansi_sprintf sprintf
  91. #endif
  92. #if defined(PJ_HAS_NO_SNPRINTF) && PJ_HAS_NO_SNPRINTF != 0
  93. # include <pj/types.h>
  94. # include <pj/compat/stdarg.h>
  95. PJ_BEGIN_DECL
  96. PJ_DECL(int) snprintf(char*s1, pj_size_t len, const char*s2, ...);
  97. PJ_DECL(int) vsnprintf(char*s1, pj_size_t len, const char*s2, va_list arg);
  98. PJ_END_DECL
  99. #endif
  100. #define pj_ansi_snprintf snprintf
  101. #if defined(PJ_BAN_VSPRINTF) && PJ_BAN_VSPRINTF
  102. /* Use pj_ansi_vsnprintf() instead */
  103. # define vsprintf error__vsprintf_is_banned
  104. # define pj_ansi_vsprintf error__vsprintf_is_banned
  105. #else
  106. # define pj_ansi_vsprintf vsprintf
  107. #endif
  108. #define pj_ansi_vsnprintf vsnprintf
  109. #define pj_unicode_strcmp wcscmp
  110. #define pj_unicode_strncmp wcsncmp
  111. #define pj_unicode_strlen wcslen
  112. #define pj_unicode_strcpy wcscpy
  113. #define pj_unicode_strncpy wcsncpy
  114. #define pj_unicode_strcat wcscat
  115. #define pj_unicode_strstr wcsstr
  116. #define pj_unicode_strchr wcschr
  117. #define pj_unicode_strcasecmp wcsicmp
  118. #define pj_unicode_stricmp wcsicmp
  119. #define pj_unicode_strncasecmp wcsnicmp
  120. #define pj_unicode_strnicmp wcsnicmp
  121. #define pj_unicode_sprintf swprintf
  122. #define pj_unicode_snprintf snwprintf
  123. #define pj_unicode_vsprintf vswprintf
  124. #define pj_unicode_vsnprintf vsnwprintf
  125. #if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
  126. # define pj_native_strcmp pj_unicode_strcmp
  127. # define pj_native_strncmp pj_unicode_strncmp
  128. # define pj_native_strlen pj_unicode_strlen
  129. # define pj_native_strcpy pj_unicode_strcpy
  130. # define pj_native_strncpy pj_unicode_strncpy
  131. # define pj_native_strcat pj_unicode_strcat
  132. # define pj_native_strstr pj_unicode_strstr
  133. # define pj_native_strchr pj_unicode_strchr
  134. # define pj_native_strcasecmp pj_unicode_strcasecmp
  135. # define pj_native_stricmp pj_unicode_stricmp
  136. # define pj_native_strncasecmp pj_unicode_strncasecmp
  137. # define pj_native_strnicmp pj_unicode_strnicmp
  138. # define pj_native_sprintf pj_unicode_sprintf
  139. # define pj_native_snprintf pj_unicode_snprintf
  140. # define pj_native_vsprintf pj_unicode_vsprintf
  141. # define pj_native_vsnprintf pj_unicode_vsnprintf
  142. #else
  143. # define pj_native_strcmp pj_ansi_strcmp
  144. # define pj_native_strncmp pj_ansi_strncmp
  145. # define pj_native_strlen pj_ansi_strlen
  146. # define pj_native_strcpy pj_ansi_strcpy
  147. # define pj_native_strncpy pj_ansi_strncpy
  148. # define pj_native_strcat pj_ansi_strcat
  149. # define pj_native_strstr pj_ansi_strstr
  150. # define pj_native_strchr pj_ansi_strchr
  151. # define pj_native_strcasecmp pj_ansi_strcasecmp
  152. # define pj_native_stricmp pj_ansi_stricmp
  153. # define pj_native_strncasecmp pj_ansi_strncasecmp
  154. # define pj_native_strnicmp pj_ansi_strnicmp
  155. # define pj_native_sprintf pj_ansi_sprintf
  156. # define pj_native_snprintf pj_ansi_snprintf
  157. # define pj_native_vsprintf pj_ansi_vsprintf
  158. # define pj_native_vsnprintf pj_ansi_vsnprintf
  159. #endif
  160. #endif /* __PJ_COMPAT_STRING_H__ */