当前位置: 首页>>代码示例>>C++>>正文


C++ elektraFree函数代码示例

本文整理汇总了C++中elektraFree函数的典型用法代码示例。如果您正苦于以下问题:C++ elektraFree函数的具体用法?C++ elektraFree怎么用?C++ elektraFree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了elektraFree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: nextPackage

static KeySet * nextPackage (FILE * fp, Key * parentKey)
{
	char * line = elektraMalloc (DPKG_LINE_MAX);
	KeySet * package = ksNew (500, KS_END);
	Key * lastKey = NULL;
	Key * baseKey = NULL;
	int notDone = 0;
	while (fgets (line, DPKG_LINE_MAX, fp) != NULL)
	{
		if (*line == '\n') break;
		if (*line == ' ')
		{
			if (strchr (line, '\n'))
				notDone = 0;
			else
				notDone = 1;
			appendToKey (lastKey, line);
		}
		else if (notDone)
		{
			if (strchr (line, '\n')) notDone = 0;
			appendToKey (lastKey, line);
		}
		else
		{
			if (!strchr (line, '\n')) notDone = 1;
			char * section = line;
			char * data = strchr (line, ':');
			if (data) *data = '\0';
			++data;		     // skip :
			++data;		     // skip whitespace
			strtok (data, "\n"); // remove newline
			if (!strcmp (section, "Package"))
			{
				baseKey = keyDup (parentKey);
				keyAddBaseName (baseKey, data);
				lastKey = baseKey;
				ksAppendKey (package, baseKey);
			}
			else
			{
				Key * key = keyDup (baseKey);
				keyAddBaseName (key, section);
				keySetString (key, data);
				lastKey = key;
				ksAppendKey (package, key);
			}
		}
		memset (line, 0, DPKG_LINE_MAX);
	}
	elektraFree (line);
	return package;
}
开发者ID:BernhardDenner,项目名称:libelektra,代码行数:53,代码来源:dpkg.c

示例2: test_resolve

void test_resolve ()
{
	int pathLen = tempHomeLen + 1 + strlen (KDB_DB_USER) + 12 + 1;
	char * path = elektraMalloc (pathLen);
	exit_if_fail (path != 0, "elektraMalloc failed");
	snprintf (path, pathLen, "%s/%s/elektra.ecf", tempHome, KDB_DB_USER);

	printf ("Resolve Filename\n");

	KeySet * modules = ksNew (0, KS_END);
	elektraModulesInit (modules, 0);

	Key * parentKey = keyNew ("system", KEY_END);
	Plugin * plugin = elektraPluginOpen ("resolver", modules, set_pluginconf (), 0);
	exit_if_fail (plugin, "could not load resolver plugin");

	KeySet * test_config = set_pluginconf ();
	KeySet * config = elektraPluginGetConfig (plugin);
	succeed_if (config != 0, "there should be a config");
	compare_keyset (config, test_config);
	ksDel (test_config);

	succeed_if (plugin->kdbOpen != 0, "no open pointer");
	succeed_if (plugin->kdbClose != 0, "no open pointer");
	succeed_if (plugin->kdbGet != 0, "no open pointer");
	succeed_if (plugin->kdbSet != 0, "no open pointer");
	succeed_if (plugin->kdbError != 0, "no open pointer");

	succeed_if (!strncmp (plugin->name, "resolver", strlen ("resolver")), "got wrong name");

	resolverHandles * h = elektraPluginGetData (plugin);
	exit_if_fail (h != 0, "no plugin handle");
	succeed_if_same_string (h->system.path, "elektra.ecf");
	succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
	succeed_if_same_string (h->user.path, "elektra.ecf");
	succeed_if_same_string (h->user.filename, path);
	plugin->kdbClose (plugin, parentKey);

	// reinit with system path only
	plugin->kdbOpen (plugin, parentKey);
	h = elektraPluginGetData (plugin);
	exit_if_fail (h != 0, "no plugin handle");
	succeed_if_same_string (h->system.path, "elektra.ecf");
	succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
	succeed_if (h->user.filename == NULL, "user was initialized, but is not needed");
	plugin->kdbClose (plugin, parentKey);

	keyDel (parentKey);
	elektraPluginClose (plugin, 0);
	elektraModulesClose (modules, 0);
	ksDel (modules);
	elektraFree (path);
}
开发者ID:BernhardDenner,项目名称:libelektra,代码行数:53,代码来源:testmod_resolver.c

示例3: keySetOrderMeta

int keySetOrderMeta (Key * key, int order)
{
	char * buffer;
	int result;
	result = asprintf (&buffer, "%d", order);

	if (result < 0) return result;

	result = keySetMeta (key, "order", buffer);
	elektraFree (buffer);
	return result;
}
开发者ID:nikonthethird,项目名称:libelektra,代码行数:12,代码来源:augeas.c

