Example #1
0
int mlib_getchnlist(struct mlib_listentry_st **result, int *resnum)
{
	glob_t globres;
	char path[PATHSIZE];
	struct mlib_listentry_st *ptr;
	struct channel_context_st *res;
	int i, num;

	for (i = 0; i < MAXCHNID +1; ++i) {
		channel[i].id = -1;
	}

	snprintf(path, PATHSIZE, "%s/*", server_conf.media_dir);

	if (glob(path, 0, NULL, &globres)) {
		return -1;
	}

	ptr = malloc(globres.gl_pathc * sizeof(struct mlib_listentry_st));
	if (ptr == NULL) {
		syslog(LOG_ERR, "malloc(): %m");
		exit(1);
	}

	num = 0;

	for (i = 0; i < globres.gl_pathc; ++i) {
		res = path2entry(globres.gl_pathv[i]);
		if (res) {
			memcpy(channel + res->id, res, sizeof(*res));
			ptr[num].id = res->id;
			ptr[num].desc = strdup(res->desc);

			num++;
		}
	}

	*result = realloc(ptr, num * sizeof(struct mlib_listentry_st));

	*resnum = num;

	return 0;
}
Example #2
0
int mlib_getchnlist(struct mlib_listentry_st **result, int *resnum){
	int i;
	int num = 0;
	char path[PATHSIZE];
	glob_t globres;

	struct mlib_listetry *ptr;
	struct channel_context_st *res;

	for (i = 0; i <MAXCHNID+1; i++) {
		channel[i].chnid = -1;
	}

	//debug
	snprintf(path, PATHSIZE, "%s/*", server_conf.media_dir);

	if (glob(path, 0, NULL, globres)) {
		return -1;
	}

	ptr = malloc(sizeof(struct milb_listetry_st) * globres.gl_pathc);
	if (NULL == ptr) {
		syslog(LOG_ERR, "malloc error");
		exit(0);
	}

	for (i = 0; i < globres.gl_pathc; i++) {
		//globres.pathv[i]--> "/home/ybx/media/ch1"
		path2entry(globres.gl_pathv[i]);
		num++;
	}

	*result = 

	*resnum = num;

	return 0;
}