ac_tcslen.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. #pragma once
  13. #ifndef _AC_TCSLEN_
  14. #define _AC_TCSLEN_
  15. #if defined ASSERT
  16. #define AcTcsLen_Assert ASSERT
  17. #elif defined(assert)
  18. #define AcTcsLen_Assert assert
  19. #elif defined(_ASSERTE)
  20. #define AcTcsLen_Assert _ASSERTE
  21. #elif defined ATLASSERT
  22. #define AcTcsLen_Assert ATLASSERT
  23. #else
  24. #define AcTcsLen_Assert(x)
  25. #endif
  26. #ifndef USEINTRINSTRLEN
  27. #ifdef _tcslen
  28. #undef _tcslen
  29. #endif
  30. #ifdef UNICODE
  31. #define _tcslen ac_wcslen
  32. #else
  33. #define _tcslen ac_strlen
  34. #endif
  35. #ifdef wcslen
  36. #undef wcslen
  37. #endif
  38. #define wcslen ac_wcslen
  39. #ifdef strlen
  40. #undef strlen
  41. #endif
  42. #define strlen ac_strlen
  43. // use inline to prevent multiple definition errors.
  44. __declspec(noinline) inline unsigned __stdcall ac_wcslen(const wchar_t * s)
  45. {
  46. unsigned n = 0;
  47. while (*s != L'\0') {
  48. s++;
  49. n++;
  50. AcTcsLen_Assert(n < 0x7FFFFFFE); // 2G-1 sanity check
  51. }
  52. return n;
  53. }
  54. __declspec(noinline) inline unsigned __stdcall ac_strlen(const char * s)
  55. {
  56. unsigned n = 0;
  57. while (*s != '\0') {
  58. s++;
  59. n++;
  60. AcTcsLen_Assert(n < 0x7FFFFFFE); // 2G-1 sanity check
  61. }
  62. return n;
  63. }
  64. #else
  65. #ifndef _tcslen
  66. #ifdef UNICODE
  67. #define _tcslen wcslen
  68. #else
  69. #define _tcslen strlen
  70. #endif
  71. #endif //_tcslen
  72. #endif //USEINTRINSTRLEN
  73. #endif //_AC_TCSLEN_