obs-nix.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, struct dstr * output)
  21. {
  22. dstr_copy(output, path);
  23. dstr_cat(output, data);
  24. blog(LOG_INFO, "Attempting path: %s\n", output->array);
  25. return access(output->array, R_OK) == 0;
  26. }
  27. static inline bool check_lib_path(const char* data, const char *path, struct dstr *output)
  28. {
  29. bool result = false;
  30. struct dstr tmp;
  31. dstr_init_copy(&tmp, "lib");
  32. dstr_cat(&tmp, data);
  33. dstr_cat(&tmp, ".so");
  34. result = check_path(tmp.array, path, output);
  35. dstr_free(&tmp);
  36. return result;
  37. }
  38. /*
  39. * /usr/local/lib/obs-plugins
  40. * /usr/lib/obs-plugins
  41. */
  42. char *find_plugin(const char *plugin)
  43. {
  44. struct dstr output;
  45. dstr_init(&output);
  46. if (check_lib_path(plugin, "obs-plugins/", &output))
  47. return output.array;
  48. if (check_lib_path(plugin, OBS_INSTALL_PREFIX "lib/obs-plugins", &output))
  49. return output.array;
  50. dstr_free(&output);
  51. return NULL;
  52. }
  53. /*
  54. * /usr/local/share/libobs
  55. * /usr/share/libobs
  56. */
  57. char *find_libobs_data_file(const char *file)
  58. {
  59. struct dstr output;
  60. dstr_init(&output);
  61. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  62. return output.array;
  63. if (check_path(file, OBS_INSTALL_PREFIX OBS_DATA_PATH "/libobs/", &output))
  64. return output.array;
  65. dstr_free(&output);
  66. return NULL;
  67. }
  68. /*
  69. * /usr/local/share/obs-plugins
  70. * /usr/share/obs-plugins
  71. */
  72. char *obs_find_plugin_file(const char *file)
  73. {
  74. struct dstr output;
  75. dstr_init(&output);
  76. if (check_path(file, OBS_DATA_PATH "/obs-plugins/", &output))
  77. return output.array;
  78. if (check_path(file, OBS_INSTALL_PREFIX OBS_DATA_PATH "/obs-plugins/", &output))
  79. return output.array;
  80. dstr_free(&output);
  81. return NULL;
  82. }