示例4: foreachAugeasNode

static int foreachAugeasNode (augeas * handle, const char * treePath, ForeachAugNodeClb callback, void * callbackData)
{
	char * matchPath;
	int result = 0;
	result = asprintf (&matchPath, "%s//*", treePath);

	if (result < 0) return -1;

	/* must be non NULL for aug_match to return matches */
	char ** matches = (char **)1;
	int numMatches = aug_match (handle, matchPath, &matches);
	elektraFree (matchPath);

	if (numMatches < 0) return numMatches;

	int i;
	for (i = 0; i < numMatches; i++)
	{
		/* retrieve the value from augeas */
		char * curPath = matches[i];

		result = (*callback) (handle, curPath, callbackData);

		/* if handling the key failed, abort with an error as
		 * the failed key could be a crucial one
		 */
		if (result < 0) break;

		elektraFree (curPath);
	}

	for (; i < numMatches; i++)
	{
		elektraFree (matches[i]);
	}

	elektraFree (matches);

	return result;
}
开发者ID:nikonthethird,项目名称:libelektra,代码行数:40,代码来源:augeas.c

示例5: test_commit

static void test_commit (void)
{
	printf ("test commit notification\n");

	Key * parentKey = keyNew ("system/tests/foo", KEY_END);
	Key * toAdd = keyNew ("system/tests/foo/bar", KEY_END);
	KeySet * ks = ksNew (0, KS_END);

	KeySet * conf = ksNew (3, keyNew ("/endpoint", KEY_VALUE, TEST_ENDPOINT, KEY_END),
			       keyNew ("/connectTimeout", KEY_VALUE, TESTCONFIG_CONNECT_TIMEOUT, KEY_END),
			       keyNew ("/subscribeTimeout", KEY_VALUE, TESTCONFIG_SUBSCRIBE_TIMEOUT, KEY_END), KS_END);
	PLUGIN_OPEN ("zeromqsend");

	// initial get to save current state
	plugin->kdbGet (plugin, ks, parentKey);

	// add key to keyset
	ksAppendKey (ks, toAdd);

	receiveTimeout = 0;
	receivedKeyName = NULL;
	receivedChangeType = NULL;

	pthread_t * thread = startNotificationReaderThread ("Commit");
	plugin->kdbSet (plugin, ks, parentKey);
	pthread_join (*thread, NULL);

	succeed_if (receiveTimeout == 0, "receiving did time out");
	succeed_if (!keyGetMeta (parentKey, "warnings"), "warning meta key was set");
	succeed_if_same_string ("Commit", receivedChangeType);
	succeed_if_same_string (keyName (parentKey), receivedKeyName);

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
	elektraFree (receivedKeyName);
	elektraFree (receivedChangeType);
	elektraFree (thread);
}
开发者ID:ElektraInitiative,项目名称:libelektra,代码行数:39,代码来源:testmod_zeromqsend.c

示例6: f

/**
 * Key Object Cleaner.
 *
 * Will reset all internal data.
 *
 * After this call you will receive a fresh
 * key.
 *
 * The reference counter will stay unmodified.
 *
 * @note that you might also clear() all aliases
 * with this operation.
 *
 * @code
int f (Key *k)
{
	keyClear (k);
	// you have a fresh key k here
	keySetString (k, "value");
	// the caller will get an empty key k with an value
}
 * @endcode
 *
 * @retval returns 0 on success
 * @retval -1 on null pointer
 *
 * @param key the key object to work with
 * @ingroup key
 */
int keyClear (Key * key)
{
	if (!key)
	{
		return -1;
	}

	size_t ref = 0;

	ref = key->ksReference;
	if (key->key) elektraFree (key->key);
	if (key->data.v) elektraFree (key->data.v);
	if (key->meta) ksDel (key->meta);

	keyInit (key);


	/* Set reference properties */
	key->ksReference = ref;

	return 0;
}
开发者ID:fberlakovich,项目名称:libelektra,代码行数:51,代码来源:key.c

示例7: printHelpMessage

/**
 * Outputs the help message to stdout
 *
 * @param usage	   If this is not NULL, it will be used instead of the default usage line.
 * @param prefix   If this is not NULL, it will be inserted between the usage line and the options list.
 */
void printHelpMessage (const char * usage, const char * prefix)
{
	if (helpKey == NULL)
	{
		return;
	}

	char * help = elektraGetOptsHelpMessage (helpKey, usage, prefix);
	printf ("%s", help);
	elektraFree (help);
	keyDel (helpKey);
	helpKey = NULL;
}
开发者ID:ElektraInitiative,项目名称:libelektra,代码行数:19,代码来源:simple.expected.c

示例8: foreachAugeasNode

