obs-nix.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. {
  50. if (check_lib_path(plugin, "../../obs-plugins/32bit/", &output))
  51. return output.array;
  52. }
  53. else
  54. {
  55. if (check_lib_path(plugin, "../../obs-plugins/64bit/", &output))
  56. return output.array;
  57. }
  58. if (OBS_INSTALL_PREFIX [0] != 0)
  59. {
  60. if (check_lib_path(plugin,
  61. OBS_INSTALL_PREFIX "lib/obs-plugins/",
  62. &output))
  63. return output.array;
  64. }
  65. dstr_free(&output);
  66. return NULL;
  67. }
  68. /*
  69. * /usr/local/share/libobs
  70. * /usr/share/libobs
  71. */
  72. char *find_libobs_data_file(const char *file)
  73. {
  74. struct dstr output;
  75. dstr_init(&output);
  76. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  77. return output.array;
  78. if (OBS_INSTALL_PREFIX [0] != 0)
  79. {
  80. if (check_path(file, OBS_INSTALL_DATA_PATH "/libobs/",
  81. &output))
  82. return output.array;
  83. }
  84. dstr_free(&output);
  85. return NULL;
  86. }
  87. /*
  88. * /usr/local/share/obs-plugins
  89. * /usr/share/obs-plugins
  90. */
  91. char *obs_find_plugin_file(const char *file)
  92. {
  93. struct dstr output;
  94. dstr_init(&output);
  95. if (check_path(file, OBS_DATA_PATH "/obs-plugins/", &output))
  96. return output.array;
  97. if (OBS_INSTALL_PREFIX [0] != 0)
  98. {
  99. if (check_path(file, OBS_INSTALL_DATA_PATH "/obs-plugins/",
  100. &output))
  101. return output.array;
  102. }
  103. dstr_free(&output);
  104. return NULL;
  105. }