obs-nix.c 2.6 KB
Newer Older
J
jp9000 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/******************************************************************************
    Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include <stdlib.h>
19 20
#include <stdio.h>
#include <unistd.h>
J
jp9000 已提交
21 22 23
#include "util/dstr.h"
#include "obs.h"

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
static inline bool check_path(const char* data, const char *path, struct dstr * output)
{
	dstr_copy(output, path);
	dstr_cat(output, data);
	
    blog(LOG_INFO, "Attempting path: %s\n", output->array);
	
	return access(output->array, R_OK) == 0;
}

static inline bool check_lib_path(const char* data, const char *path, struct dstr *output)
{
	bool result = false;
	struct dstr tmp;
	
    dstr_init_copy(&tmp, "lib");
    dstr_cat(&tmp, data);
	dstr_cat(&tmp, ".so");
	result = check_path(tmp.array, path, output); 
	
	dstr_free(&tmp);
	
	return result;
}

J
jp9000 已提交
49 50 51 52 53
/*
 *   /usr/local/lib/obs-plugins
 *   /usr/lib/obs-plugins
 */
char *find_plugin(const char *plugin)
54 55 56 57 58 59 60 61 62 63 64
{ 
	struct dstr output;
	dstr_init(&output);

	if (check_lib_path(plugin, "/usr/local/lib/obs-plugins/", &output))
		return output.array;

	if (check_lib_path(plugin, "/usr/lib/obs-plugins/", &output))
		return output.array;

	dstr_free(&output);
J
jp9000 已提交
65 66 67 68 69 70 71 72 73
	return NULL;
}

/*
 *   /usr/local/share/libobs
 *   /usr/share/libobs
 */
char *find_libobs_data_file(const char *file)
{
74 75 76 77 78 79 80 81 82 83
	struct dstr output;
		dstr_init(&output);

	if (check_path(file, "/usr/local/share/libobs/", &output))
		return output.array;

	if (check_path(file, "/usr/share/libobs/", &output))
		return output.array;

	dstr_free(&output);
J
jp9000 已提交
84 85 86 87 88 89 90 91
	return NULL;
}

/*
 *   /usr/local/share/obs-plugins
 *   /usr/share/obs-plugins
 */
char *obs_find_plugin_file(const char *file)
92 93 94 95 96 97 98 99 100 101 102 103
{ 	
    struct dstr output;
    dstr_init(&output);

    if (check_path(file, "/usr/local/share/obs-plugins/", &output))
        return output.array;

    if (check_path(file, "/usr/share/obs-plugins", &output))
        return output.array;

    dstr_free(&output);
    return NULL;
J
jp9000 已提交
104
}