obs-nix.c 2.6 KB

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