本文整理汇总了C++中BufferDestroy函数的典型用法代码示例。如果您正苦于以下问题:C++ BufferDestroy函数的具体用法?C++ BufferDestroy怎么用?C++ BufferDestroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BufferDestroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsIPV6Address
int IsIPV6Address(char *name)
{
if (!name)
{
return false;
}
Buffer *buffer = BufferNewFrom(name, strlen(name));
if (!buffer)
{
return false;
}
IPAddress *ip_address = NULL;
bool is_ip = false;
is_ip = IPAddressIsIPAddress(buffer, &ip_address);
if (!is_ip)
{
BufferDestroy(buffer);
return false;
}
if (IPAddressType(ip_address) != IP_ADDRESS_TYPE_IPV6)
{
BufferDestroy(buffer);
IPAddressDestroy(&ip_address);
return false;
}
BufferDestroy(buffer);
IPAddressDestroy(&ip_address);
return true;
}
示例2: test_copyEqualBuffer
static void test_copyEqualBuffer(void **state)
{
char element0[] = "element0";
unsigned int element0size = strlen(element0);
char element1[] = "element1";
unsigned int element1size = strlen(element1);
Buffer *buffer0 = NULL;
Buffer *buffer1 = NULL;
Buffer *buffer2 = NULL;
// Empty buffers, all empty buffers are the same
assert_int_equal(0, BufferNew(&buffer0));
assert_int_equal(0, BufferNew(&buffer1));
assert_true(BufferEqual(buffer0, buffer0));
assert_true(BufferEqual(buffer0, buffer1));
assert_int_equal(0, BufferCopy(buffer0, &buffer2));
assert_true(BufferEqual(buffer0, buffer2));
// Add some flavour
assert_int_equal(0, BufferDestroy(&buffer2));
assert_int_equal(element0size, BufferSet(buffer0, element0, element0size));
assert_int_equal(element1size, BufferSet(buffer1, element1, element1size));
assert_true(BufferEqual(buffer0, buffer0));
assert_false(BufferEqual(buffer0, buffer1));
assert_int_equal(0, BufferCopy(buffer0, &buffer2));
assert_true(BufferEqual(buffer0, buffer2));
// Destroy the buffers
assert_int_equal(0, BufferDestroy(&buffer0));
assert_int_equal(0, BufferDestroy(&buffer1));
assert_int_equal(0, BufferDestroy(&buffer2));
}
示例3: test_zeroBuffer
static void test_zeroBuffer(void)
{
char *element0 = xstrdup("element0");
unsigned int element0size = strlen(element0);
const char *element0pointer = NULL;
Buffer *buffer = BufferNew();
assert_int_equal(element0size, BufferSet(buffer, element0, element0size));
element0pointer = buffer->buffer;
assert_int_equal(element0size, buffer->used);
assert_int_equal(element0size, BufferSize(buffer));
BufferZero(buffer);
assert_int_equal(DEFAULT_BUFFER_SIZE, buffer->capacity);
assert_int_equal(0, buffer->used);
assert_int_equal(0, BufferSize(buffer));
const char *data = BufferData(buffer);
assert_string_equal(data, "");
assert_true(element0pointer == buffer->buffer);
BufferZero(NULL);
assert_int_equal(0, BufferDestroy(&buffer));
/*
* Release the resources
*/
BufferDestroy(&buffer);
free (element0);
}
示例4: test_destroyBuffer
static void test_destroyBuffer(void)
{
Buffer *buffer = BufferNew();
assert_int_equal(0, BufferDestroy(&buffer));
assert_true(buffer == NULL);
assert_int_equal(0, BufferDestroy(NULL));
}
示例5: Epimenides
static bool Epimenides(EvalContext *ctx, const char *ns, const char *scope, const char *var, Rval rval, int level)
{
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
if (StringContainsVar(RvalScalarValue(rval), var))
{
Log(LOG_LEVEL_ERR, "Scalar variable '%s' contains itself (non-convergent) '%s'", var, RvalScalarValue(rval));
return true;
}
if (IsCf3VarString(RvalScalarValue(rval)))
{
Buffer *exp = BufferNew();
ExpandScalar(ctx, ns, scope, RvalScalarValue(rval), exp);
if (strcmp(BufferData(exp), RvalScalarValue(rval)) == 0)
{
BufferDestroy(exp);
return false;
}
if (level > 3)
{
BufferDestroy(exp);
return false;
}
if (Epimenides(ctx, ns, scope, var, (Rval) { BufferGet(exp), RVAL_TYPE_SCALAR}, level + 1))
{
BufferDestroy(exp);
return true;
}
BufferDestroy(exp);
}
break;
case RVAL_TYPE_LIST:
for (const Rlist *rp = RvalRlistValue(rval); rp != NULL; rp = rp->next)
{
if (Epimenides(ctx, ns, scope, var, rp->val, level))
{
return true;
}
}
break;
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_FNCALL:
case RVAL_TYPE_NOPROMISEE:
return false;
}
return false;
}
示例6: RunCmpCommand
static VersionCmpResult RunCmpCommand(EvalContext *ctx, const char *command, const char *v1, const char *v2, Attributes a,
const Promise *pp, PromiseResult *result)
{
Buffer *expanded_command = BufferNew();
{
VarRef *ref_v1 = VarRefParseFromScope("v1", PACKAGES_CONTEXT);
EvalContextVariablePut(ctx, ref_v1, v1, CF_DATA_TYPE_STRING, "source=promise");
VarRef *ref_v2 = VarRefParseFromScope("v2", PACKAGES_CONTEXT);
EvalContextVariablePut(ctx, ref_v2, v2, CF_DATA_TYPE_STRING, "source=promise");
ExpandScalar(ctx, NULL, PACKAGES_CONTEXT, command, expanded_command);
EvalContextVariableRemove(ctx, ref_v1);
VarRefDestroy(ref_v1);
EvalContextVariableRemove(ctx, ref_v2);
VarRefDestroy(ref_v2);
}
FILE *pfp = a.packages.package_commands_useshell ? cf_popen_sh(BufferData(expanded_command), "w") : cf_popen(BufferData(expanded_command), "w", true);
if (pfp == NULL)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Can not start package version comparison command '%s'. (cf_popen: %s)",
BufferData(expanded_command), GetErrorStr());
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
BufferDestroy(expanded_command);
return VERCMP_ERROR;
}
Log(LOG_LEVEL_VERBOSE, "Executing '%s'", BufferData(expanded_command));
int retcode = cf_pclose(pfp);
if (retcode == -1)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Error during package version comparison command execution '%s'. (cf_pclose: %s)",
BufferData(expanded_command), GetErrorStr());
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
BufferDestroy(expanded_command);
return VERCMP_ERROR;
}
BufferDestroy(expanded_command);
return retcode == 0;
}
示例7: assert
char *VarRefToString(const VarRef *ref, bool qualified)
{
assert(ref->lval);
Buffer *buf = BufferNew();
if (qualified && VarRefIsQualified(ref))
{
const char *ns = ref->ns ? ref->ns : "default";
BufferAppend(buf, ns, strlen(ns));
BufferAppend(buf, ":", sizeof(char));
BufferAppend(buf, ref->scope, strlen(ref->scope));
BufferAppend(buf, ".", sizeof(char));
}
BufferAppend(buf, ref->lval, strlen(ref->lval));
for (size_t i = 0; i < ref->num_indices; i++)
{
BufferAppend(buf, "[", sizeof(char));
BufferAppend(buf, ref->indices[i], strlen(ref->indices[i]));
BufferAppend(buf, "]", sizeof(char));
}
char *var_string = xstrdup(BufferData(buf));
BufferDestroy(&buf);
return var_string;
}
示例8: ShowContextsFormatted
static void ShowContextsFormatted(EvalContext *ctx)
{
ClassTableIterator *iter = EvalContextClassTableIteratorNewGlobal(ctx, NULL, true, true);
Class *cls = NULL;
Seq *seq = SeqNew(1000, free);
while ((cls = ClassTableIteratorNext(iter)))
{
char *class_name = ClassRefToString(cls->ns, cls->name);
StringSet *tagset = EvalContextClassTags(ctx, cls->ns, cls->name);
Buffer *tagbuf = StringSetToBuffer(tagset, ',');
char *line;
xasprintf(&line, "%-60s %-40s", class_name, BufferData(tagbuf));
SeqAppend(seq, line);
BufferDestroy(tagbuf);
free(class_name);
}
SeqSort(seq, (SeqItemComparator)strcmp, NULL);
printf("%-60s %-40s\n", "Class name", "Meta tags");
for (size_t i = 0; i < SeqLength(seq); i++)
{
const char *context = SeqAt(seq, i);
printf("%s\n", context);
}
SeqDestroy(seq);
ClassTableIteratorDestroy(iter);
}
示例9: ShowVariablesFormatted
static void ShowVariablesFormatted(EvalContext *ctx)
{
VariableTableIterator *iter = EvalContextVariableTableIteratorNew(ctx, NULL, NULL, NULL);
Variable *v = NULL;
Seq *seq = SeqNew(2000, free);
while ((v = VariableTableIteratorNext(iter)))
{
char *varname = VarRefToString(v->ref, true);
Writer *w = StringWriter();
switch (DataTypeToRvalType(v->type))
{
case RVAL_TYPE_CONTAINER:
JsonWriteCompact(w, RvalContainerValue(v->rval));
break;
default:
RvalWrite(w, v->rval);
}
const char *var_value;
if (StringIsPrintable(StringWriterData(w)))
{
var_value = StringWriterData(w);
}
else
{
var_value = "<non-printable>";
}
StringSet *tagset = EvalContextVariableTags(ctx, v->ref);
Buffer *tagbuf = StringSetToBuffer(tagset, ',');
char *line;
xasprintf(&line, "%-40s %-60s %-40s", varname, var_value, BufferData(tagbuf));
SeqAppend(seq, line);
BufferDestroy(tagbuf);
WriterClose(w);
free(varname);
}
SeqSort(seq, (SeqItemComparator)strcmp, NULL);
printf("%-40s %-60s %-40s\n", "Variable name", "Variable value", "Meta tags");
for (size_t i = 0; i < SeqLength(seq); i++)
{
const char *variable = SeqAt(seq, i);
printf("%s\n", variable);
}
SeqDestroy(seq);
VariableTableIteratorDestroy(iter);
}
示例10: BufferRewrite
void BufferRewrite(Buffer *buffer, BufferFilterFn filter, const bool invert)
{
assert(buffer);
Buffer *rewrite = BufferFilter(buffer, filter, invert);
BufferSet(buffer, BufferData(rewrite), BufferSize(rewrite));
BufferDestroy(rewrite);
}
示例11: TestCreateBuffer
void TestCreateBuffer(CuTest* tc)
{
buffer_t *buf = BufferCreate();
CuAssertTrue(tc, buf != NULL);
CuAssertIntEquals(tc, 0, BufferGetSize(buf));
BufferDestroy(&buf);
CuAssertPtrEquals(tc, 0, buf);
}
示例12: assert
Rlist *RlistFromSplitRegex(const char *string, const char *regex, size_t max_entries, bool allow_blanks)
{
assert(string);
if (!string)
{
return NULL;
}
const char *sp = string;
size_t entry_count = 0;
int start = 0;
int end = 0;
Rlist *result = NULL;
Buffer *buffer = BufferNewWithCapacity(CF_MAXVARSIZE);
pcre *rx = CompileRegex(regex);
if (rx)
{
while ((entry_count < max_entries) &&
StringMatchWithPrecompiledRegex(rx, sp, &start, &end))
{
if (end == 0)
{
break;
}
BufferClear(buffer);
BufferAppend(buffer, sp, start);
if (allow_blanks || BufferSize(buffer) > 0)
{
RlistAppendScalar(&result, BufferData(buffer));
entry_count++;
}
sp += end;
}
pcre_free(rx);
}
if (entry_count < max_entries)
{
BufferClear(buffer);
size_t remaining = strlen(sp);
BufferAppend(buffer, sp, remaining);
if ((allow_blanks && sp != string) || BufferSize(buffer) > 0)
{
RlistAppendScalar(&result, BufferData(buffer));
}
}
BufferDestroy(buffer);
return result;
}
示例13: test_expand_scalar_undefined
static void test_expand_scalar_undefined(void **state)
{
EvalContext *ctx = *state;
Buffer *res = BufferNew();
ExpandScalar(ctx, "default", "bundle", "a$(undefined)b", res);
assert_string_equal("a$(undefined)b", BufferData(res));
BufferDestroy(res);
}
示例14: CreateHardClassesFromFeatures
void CreateHardClassesFromFeatures(EvalContext *ctx, char *tags)
{
Buffer *buffer = BufferNew();
for(int i=0 ; features[i]!=NULL ; i++) {
BufferPrintf(buffer, "feature_%s", features[i]);
CreateHardClassesFromCanonification(ctx, BufferData(buffer), tags);
}
BufferDestroy(buffer);
}
示例15: TestAppend
void TestAppend(CuTest* tc)
{
buffer_t *buf = BufferCreate();
uint8_t data[2] = { 1, 2 };
BufferAppend(buf, data, sizeof(data));
CuAssertIntEquals(tc, 2, BufferGetSize(buf));
CuAssertIntEquals(tc, 1, BufferGetByte(buf, 0));
CuAssertIntEquals(tc, 2, BufferGetByte(buf, 1));
BufferDestroy(&buf);
}