本文整理汇总了C++中wordfree函数的典型用法代码示例。如果您正苦于以下问题:C++ wordfree函数的具体用法?C++ wordfree怎么用?C++ wordfree使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wordfree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wordexp
const char *az_get_app_data_directory(void) {
static char path_buffer[PATH_MAX];
if (path_buffer[0] == '\0') {
// First, do tilde-expansion so we get a path in the user's homedir.
wordexp_t words;
wordexp("~/.azimuth-game", &words, 0);
if (words.we_wordc < 1) {
wordfree(&words);
return NULL;
}
strncpy(path_buffer, words.we_wordv[0], sizeof(path_buffer) - 1);
wordfree(&words);
struct stat stat_buffer;
// Try to stat the desired path.
if (stat(path_buffer, &stat_buffer) == 0) {
// If the path exists but isn't a directory, we fail.
if (!S_ISDIR(stat_buffer.st_mode)) {
path_buffer[0] = '\0';
return NULL;
}
}
// If the directory doesn't exist, try to create it. If we can't create
// it, or if stat failed for some other reason, we fail.
else if (errno != ENOENT || mkdir(path_buffer, 0700) != 0) {
path_buffer[0] = '\0';
return NULL;
}
}
return path_buffer;
}
示例2: read_repopaths
static int
read_repopaths(char **md_repo, char **md_primary_xml, char **md_filelists,
char **md_repo_updates, char **md_primary_updates_xml,
char **md_filelists_updates)
{
wordexp_t word_vector;
*md_repo = *md_primary_xml = *md_filelists = *md_repo_updates = \
*md_primary_updates_xml = *md_filelists_updates = NULL;
if (wordexp(CFG_FILE, &word_vector, 0))
return 1;
if (word_vector.we_wordc < 1) {
wordfree(&word_vector);
return 1;
}
const char *cfgpath = word_vector.we_wordv[0];
FILE *f = fopen(cfgpath, "r");
if (!f) {
wordfree(&word_vector);
return 1;
}
size_t size = 0;
if ((getline(md_repo, &size, f) < 0) ||
(getline(md_primary_xml, &size, f) < 0) ||
(getline(md_filelists, &size, f) < 0) ||
(getline(md_repo_updates, &size, f) < 0) ||
(getline(md_primary_updates_xml, &size, f) < 0) ||
(getline(md_filelists_updates, &size, f) < 0)) {
free(*md_repo);
free(*md_primary_xml);
free(*md_filelists);
free(*md_repo_updates);
free(*md_primary_updates_xml);
free(*md_filelists_updates);
fclose(f);
wordfree(&word_vector);
return 1;
}
fclose(f);
wordfree(&word_vector);
rtrim(*md_repo);
rtrim(*md_primary_xml);
rtrim(*md_filelists);
rtrim(*md_repo_updates);
rtrim(*md_primary_updates_xml);
rtrim(*md_filelists_updates);
return 0;
}
示例3: glob_for_cachedir
static int
glob_for_cachedir(char *path)
{
int ret = 1;
if (!str_endswith(path, "XXXXXX"))
return ret;
wordexp_t word_vector;
char *p = solv_strdup(path);
const int len = strlen(p);
struct stat s;
ret = 2;
p[len-6] = '*';
p[len-5] = '\0';
if (wordexp(p, &word_vector, 0)) {
solv_free(p);
return ret;
}
for (int i = 0; i < word_vector.we_wordc; ++i) {
char *entry = word_vector.we_wordv[i];
if (stat(entry, &s))
continue;
if (S_ISDIR(s.st_mode) &&
s.st_uid == getuid()) {
assert(strlen(path) == strlen(entry));
strcpy(path, entry);
ret = 0;
break;
}
}
wordfree(&word_vector);
solv_free(p);
return ret;
}
示例4: ExpandEnvironmentStrings
std::string DataDirLocater::SubstEnvVars(const std::string& in) const
{
std::string out;
#ifdef _WIN32
const size_t maxSize = 32 * 1024;
char out_c[maxSize];
ExpandEnvironmentStrings(in.c_str(), out_c, maxSize); // expands %HOME% etc.
out = out_c;
#else
std::string previous = in;
for (int i = 0; i < 10; ++i) { // repeat substitution till we got a pure absolute path
wordexp_t pwordexp;
int r = wordexp(previous.c_str(), &pwordexp, WRDE_NOCMD); // expands $FOO, ${FOO}, ${FOO-DEF} ~/, etc.
if (r == EXIT_SUCCESS) {
if (pwordexp.we_wordc > 0) {
out = pwordexp.we_wordv[0];;
for (unsigned int w = 1; w < pwordexp.we_wordc; ++w) {
out += " ";
out += pwordexp.we_wordv[w];
}
}
wordfree(&pwordexp);
} else {
out = in;
}
if (previous == out) {
break;
}
previous.swap(out);
}
#endif
return out;
}
示例5: do_wordexp
static char*
do_wordexp (const char *path)
{
#ifdef HAVE_WORDEXP_H
wordexp_t wexp;
char *dir;
if (!path) {
/* g_debug ("%s: path is empty", __FUNCTION__); */
return NULL;
}
if (wordexp (path, &wexp, 0) != 0) {
/* g_debug ("%s: expansion failed for %s", __FUNCTION__, path); */
return NULL;
}
/* we just pick the first one */
dir = g_strdup (wexp.we_wordv[0]);
/* strangely, below seems to lead to a crash on MacOS (BSD);
so we have to allow for a tiny leak here on that
platform... maybe instead of __APPLE__ it should be
__BSD__?*/
#ifndef __APPLE__
wordfree (&wexp);
#endif /*__APPLE__*/
return dir;
# else /*!HAVE_WORDEXP_H*/
/* E.g. OpenBSD does not have wordexp.h, so we ignore it */
return path ? g_strdup (path) : NULL;
#endif /*HAVE_WORDEXP_H*/
}
示例6: _ifparser_source
static void
_ifparser_source (const char *path, const char *en_dir, int quiet)
{
char *abs_path;
wordexp_t we;
uint i;
if (g_path_is_absolute (path))
abs_path = g_strdup (path);
else
abs_path = g_build_filename (en_dir, path, NULL);
if (!quiet)
nm_log_info (LOGD_SETTINGS, " interface-parser: source line includes interfaces file(s) %s\n", abs_path);
/* ifupdown uses WRDE_NOCMD for wordexp. */
if (wordexp (abs_path, &we, WRDE_NOCMD)) {
if (!quiet)
nm_log_warn (LOGD_SETTINGS, "word expansion for %s failed\n", abs_path);
} else {
for (i = 0; i < we.we_wordc; i++)
_recursive_ifparser (we.we_wordv[i], quiet);
wordfree (&we);
}
g_free (abs_path);
}
示例7: xdg_open_selection_cb
static void
xdg_open_selection_cb (GtkClipboard *clipboard, const char *string, gpointer data)
{
char *command;
wordexp_t result;
gboolean spawn;
GError *spawn_error = NULL;
command = g_strconcat ("xdg-open ", string, NULL);
switch (wordexp (command, &result, WRDE_NOCMD)) {
case 0:
break;
case WRDE_BADCHAR:
fprintf (stderr, "'%s' contains an invalid character\n", string);
goto finalize;
case WRDE_CMDSUB:
fprintf (stderr, "'%s' uses command substitution, which is not allowed\n", string);
goto finalize;
case WRDE_NOSPACE:
fprintf (stderr, "Could not allocate enough memory when parsing '%s'\n", string);
goto finalize;
case WRDE_SYNTAX:
fprintf (stderr, "Syntax error in '%s'\n", string);
goto finalize;
}
spawn = g_spawn_async (NULL, result.we_wordv, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, &spawn_error);
if (!spawn) {
fprintf (stderr, "%s\n", spawn_error->message);
g_error_free (spawn_error);
}
finalize:
wordfree (&result);
}
示例8: expandPath
std::string expandPath(const char* file)
{
if (!file)
return "";
std::string f;
size_t size = strlen(file);
f.reserve(size);
for (size_t x=0; x<size; x++)
{
if (file[x] == ' ')
f.push_back('\\');
f.push_back(file[x]);
}
wordexp_t exp_result;
memset(&exp_result, 0, sizeof(wordexp_t));
int res = wordexp(f.c_str(), &exp_result, 0);
if (res != 0)
return "";
std::string r;
if (exp_result.we_wordv[0])
r = exp_result.we_wordv[0];
wordfree(&exp_result);
return r;
}
示例9: getenv
char *swaynag_get_config_path(void) {
static const char *config_paths[] = {
"$HOME/.swaynag/config",
"$XDG_CONFIG_HOME/swaynag/config",
SYSCONFDIR "/swaynag/config",
};
char *config_home = getenv("XDG_CONFIG_HOME");
if (!config_home || config_home[0] == '\0') {
config_paths[1] = "$HOME/.config/swaynag/config";
}
wordexp_t p;
for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) {
if (wordexp(config_paths[i], &p, 0) == 0) {
char *path = strdup(p.we_wordv[0]);
wordfree(&p);
if (file_exists(path)) {
return path;
}
free(path);
}
}
return NULL;
}
示例10: word_expansion
char * word_expansion(char * line)
{
//on traite les caractères spéciaux
char * new_line = replace_char(line, "|");
char * new_line_2 = replace_char(new_line, "<");
char * new_line_3 = replace_char(new_line_2, ">");
char * new_line_4 = replace_char(new_line_3, "&");
wordexp_t result;
wordexp(new_line_4, &result, 0);
free(new_line_4);
int cmd_offset = 0;
//on calcule la longueur de la nouvelle commande
for(int i=0; i<result.we_wordc; i++)
{
cmd_offset += strlen(result.we_wordv[i]);
cmd_offset++; //derrière chaque commande, il y a un espace
}
//cmd_offset--;
char * max_cmd = malloc(sizeof(char)*cmd_offset);
//initialisation à '\0'
for(int i=0; i<cmd_offset; i++)
max_cmd[i] = '\0';
int tmp_cmd_offset = 0;
//on fait la recopie
for(int i=0; tmp_cmd_offset<cmd_offset; i++)
{
strcat(max_cmd, result.we_wordv[i]);
tmp_cmd_offset += (int)strlen(result.we_wordv[i]);
max_cmd[tmp_cmd_offset++] = ' ';
}
max_cmd[cmd_offset] = '\0';
wordfree(&result);
return max_cmd;
}
示例11: assert
g_vector<g_string> PinCmd::getFullCmdArgs(uint32_t procIdx, const char** inputFile) {
assert(procIdx < procInfo.size()); //must be one of the topmost processes
g_vector<g_string> res = getPinCmdArgs(procIdx);
g_string cmd = procInfo[procIdx].cmd;
/* Loader injection: Turns out that Pin mingles with the simulated binary, which decides the loader used,
* even when PIN_VM_LIBRARY_PATH is used. This kill the invariance on libzsim.so's loaded address, because
* loaders in different children have different sizes. So, if specified, we prefix the program with the
* given loader. This is optional because it won't work with statically linked binaries.
*
* BTW, thinking of running pin under a specific loaderto fix this instead? Nope, it gets into an infinite loop.
*/
if (procInfo[procIdx].loader != "") {
cmd = procInfo[procIdx].loader + " " + cmd;
info("Injected loader on process%d, command line: %s", procIdx, cmd.c_str());
warn("Loader injection makes Pin unaware of symbol routines, so things like routine patching"
"will not work! You can homogeneize the loaders instead by editing the .interp ELF section");
}
//Parse command -- use glibc's wordexp to parse things like quotes, handle argument expansion, etc correctly
wordexp_t p;
wordexp(cmd.c_str(), &p, 0);
for (uint32_t i = 0; i < p.we_wordc; i++) {
res.push_back(g_string(p.we_wordv[i]));
}
wordfree(&p);
//Input redirect
*inputFile = (procInfo[procIdx].input == "")? nullptr : procInfo[procIdx].input.c_str();
return res;
}
示例12: wordexp
std::string ConfigurationManager::retrieveAsPath(std::string namespaceName, std::string identifier, std::string defaultValue)
{
std::string result = defaultValue;
EntriesMap::const_iterator iter = entries->find(std::make_pair(namespaceName, identifier));
if(iter != entries->end())
{
wordexp_t expansion;
int expansionResult = 0;
expansionResult = wordexp(iter->second.c_str(), &expansion, WRDE_NOCMD);
if(expansionResult == 0 && expansion.we_wordc > 0)
{
result.clear();
for(int i=0;i<expansion.we_wordc;i++)
{
result += expansion.we_wordv[i];
}
}
wordfree(&expansion);
if(result[0] != '/') // relative path, need to prefix with workingDir
{
result = workingDir + result;
}
}
return result;
}
示例13: mame_expand_string
static void
mame_expand_string (gchar **p_string)
{
#if HAVE_WORDEXP_H
wordexp_t words;
g_return_if_fail (p_string != NULL);
g_return_if_fail (*p_string != NULL);
/* MAME configurations often use shell variables like $HOME
* in its search and output paths, so we need to expand them. */
if (wordexp (*p_string, &words, WRDE_NOCMD) == 0)
{
GString *buffer;
gsize ii;
buffer = g_string_sized_new (strlen (*p_string));
for (ii = 0; ii < words.we_wordc; ii++)
{
if (ii > 0)
g_string_append_c (buffer, ' ');
g_string_append (buffer, words.we_wordv[ii]);
}
g_free (*p_string);
*p_string = g_string_free (buffer, FALSE);
wordfree (&words);
}
#endif
}
示例14: Process
void Process(const char * i_lpszType, const char ** i_lpszCol_Names)
{
XDATASET cFile;
XDATASET cCombined;
wordexp_t cResults;
char lpszSearchFile[64];
char lpszOutputFile[64];
unsigned int uiColors[8][2] =
{
{2,4}, // u - v
{2,3}, // u - b
{3,4}, // b - v
{7,5}, // uvm2 - uvw1
{6,5}, // uvw2 - uvw1
{7,4}, // uvm2 - v
{6,4}, // uw2 - v
{5,4} // uw1 - v
};
sprintf(lpszSearchFile,"*%s*photometry.csv",i_lpszType);
sprintf(lpszOutputFile,"%s_photometry.csv",i_lpszType);
if (wordexp(lpszSearchFile,&cResults,WRDE_NOCMD|WRDE_UNDEF) == 0)
{
if (cResults.we_wordc > 0)
{
printf("Count %i\n",cResults.we_wordc);
unsigned int uiCount = cResults.we_wordc;
for (unsigned int uiI = 0; uiI < cResults.we_wordc; uiI++)
if (strcmp(cResults.we_wordv[uiI],lpszOutputFile) == 0)
uiCount--;
if (uiCount > 0)
cCombined.Allocate(17,uiCount);
uiCount = 0;
for (unsigned int uiI = 0; uiI < cResults.we_wordc; uiI++)
{
if (strcmp(cResults.we_wordv[uiI],lpszOutputFile) != 0)
{
printf("Reading %s\n",cResults.we_wordv[uiI]);
cFile.ReadDataFile(cResults.we_wordv[uiI],false,false,',',1);
for(unsigned int uiJ = 0; uiJ < 9; uiJ++)
cCombined.SetElement(uiJ,uiCount,cFile.GetElement(uiJ,0));
for (unsigned int uiJ = 0; uiJ < 8; uiJ++)
cCombined.SetElement(9 + uiJ,uiCount,cFile.GetElement(uiColors[uiJ][0],0) - cFile.GetElement(uiColors[uiJ][1],0));
uiCount++;
}
}
if (uiCount > 0)
cCombined.SaveDataFileCSV(lpszOutputFile,i_lpszCol_Names);
wordfree(&cResults);
}
}
}
示例15: expansion_demo
static void expansion_demo(char const *str)
{
printf("Before expansion: %s\n", str);
wordexp_t exp;
wordexp(str, &exp, 0);
printf("After expansion: %s\n", exp.we_wordv[0]);
wordfree(&exp);
}