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