crn_platform.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // File: crn_platform.cpp
  2. // See Copyright Notice and license at the end of inc/crnlib.h
  3. #include "crn_core.h"
  4. #if CRNLIB_USE_WIN32_API
  5. #include "crn_winhdr.h"
  6. #endif
  7. #ifndef _MSC_VER
  8. int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...)
  9. {
  10. if (!sizeOfBuffer)
  11. return 0;
  12. va_list args;
  13. va_start(args, format);
  14. int c = vsnprintf(buffer, sizeOfBuffer, format, args);
  15. va_end(args);
  16. buffer[sizeOfBuffer - 1] = '\0';
  17. if (c < 0)
  18. return sizeOfBuffer - 1;
  19. return CRNLIB_MIN(c, (int)sizeOfBuffer - 1);
  20. }
  21. int vsprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, va_list args)
  22. {
  23. if (!sizeOfBuffer)
  24. return 0;
  25. int c = vsnprintf(buffer, sizeOfBuffer, format, args);
  26. buffer[sizeOfBuffer - 1] = '\0';
  27. if (c < 0)
  28. return sizeOfBuffer - 1;
  29. return CRNLIB_MIN(c, (int)sizeOfBuffer - 1);
  30. }
  31. char* strlwr(char* p)
  32. {
  33. char *q = p;
  34. while (*q)
  35. {
  36. char c = *q;
  37. *q++ = tolower(c);
  38. }
  39. return p;
  40. }
  41. char* strupr(char *p)
  42. {
  43. char *q = p;
  44. while (*q)
  45. {
  46. char c = *q;
  47. *q++ = toupper(c);
  48. }
  49. return p;
  50. }
  51. #endif // __GNUC__
  52. void crnlib_debug_break(void)
  53. {
  54. CRNLIB_BREAKPOINT
  55. }
  56. #if CRNLIB_USE_WIN32_API
  57. #include "crn_winhdr.h"
  58. bool crnlib_is_debugger_present(void)
  59. {
  60. return IsDebuggerPresent() != 0;
  61. }
  62. void crnlib_output_debug_string(const char* p)
  63. {
  64. OutputDebugStringA(p);
  65. }
  66. #else
  67. bool crnlib_is_debugger_present(void)
  68. {
  69. return false;
  70. }
  71. void crnlib_output_debug_string(const char* p)
  72. {
  73. puts(p);
  74. }
  75. #endif // CRNLIB_USE_WIN32_API