static int foreachAugeasNode(augeas *handle, const char *treePath,
		ForeachAugNodeClb callback, void *callbackData)
{
	char *matchPath;
	asprintf (&matchPath, "%s/*", treePath);

	/* must be non NULL for aug_match to return matches */
	char **matches = (char **) 1;
	int numMatches = aug_match (handle, matchPath, &matches);
	elektraFree (matchPath);

	if (numMatches < 0) return numMatches;

	int i;
	int result = 0;
	for (i = 0; i < numMatches; i++)
	{
		/* retrieve the value from augeas */
		char *curPath = matches[i];

		result = (*callback) (handle, curPath, callbackData);

		/* handle the subtree */
		result = foreachAugeasNode (handle, curPath, callback, callbackData);

		if (result < 0) break;

		elektraFree (curPath);
	}

	for (; i < numMatches; i++)
	{
		elektraFree (matches[i]);
	}

	elektraFree (matches);

	return result;
}
开发者ID:tryge,项目名称:libelektra,代码行数:39,代码来源:augeas.c

示例9: isValidSuffix

static int isValidSuffix (char * suffix, const Key * suffixList)
{
	if (!suffixList) return 0;
	char * searchString = elektraMalloc (strlen (suffix) + 3);
	snprintf (searchString, strlen (suffix) + 3, "'%s'", suffix);
	int ret = 0;
	if (strstr (keyString (suffixList), searchString))
	{
		ret = 1;
	}
	elektraFree (searchString);
	return ret;
}
开发者ID:ElektraInitiative,项目名称:libelektra,代码行数:13,代码来源:conditionals.c

示例10: renameKey

/**
 * @internal
 * Create a new key with a different root or common name.
 *
 * Does not modify `key`. The new key needs to be freed after usage.
 *
 * Preconditions: The key name starts with `source`.
 *
 * Example:
 * ```
 * Key * source = keyNew("user/plugins/foo/placements/get", KEY_END);
 * Key * dest = renameKey ("user/plugins/foo", "user/plugins/bar", source);
 * succeed_if_same_string (keyName(dest), "user/plugins/bar/placements/get");
 * ```
 *
 *
 * @param  source Part of the key name to replace
 * @param  dest   Replaces `source`
 * @param  key    key
 * @return        key with new name
 */
static Key * renameKey (const char * source, const char * dest, Key * key)
{
	const char * name = keyName (key);
	char * baseKeyNames = strndup (name + strlen (source), strlen (name));

	Key * moved = keyDup (key);
	keySetName (moved, dest);
	keyAddName (moved, baseKeyNames);

	elektraFree (baseKeyNames);

	return moved;
}
开发者ID:0003088,项目名称:libelektra,代码行数:34,代码来源:notification.c

示例11: keyAddBaseName

/**
 * Adds @p baseName (that will be escaped) to the current key name.
 *
 * A new baseName will be added, no other part of the key name will be
 * affected.
 *
 * Assumes that @p key is a directory and will append @p baseName to it.
 * The function adds the path separator for concatenating.
 *
 * So if @p key has name @c "system/dir1/dir2" and this method is called with
 * @p baseName @c "mykey", the resulting key will have the name
 * @c "system/dir1/dir2/mykey".
 *
 * When @p baseName is 0 nothing will happen and the size of the name is returned.
 *
 * The escaping rules apply as in @link keyname above @endlink.
 *
 * A simple example is:
 * @snippet basename.c add base basic
 *
 * E.g. if you add . it will be escaped:
 * @snippet testabi_key.c base1 add
 *
 * @see keySetBaseName() to set a base name
 * @see keySetName() to set a new name.
 *
 * @param key the key object to work with
 * @param baseName the string to append to the name
 * @return the size in bytes of the new key name including the ending NULL
 * @retval -1 if the key had no name
 * @retval -1 on NULL pointers
 * @retval -1 if key was inserted to a keyset before
 * @ingroup keyname
 *
 */
ssize_t keyAddBaseName (Key * key, const char * baseName)
{
	if (!key) return -1;
	if (!baseName) return key->keySize;
	if (test_bit (key->flags, KEY_FLAG_RO_NAME)) return -1;
	if (!key->key) return -1;

	char * escaped = elektraMalloc (strlen (baseName) * 2 + 2);
	elektraEscapeKeyNamePart (baseName, escaped);
	size_t len = strlen (escaped);
	if (!strcmp (key->key, "/"))
	{
		key->keySize += len;
	}
	else
	{
		key->keySize += len + 1;
	}

	elektraRealloc ((void **)&key->key, key->keySize * 2);
	if (!key->key)
	{
		elektraFree (escaped);
		return -1;
	}

	if (strcmp (key->key, "/"))
	{
		key->key[key->keySize - len - 2] = KDB_PATH_SEPARATOR;
	}
	memcpy (key->key + key->keySize - len - 1, escaped, len);

	elektraFree (escaped);

	elektraFinalizeName (key);

	return key->keySize;
}
开发者ID:fberlakovich,项目名称:libelektra,代码行数:73,代码来源:keyname.c

