whereami.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)
  2. #ifndef WHEREAMI_H
  3. #define WHEREAMI_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifndef WAI_FUNCSPEC
  8. #define WAI_FUNCSPEC
  9. #endif
  10. #ifndef WAI_PREFIX
  11. #define WAI_PREFIX(function) wai_##function
  12. #endif
  13. /**
  14. * Returns the path to the current executable.
  15. *
  16. * Usage:
  17. * - first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to
  18. * retrieve the length of the path
  19. * - allocate the destination buffer with `path = (char*)malloc(length + 1);`
  20. * - call `wai_getExecutablePath(path, length, NULL)` again to retrieve the
  21. * path
  22. * - add a terminal NUL character with `path[length] = '\0';`
  23. *
  24. * @param out destination buffer, optional
  25. * @param capacity destination buffer capacity
  26. * @param dirname_length optional recipient for the length of the dirname part
  27. * of the path.
  28. *
  29. * @return the length of the executable path on success (without a terminal NUL
  30. * character), otherwise `-1`
  31. */
  32. WAI_FUNCSPEC
  33. int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length);
  34. /**
  35. * Returns the path to the current module
  36. *
  37. * Usage:
  38. * - first call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve
  39. * the length of the path
  40. * - allocate the destination buffer with `path = (char*)malloc(length + 1);`
  41. * - call `wai_getModulePath(path, length, NULL)` again to retrieve the path
  42. * - add a terminal NUL character with `path[length] = '\0';`
  43. *
  44. * @param out destination buffer, optional
  45. * @param capacity destination buffer capacity
  46. * @param dirname_length optional recipient for the length of the dirname part
  47. * of the path.
  48. *
  49. * @return the length of the module path on success (without a terminal NUL
  50. * character), otherwise `-1`
  51. */
  52. WAI_FUNCSPEC
  53. int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length);
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif // #ifndef WHEREAMI_H