Quirks.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "Quirks.h"
  2. #include <cstddef>
  3. #include <cstring>
  4. #include <memory>
  5. #include "Logger.h"
  6. using namespace WalrusRPG;
  7. void Quirks::init(const char *argv_0)
  8. {
  9. WalrusRPG::Logger::log("Quirks init");
  10. }
  11. void Quirks::deinit()
  12. {
  13. WalrusRPG::Logger::log("Quirks deinit");
  14. }
  15. std::unique_ptr<char> Quirks::solve_absolute_path(const char *path)
  16. {
  17. std::unique_ptr<char> result(new char[strlen(path) + 1]);
  18. strcpy(result.get(), path);
  19. return result;
  20. }
  21. bool Quirks::get_key(keycode_t key)
  22. {
  23. return hidKeysDown() & key;
  24. }
  25. #include <stdlib.h>
  26. #include <unistd.h> /* for write(), also available on Windows */
  27. extern "C" void* emulate_cc_new(unsigned len) { \
  28. void *p = malloc(len);
  29. if (p == 0) {
  30. /* Don't use stdio (e.g. fputs), because that may want to allocate more
  31. * memory.
  32. */
  33. (void)!write(2, "out of memory\n", 14);
  34. abort();
  35. }
  36. return p;
  37. }
  38. extern "C" void emulate_cc_delete(void* p) {
  39. if (p != 0)
  40. free(p);
  41. }
  42. void* operator new (unsigned len) __attribute__((alias("emulate_cc_new")));
  43. void* operator new[](unsigned len) __attribute__((alias("emulate_cc_new")));
  44. void operator delete (void* p) __attribute__((alias("emulate_cc_delete")));
  45. void operator delete[](void* p) __attribute__((alias("emulate_cc_delete")));
  46. extern "C" void __cxa_pure_virtual()
  47. {
  48. //while (1);
  49. }