WinAdapter.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //===-- WinAdapter.cpp - Windows Adapter for other platforms ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _WIN32
  10. #include "dxc/Support/WinAdapter.h"
  11. #include "dxc/Support/WinFunctions.h"
  12. DEFINE_CROSS_PLATFORM_UUIDOF(IUnknown)
  13. DEFINE_CROSS_PLATFORM_UUIDOF(INoMarshal)
  14. DEFINE_CROSS_PLATFORM_UUIDOF(IStream)
  15. DEFINE_CROSS_PLATFORM_UUIDOF(ISequentialStream)
  16. //===--------------------------- IUnknown ---------------------------------===//
  17. ULONG IUnknown::AddRef() {
  18. ++m_count;
  19. return m_count;
  20. }
  21. ULONG IUnknown::Release() {
  22. ULONG result = --m_count;
  23. if (m_count == 0) {
  24. delete this;
  25. }
  26. return result;
  27. }
  28. IUnknown::~IUnknown() {}
  29. //===--------------------------- IMalloc ----------------------------------===//
  30. void *IMalloc::Alloc(size_t size) { return malloc(size); }
  31. void *IMalloc::Realloc(void *ptr, size_t size) { return realloc(ptr, size); }
  32. void IMalloc::Free(void *ptr) { free(ptr); }
  33. HRESULT IMalloc::QueryInterface(REFIID riid, void **ppvObject) {
  34. assert(false && "QueryInterface not implemented for IMalloc.");
  35. return E_NOINTERFACE;
  36. }
  37. //===--------------------------- CAllocator -------------------------------===//
  38. void *CAllocator::Reallocate(void *p, size_t nBytes) throw() {
  39. return realloc(p, nBytes);
  40. }
  41. void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); }
  42. void CAllocator::Free(void *p) throw() { free(p); }
  43. //===---------------------- Char converstion ------------------------------===//
  44. const char *CPToLocale(uint32_t CodePage) {
  45. #ifdef __APPLE__
  46. static const char *utf8 = "en_US.UTF-8";
  47. static const char *iso88591 = "en_US.ISO8859-1";
  48. #else
  49. static const char *utf8 = "en_US.utf8";
  50. static const char *iso88591 = "en_US.iso88591";
  51. #endif
  52. if (CodePage == CP_UTF8) {
  53. return utf8;
  54. } else if (CodePage == CP_ACP) {
  55. // Experimentation suggests that ACP is expected to be ISO-8859-1
  56. return iso88591;
  57. }
  58. return nullptr;
  59. }
  60. //===--------------------------- CHandle -------------------------------===//
  61. CHandle::CHandle(HANDLE h) { m_h = h; }
  62. CHandle::~CHandle() { CloseHandle(m_h); }
  63. CHandle::operator HANDLE() const throw() { return m_h; }
  64. #endif