obs-nix.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Copyright (C) 2014 by Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include "util/dstr.h"
  19. #include "obs.h"
  20. static inline bool check_path(const char* data, const char *path,
  21. struct dstr * output)
  22. {
  23. dstr_copy(output, path);
  24. dstr_cat(output, data);
  25. blog(LOG_INFO, "Attempting path: %s\n", output->array);
  26. return access(output->array, R_OK) == 0;
  27. }
  28. static inline bool check_lib_path(const char* data, const char *path,
  29. struct dstr *output)
  30. {
  31. bool result = false;
  32. struct dstr tmp;
  33. dstr_init_copy(&tmp, "lib");
  34. dstr_cat(&tmp, data);
  35. dstr_cat(&tmp, ".so");
  36. result = check_path(tmp.array, path, output);
  37. dstr_free(&tmp);
  38. return result;
  39. }
  40. /*
  41. * /usr/local/lib/obs-plugins
  42. * /usr/lib/obs-plugins
  43. */
  44. char *find_plugin(const char *plugin)
  45. {
  46. struct dstr output;
  47. dstr_init(&output);
  48. if(sizeof(void*) == 4) {
  49. if (check_lib_path(plugin, "../../obs-plugins/32bit/", &output))
  50. return output.array;
  51. } else {
  52. if (check_lib_path(plugin, "../../obs-plugins/64bit/", &output))
  53. return output.array;
  54. }
  55. if (OBS_INSTALL_PREFIX [0] != 0) {
  56. if (check_lib_path(plugin,
  57. OBS_INSTALL_PREFIX "lib/obs-plugins/",
  58. &output))
  59. return output.array;
  60. }
  61. dstr_free(&output);
  62. return NULL;
  63. }
  64. /*
  65. * /usr/local/share/libobs
  66. * /usr/share/libobs
  67. */
  68. char *find_libobs_data_file(const char *file)
  69. {
  70. struct dstr output;
  71. dstr_init(&output);
  72. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  73. return output.array;
  74. if (OBS_INSTALL_PREFIX [0] != 0) {
  75. if (check_path(file, OBS_INSTALL_DATA_PATH "/libobs/",
  76. &output))
  77. return output.array;
  78. }
  79. dstr_free(&output);
  80. return NULL;
  81. }
  82. /*
  83. * /usr/local/share/obs-plugins
  84. * /usr/share/obs-plugins
  85. */
  86. char *obs_find_plugin_file(const char *file)
  87. {
  88. struct dstr output;
  89. dstr_init(&output);
  90. if (check_path(file, OBS_DATA_PATH "/obs-plugins/", &output))
  91. return output.array;
  92. if (OBS_INSTALL_PREFIX [0] != 0) {
  93. if (check_path(file, OBS_INSTALL_DATA_PATH "/obs-plugins/",
  94. &output))
  95. return output.array;
  96. }
  97. dstr_free(&output);
  98. return NULL;
  99. }