Quirks.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. {
  29. void *p = malloc(len);
  30. if (p == 0)
  31. {
  32. /* Don't use stdio (e.g. fputs), because that may want to allocate more
  33. * memory.
  34. */
  35. (void) !write(2, "out of memory\n", 14);
  36. abort();
  37. }
  38. return p;
  39. }
  40. extern "C" void emulate_cc_delete(void *p)
  41. {
  42. if (p != 0)
  43. free(p);
  44. }
  45. void *operator new(unsigned len) __attribute__((alias("emulate_cc_new")));
  46. void *operator new[](unsigned len) __attribute__((alias("emulate_cc_new")));
  47. void operator delete(void *p) __attribute__((alias("emulate_cc_delete")));
  48. void operator delete[](void *p) __attribute__((alias("emulate_cc_delete")));
  49. extern "C" void __cxa_pure_virtual()
  50. {
  51. // while (1);
  52. }