obs-nix.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 (check_lib_path(plugin, "obs-plugins/", &output))
  49. return output.array;
  50. if (check_lib_path(plugin, OBS_INSTALL_PREFIX "lib/obs-plugins",
  51. &output))
  52. return output.array;
  53. dstr_free(&output);
  54. return NULL;
  55. }
  56. /*
  57. * /usr/local/share/libobs
  58. * /usr/share/libobs
  59. */
  60. char *find_libobs_data_file(const char *file)
  61. {
  62. struct dstr output;
  63. dstr_init(&output);
  64. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  65. return output.array;
  66. if (check_path(file, OBS_INSTALL_PREFIX OBS_DATA_PATH "/libobs/",
  67. &output))
  68. return output.array;
  69. dstr_free(&output);
  70. return NULL;
  71. }
  72. /*
  73. * /usr/local/share/obs-plugins
  74. * /usr/share/obs-plugins
  75. */
  76. char *obs_find_plugin_file(const char *file)
  77. {
  78. struct dstr output;
  79. dstr_init(&output);
  80. if (check_path(file, OBS_DATA_PATH "/obs-plugins/", &output))
  81. return output.array;
  82. if (check_path(file, OBS_INSTALL_PREFIX OBS_DATA_PATH "/obs-plugins/",
  83. &output))
  84. return output.array;
  85. dstr_free(&output);
  86. return NULL;
  87. }