Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.7 KiB

  1. #ifndef _STR_UTIL_H_
  2. #define _STR_UTIL_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #pragma warning(disable :4706) //4706 "�������̔��r�l�͑����̌��ʂɂȂ��Ă��܂�"
  7. //----------------------------------------------------------------
  8. //ANSI version string utility
  9. //----------------------------------------------------------------
  10. #define StrlenW lstrlenW
  11. #define StrlenA lstrlenA
  12. #define StrcpyA lstrcpyA
  13. #define StrcatA lstrcatA
  14. #define StrcmpA lstrcmp
  15. inline int __cdecl StrncmpA(const char * first,
  16. const char * last,
  17. unsigned int count)
  18. {
  19. if (!count)
  20. return(0);
  21. while (--count && *first && *first == *last) {
  22. first++;
  23. last++;
  24. }
  25. return *(unsigned char *)first - *(unsigned char *)last;
  26. }
  27. inline char * __cdecl StrncpyA(char * dest, const char * source, unsigned int count)
  28. {
  29. char *start = dest;
  30. while (count && (*dest++ = *source++)) /* copy string */
  31. count--;
  32. if (count) /* pad out with zeroes */
  33. while (--count)
  34. *dest++ = '\0';
  35. return(start);
  36. }
  37. inline char * __cdecl StrchrA(const char * string, int ch)
  38. {
  39. while (*string && *string != (char)ch)
  40. string++;
  41. if (*string == (char)ch)
  42. return((char *)string);
  43. return NULL;
  44. }
  45. //----------------------------------------------------------------
  46. //Unicode version string utility
  47. //----------------------------------------------------------------
  48. inline WCHAR * __cdecl StrchrW(const WCHAR * string, int ch)
  49. {
  50. while (*string && *string != (WCHAR)ch)
  51. string++;
  52. if (*string == (WCHAR)ch)
  53. return((WCHAR *)string);
  54. return NULL;
  55. }
  56. inline int __cdecl StrncmpW(const WCHAR * first,
  57. const WCHAR * last,
  58. unsigned int count)
  59. {
  60. if (!count)
  61. return(0);
  62. while (--count && *first && *first == *last) {
  63. first++;
  64. last++;
  65. }
  66. return *first - *last;
  67. }
  68. inline int __cdecl StrcmpW(const WCHAR * first, const WCHAR * last)
  69. {
  70. for (; *first && *last && (*first == *last); first++, last++);
  71. return (*first - *last);
  72. }
  73. inline WCHAR * __cdecl StrcpyW(WCHAR * dest, const WCHAR * source)
  74. {
  75. WCHAR *start = dest;
  76. while (*dest++ = *source++);
  77. return(start);
  78. }
  79. inline WCHAR * __cdecl StrncpyW(WCHAR * dest,
  80. const WCHAR * source,
  81. unsigned int count)
  82. {
  83. WCHAR *start = dest;
  84. while (count && (*dest++ = *source++)) /* copy string */
  85. count--;
  86. if (count) /* pad out with zeroes */
  87. while (--count)
  88. *dest++ = 0;
  89. return(start);
  90. }
  91. inline WCHAR * __cdecl StrcatW(WCHAR * dest, const WCHAR * source)
  92. {
  93. WCHAR *start = dest;
  94. WCHAR *pwch;
  95. for (pwch = dest; *pwch; pwch++);
  96. while (*pwch++ = *source++);
  97. return(start);
  98. }
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif //_STR_UTIL_H_