cs_os.c 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * cs_str.c
  3. * Copyright (c) 2007-2018 ls
  4. **/
  5. #include "../inc/cs.h"
  6. #include "../inc/cs_os.h"
  7. CS_API cs_int_t cs_os_pagesize() {
  8. static cs_int_t __os_pagesize = -1;
  9. if (__os_pagesize == -1) {
  10. #ifdef _WIN32
  11. SYSTEM_INFO si;
  12. GetSystemInfo(&si);
  13. __os_pagesize = (cs_int_t)si.dwPageSize;
  14. #else
  15. __os_pagesize = getpagesize();
  16. #endif
  17. }
  18. return (__os_pagesize);
  19. }
  20. CS_API cs_uint_t cs_os_cpu_count() {
  21. static cs_uint_t __os_cpu_num = 0;
  22. if (__os_cpu_num == 0) {
  23. #ifdef _WIN32
  24. SYSTEM_INFO si;
  25. GetSystemInfo(&si);
  26. __os_cpu_num = (cs_uint_t)si.dwNumberOfProcessors;
  27. #endif
  28. }
  29. return(__os_cpu_num);
  30. }
  31. #ifdef _WIN32
  32. CS_API cs_int_t cs_os_is_winnt() {
  33. static cs_int_t __os_type = -1;
  34. /*
  35. * The value of __os_type is computed only once, and cached to
  36. * avoid the overhead of repeated calls to GetVersion().
  37. */
  38. if (__os_type == -1) {
  39. if ((GetVersion() & 0x80000000) == 0) {
  40. __os_type = 1;
  41. } else {
  42. __os_type = 0;
  43. }
  44. }
  45. return (__os_type);
  46. }
  47. #endif