예제 #1
0
파일: SpawnUnix.cpp 프로젝트: Agilack/vle
    bool initchild(const std::string& exe,
                   std::vector < std::string > args)
    {

        ::dup2(m_pipeout[1], STDOUT_FILENO);
        ::dup2(m_pipeerr[1], STDERR_FILENO);

        ::close(m_pipeout[1]);
        ::close(m_pipeerr[1]);
        ::close(m_pipeout[0]);
        ::close(m_pipeerr[0]);

        args.insert(args.begin(), exe);

        char **localenvp = prepare_environment_variable();
        char **localargv = convert_string_str_array(args);

        ::execve(exe.c_str(), localargv, localenvp);

        free_str_array(localargv);
        free_str_array(localenvp);
        std::abort();

        return false;
    }
예제 #2
0
static void gp_service_free(struct gp_service *svc)
{
    free(svc->name);
    if (svc->mechs & GP_CRED_KRB5) {
        free(svc->krb5.principal);
        free_str_array(&(svc->krb5.cred_store),
                       &svc->krb5.cred_count);
    }
    gp_free_creds_handle(&svc->creds_handle);
    SELINUX_context_free(svc->selinux_ctx);
    memset(svc, 0, sizeof(struct gp_service));
}
int main(void)
{
  NTree *tree;
  char **array;

  tree = NULL;
  ntree_insert(&tree, NULL, "/");

  ntree_insert(&tree, (array = string_split("/", ' ')), "tmp");
  free_str_array(array);
  
  ntree_print(tree);
  ntree_free(tree);
  return (0);
}
예제 #4
0
파일: Compress.cpp 프로젝트: rousse/vle
static void create_archive(const char *filepath, const char *tarfile)
{
    struct archive *a;
    struct archive_entry *entry;
    struct stat st;
    char buff[8192];
    int len;
    int fd;
    char **filenames, **filename;

    filenames = list_filenames(filepath);
    filename = filenames;

    a = archive_write_new();
    archive_write_set_compression_bzip2(a);
    archive_write_set_format_ustar(a);
    archive_write_open_filename(a, tarfile);
    while (*filename) {
	stat(*filename, &st);
	entry = archive_entry_new();
	archive_entry_set_pathname(entry, *filename);
	archive_entry_set_size(entry, st.st_size);
	archive_entry_set_filetype(entry, AE_IFREG);
	archive_entry_set_perm(entry, 0644);
	archive_write_header(a, entry);
	fd = open(*filename, O_RDONLY);
	len = read(fd, buff, sizeof(buff));
	while ( len > 0 ) {
	    archive_write_data(a, buff, len);
	    len = read(fd, buff, sizeof(buff));
	}
	close(fd);
	archive_entry_free(entry);
	filename++;
    }

    free_str_array(filenames);
    archive_write_close(a);
#if ARCHIVE_VERSION_NUMBER < 4000000
    archive_write_finish(a);
#else
    archive_write_free(a);
#endif
}
예제 #5
0
int track_info_matches(struct track_info *ti, const char *text, unsigned int flags)
{
	const char *artist = comments_get_val(ti->comments, "artist");
	const char *album = comments_get_val(ti->comments, "album");
	const char *title = comments_get_val(ti->comments, "title");
	char **words;
	int i, matched = 1;

	words = get_words(text);
	if (words[0] == NULL)
		matched = 0;
	for (i = 0; words[i]; i++) {
		const char *word = words[i];

		if ((flags & TI_MATCH_ARTIST && artist) ||
		    (flags & TI_MATCH_ALBUM && album) ||
		    (flags & TI_MATCH_TITLE && title)) {
			if (flags & TI_MATCH_ARTIST && artist && u_strcasestr(artist, word))
				continue;
			if (flags & TI_MATCH_ALBUM && album && u_strcasestr(album, word))
				continue;
			if (flags & TI_MATCH_TITLE && title && u_strcasestr(title, word))
				continue;
		} else {
			/* compare with url or filename without path */
			char *filename = ti->filename;

			if (!is_url(filename)) {
				char *slash = strrchr(ti->filename, '/');
				if (slash)
					filename = slash + 1;
			}
			if (u_strcasestr_filename(filename, word))
				continue;
		}
		matched = 0;
		break;
	}
	free_str_array(words);
	return matched;
}
/**
 * list_dir - Recursively goes through all the folders
 * @dir_name: path
 * @len: length of original path
 * @tree: path to ntree 
 * Description: Puts all file/folder names to an ntree
 */
void list_dir (char * dir_name, int len, NTree **tree)
{
	DIR * d;
	d = opendir (dir_name);
	while (1)
	{
		char **array;
		struct dirent * entry;
		char * d_name;
		entry = readdir (d);
		if (! entry)
		{
			break;
		}
		d_name = entry->d_name;
		if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0)
		{ 
			continue;
		}
		filter_it(dir_name+len);
		ntree_insert(tree, (array = string_split(dir_name, ' ')), d_name);
		free_str_array(array);
		filter_back(dir_name+len);
		if (entry->d_type & DT_DIR)
		{
			if (strcmp(d_name, "..")!=0 && strcmp(d_name, ".")!=0)
			{
				char *path;
				path = string_concat(dir_name, '/', d_name);
				list_dir (path, len, tree);
				free(path);
			}
		}
	}
	closedir (d);
}