示例12: elektraResolveFinishByDirname

static void elektraResolveFinishByDirname (ElektraResolved * handle, ElektraResolveTempfile tmpDir)
{
	size_t filenameSize = elektraStrLen (handle->relPath) + elektraStrLen (handle->dirname);
	char * filename = elektraMalloc (filenameSize);
	strcpy (filename, handle->dirname);
	if (handle->relPath[0] != '/')
	{
		strcat (filename, "/");
	}
	strcat (filename, handle->relPath);
	elektraFree (handle->dirname);
	handle->fullPath = filename;
	elektraResolveFinishByFilename (handle, tmpDir);
}
开发者ID:0003088,项目名称:libelektra,代码行数:14,代码来源:filename.c

示例13: kdbClose

/**
 * Closes the session with the Key database.
 *
 * @pre The handle must be a valid handle as returned from kdbOpen()
 *
 * @pre errorKey must be a valid key, e.g. created with keyNew()
 *
 * This is the counterpart of kdbOpen().
 *
 * You must call this method when you finished your affairs with the key
 * database. You can manipulate Key and KeySet objects also after
 * kdbClose(), but you must not use any kdb*() call afterwards.
 *
 * The @p handle parameter will be finalized and all resources associated to it
 * will be freed. After a kdbClose(), the @p handle cannot be used anymore.
 *
 * @param handle contains internal information of
 *               @link kdbOpen() opened @endlink key database
 * @param errorKey the key which holds error/warning information
 * @retval 0 on success
 * @retval -1 on NULL pointer
 * @ingroup kdb
 */
int kdbClose (KDB * handle, Key * errorKey)
{
	if (!handle)
	{
		return -1;
	}

	Key * initialParent = keyDup (errorKey);
	int errnosave = errno;
	splitDel (handle->split);

	trieClose (handle->trie, errorKey);

	backendClose (handle->defaultBackend, errorKey);
	handle->defaultBackend = 0;

	// not set in fallback mode, so lets check:
	if (handle->initBackend)
	{
		backendClose (handle->initBackend, errorKey);
		handle->initBackend = 0;
	}

	for (int i = 0; i < NR_GLOBAL_POSITIONS; ++i)
	{
		for (int j = 0; j < NR_GLOBAL_SUBPOSITIONS; ++j)
		{
			elektraPluginClose (handle->globalPlugins[i][j], errorKey);
		}
	}

	if (handle->modules)
	{
		elektraModulesClose (handle->modules, errorKey);
		ksDel (handle->modules);
	}
	else
	{
		ELEKTRA_ADD_WARNING (47, errorKey, "modules were not open");
	}

	elektraFree (handle);

	keySetName (errorKey, keyName (initialParent));
	keySetString (errorKey, keyString (initialParent));
	keyDel (initialParent);
	errno = errnosave;
	return 0;
}
开发者ID:KurtMi,项目名称:libelektra,代码行数:72,代码来源:kdb.c

示例14: elektraResolvePasswd

static char * elektraResolvePasswd (Key * warningsKey)
{
	ssize_t bufSize = sysconf (_SC_GETPW_R_SIZE_MAX);
	if (bufSize == -1) bufSize = 16384; // man 3 getpwuid

	char * buf = elektraMalloc (bufSize);
	if (!buf) return NULL;
	struct passwd pwd;
	struct passwd * result;

	int s = getpwuid_r (getuid (), &pwd, buf, bufSize, &result);
	if (result == NULL)
	{
		elektraFree (buf);
		if (s != 0)
		{
			ELEKTRA_ADD_WARNING (90, warningsKey, strerror (s));
		}
		return NULL;
	}
	char * resolved = elektraStrDup (pwd.pw_dir);
	elektraFree (buf);
	return resolved;
}
开发者ID:0003088,项目名称:libelektra,代码行数:24,代码来源:filename.c

示例15: test_decode

void test_decode (void)
{
	printf ("test decode\n");

	CCodeData * d = get_data ();

	char buf[1000];
	d->buf = buf;
	Key * test = keyNew ("user/test", KEY_SIZE, sizeof (encoded_string) - 1, KEY_VALUE, encoded_string, KEY_END);
	elektraCcodeDecode (test, d);
	succeed_if (!memcmp (keyValue (test), decoded_string, sizeof (decoded_string) - 1), "string not correctly encoded");

	elektraFree (d);
	keyDel (test);
}
开发者ID:reox,项目名称:libelektra,代码行数:15,代码来源:testmod_ccode.c


注:本文中的elektraFree函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。