You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #pragma once
  18. /* On mingw stdio functions like printf are not inline, and thus get defined every time they are used.
  19. * Its <cstdio> also does `#undef printf` which invalidates our macros :(
  20. * We go through a few steps to ensure unique symbol names.
  21. */
  22. #ifdef STDIO_OVERRIDE
  23. // helper macros
  24. # define STDIO_OVERRIDE_HELPER(NS, SEP, FN) NS ## SEP ## FN
  25. # define STDIO_OVERRIDE_MACRO(NS, FN) STDIO_OVERRIDE_HELPER(NS, _, FN)
  26. // step 1: prefix the needed stdio functions
  27. # define printf STDIO_OVERRIDE_MACRO(STDIO_OVERRIDE, printf)
  28. // step 2: inlude <stdio.h> which will use our prefixed names
  29. # include <stdio.h>
  30. // step 3: undef and define dummy functions required for <cstdio> (it uses `using ::printf` syntax)
  31. # undef printf
  32. static inline void printf() {}
  33. // step 4: we can safely include <cstdio> now
  34. # include_next <cstdio>
  35. // step 5: define the same macros as in step 1
  36. # define printf STDIO_OVERRIDE_MACRO(STDIO_OVERRIDE, printf)
  37. // step 6: place the macro prefixed names in std namespace
  38. /*
  39. namespace std {
  40. using ::printf;
  41. }
  42. */
  43. #else // STDIO_OVERRIDE
  44. // if STDIO_OVERRIDE is not defined, we have nothing to do
  45. # include_next <cstdio>
  46. #endif // STDIO_OVERRIDE