本文整理汇总了C++中discard_const函数的典型用法代码示例。如果您正苦于以下问题:C++ discard_const函数的具体用法?C++ discard_const怎么用?C++ discard_const使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了discard_const函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spnego_free_data
bool spnego_free_data(struct spnego_data *spnego)
{
bool ret = true;
if (!spnego) goto out;
switch(spnego->type) {
case SPNEGO_NEG_TOKEN_INIT:
if (spnego->negTokenInit.mechTypes) {
talloc_free(discard_const(spnego->negTokenInit.mechTypes));
}
data_blob_free(&spnego->negTokenInit.reqFlags);
data_blob_free(&spnego->negTokenInit.mechToken);
data_blob_free(&spnego->negTokenInit.mechListMIC);
talloc_free(spnego->negTokenInit.targetPrincipal);
break;
case SPNEGO_NEG_TOKEN_TARG:
if (spnego->negTokenTarg.supportedMech) {
talloc_free(discard_const(spnego->negTokenTarg.supportedMech));
}
data_blob_free(&spnego->negTokenTarg.responseToken);
data_blob_free(&spnego->negTokenTarg.mechListMIC);
break;
default:
ret = false;
break;
}
ZERO_STRUCTP(spnego);
out:
return ret;
}
示例2: free_scsi_device
static void free_scsi_device(struct scsi_device *sdev)
{
if (sdev->error_str) {
free(discard_const(sdev->error_str));
sdev->error_str = NULL;
}
if (sdev->iscsi_url) {
free(discard_const(sdev->iscsi_url));
sdev->iscsi_url = NULL;
}
if (sdev->iscsi_ctx) {
iscsi_logout_sync(sdev->iscsi_ctx);
iscsi_destroy_context(sdev->iscsi_ctx);
sdev->iscsi_ctx = NULL;
}
if (sdev->sgio_dev) {
free(discard_const(sdev->sgio_dev));
sdev->sgio_dev = NULL;
}
if (sdev->sgio_fd != -1) {
close(sdev->sgio_fd);
sdev->sgio_fd = -1;
}
free(sdev);
}
示例3: START_TEST
END_TEST
START_TEST(test_group_both_set)
{
struct tevent_req *req;
test_ctx->ctx->allow_groups = discard_const(ulist_1);
test_ctx->ctx->deny_groups = discard_const(ulist_1);
req = simple_access_check_send(test_ctx, test_ctx->ev,
test_ctx->ctx, "u1");
fail_unless(test_ctx != NULL, "Cannot create request\n");
tevent_req_set_callback(req, simple_access_check_done, test_ctx);
test_loop(test_ctx);
test_ctx->done = false;
fail_unless(test_ctx->error == EOK, "access_simple_check failed.");
fail_unless(test_ctx->access_granted == false,
"Access granted while user is in deny list.");
req = simple_access_check_send(test_ctx, test_ctx->ev,
test_ctx->ctx, "u3");
fail_unless(test_ctx != NULL, "Cannot create request\n");
tevent_req_set_callback(req, simple_access_check_done, test_ctx);
test_loop(test_ctx);
fail_unless(test_ctx->error == EOK, "access_simple_check failed.");
fail_unless(test_ctx->access_granted == false,
"Access granted while user is not in allow list.");
}
示例4: opt_test_inherit
void opt_test_inherit(void **state)
{
struct dp_option *opts = talloc_get_type(*state, struct dp_option);
int ret;
struct dp_option *opts_copy;
const char *s;
const char *sd_inherit_match[] = { "string_nodefault",
"blob_nodefault",
"int_nodefault",
"bool_true",
NULL };
ret = dp_copy_defaults(opts, test_def_opts,
OPT_NUM_OPTS, &opts_copy);
assert_int_equal(ret, EOK);
assert_defaults(opts);
dp_option_inherit(NULL, OPT_STRING_NODEFAULT,
opts, opts_copy);
s = dp_opt_get_string(opts_copy, OPT_STRING_NODEFAULT);
assert_null(s);
/* string */
assert_nondefault_string_empty(opts_copy);
set_nondefault_string(opts);
dp_option_inherit(discard_const(sd_inherit_match),
OPT_STRING_NODEFAULT,
opts, opts_copy);
check_nondefault_string(opts_copy);
/* blob */
assert_nondefault_blob_empty(opts_copy);
set_nondefault_blob(opts);
dp_option_inherit(discard_const(sd_inherit_match),
OPT_BLOB_NODEFAULT,
opts, opts_copy);
check_nondefault_blob(opts_copy);
/* number */
assert_nondefault_int_notset(opts_copy);
set_nondefault_int(opts);
dp_option_inherit(discard_const(sd_inherit_match),
OPT_INT_NODEFAULT,
opts, opts_copy);
assert_nondefault_int_set(opts_copy);
/* bool */
assert_true(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));
ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
assert_int_equal(ret, EOK);
dp_option_inherit(discard_const(sd_inherit_match),
OPT_BOOL_TRUE,
opts, opts_copy);
assert_false(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));
}
示例5: get_uncompressed_size
/* returns the size of the uncompressed file, or 0 if it could not be
* determined.
*/
static off_t get_uncompressed_size(const char *path)
{
struct ecm *ecm;
size_t pos;
TDB_DATA key, data;
LOG("GET_UNCOMPRESSED_SIZE [%s]\n", path);
key.dptr = discard_const(path);
key.dsize = strlen(path);
data = tdb_fetch(filesize_tdb, key);
if (data.dptr) {
off_t size = *(off_t *)data.dptr;
free(data.dptr);
return size;
}
LOG("GET_UNCOMPRESSED_SIZE SLOW PATH [%s]\n", path);
ecm = ecm_open_file(dir_fd, path);
if (ecm == NULL) {
LOG("Failed to open ECM file %s in get_uncompressed_size\n",
path);
return 0;
}
pos = ecm_get_file_size(ecm);
ecm_close_file(ecm);
LOG("GET_UNCOMPRESSED_SIZE [%s] %zu\n", path, pos);
data.dptr = (uint8_t *)&pos;
data.dsize = sizeof(pos);
tdb_store(filesize_tdb, key, data, TDB_REPLACE);
return pos;
}
示例6: ipa_sudo_conv_store
static errno_t
ipa_sudo_conv_store(hash_table_t *table,
const char *key,
void *value)
{
hash_key_t hkey;
hash_value_t hvalue;
int hret;
if (table == NULL || key == NULL) {
return EINVAL;
}
hkey.type = HASH_KEY_STRING;
hkey.str = discard_const(key);
/* If value is NULL we don't want to override existing entry. */
if (value == NULL && hash_has_key(table, &hkey)) {
return EEXIST;
}
hvalue.type = HASH_VALUE_PTR;
hvalue.ptr = value;
hret = hash_enter(table, &hkey, &hvalue);
if (hret != HASH_SUCCESS) {
return EIO;
}
if (value != NULL) {
talloc_steal(table, value);
}
return EOK;
}
示例7: dyndns_test_error
void dyndns_test_error(void **state)
{
struct tevent_req *req;
errno_t ret;
TALLOC_CTX *tmp_ctx;
tmp_ctx = talloc_new(global_talloc_context);
assert_non_null(tmp_ctx);
check_leaks_push(tmp_ctx);
dyndns_test_ctx->state = MOCK_NSUPDATE_ERR;
req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
BE_NSUPDATE_AUTH_GSS_TSIG,
discard_const("test message"), false);
assert_non_null(req);
tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
/* Wait until the test finishes with EIO (child error) */
ret = test_ev_loop(dyndns_test_ctx->tctx);
DEBUG(SSSDBG_TRACE_LIBS,
"Child request returned [%d]: %s\n", ret, strerror(ret));
assert_int_equal(ret, ERR_DYNDNS_FAILED);
assert_true(WIFEXITED(dyndns_test_ctx->child_status));
assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 1);
assert_true(check_leaks_pop(tmp_ctx) == true);
talloc_free(tmp_ctx);
}
示例8: fetch_lock_once
/*
Just try locking/unlocking a single record once
*/
static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev)
{
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
TDB_DATA key, data;
struct ctdb_record_handle *h;
static time_t t = 0, t2;
key.dptr = discard_const(TESTKEY);
key.dsize = strlen(TESTKEY);
// printf("Trying to fetch lock the record ...\n");
h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, true);
if (h == NULL) {
printf("Failed to fetch record '%s' on node %d\n",
(const char *)key.dptr, ctdb_get_pnn(ctdb));
talloc_free(tmp_ctx);
exit(10);
}
count++;
t2 = time(NULL);
if (t != 0 && t != t2) {
static int last_count = 0;
printf("count : %d\n", count - last_count);
last_count = count;
}
t = t2;
talloc_free(tmp_ctx);
}
示例9: do_test1
static void do_test1(void)
{
struct hash_count_context *hc = NULL;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct timeval interval = {1, 0};
TDB_DATA key;
int count = 0;
int ret, i;
key.dptr = (uint8_t *)discard_const(KEY);
key.dsize = strlen(KEY);
ret = hash_count_increment(hc, key);
assert(ret == EINVAL);
ret = hash_count_init(mem_ctx, interval, NULL, NULL, &hc);
assert(ret == EINVAL);
ret = hash_count_init(mem_ctx, interval, test1_handler, &count, &hc);
assert(ret == 0);
assert(hc != NULL);
for (i=0; i<10; i++) {
ret = hash_count_increment(hc, key);
assert(ret == 0);
assert(count == i+1);
}
talloc_free(hc);
ret = talloc_get_size(mem_ctx);
assert(ret == 0);
talloc_free(mem_ctx);
}
示例10: START_TEST
END_TEST
START_TEST(test_case_sensitive)
{
char *result;
int ret;
const char *file_template = BASE"_%u";
const char *expected_cs = BASE"_TestUser";
const char *expected_ci = BASE"_testuser";
kr->pd->user = discard_const("TestUser");
ret = dp_opt_set_string(kr->krb5_ctx->opts, KRB5_CCACHEDIR, CCACHE_DIR);
fail_unless(ret == EOK, "Failed to set Ccache dir");
result = expand_ccname_template(tmp_ctx, kr, file_template, NULL, true, true);
fail_unless(result != NULL, "Cannot expand template [%s].", file_template);
fail_unless(strcmp(result, expected_cs) == 0,
"Expansion failed, result [%s], expected [%s].",
result, expected_cs);
result = expand_ccname_template(tmp_ctx, kr, file_template, NULL, true, false);
fail_unless(result != NULL, "Cannot expand template [%s].", file_template);
fail_unless(strcmp(result, expected_ci) == 0,
"Expansion failed, result [%s], expected [%s].",
result, expected_ci);
}
示例11: mprSetPtrChild
/*
set a pointer in a existing MprVar, freeing it when the property goes away
*/
void mprSetPtrChild(struct MprVar *v, const char *propname, const void *p)
{
mprSetVar(v, propname, mprCreatePtrVar(discard_const(p)));
v = mprGetProperty(v, propname, NULL);
v->allocatedData = 1;
talloc_steal(mprMemCtx(), p);
}
示例12: setup_talloc_context
END_TEST
void setup_talloc_context(void)
{
int ret;
int i;
struct pam_data *pd;
struct krb5_ctx *krb5_ctx;
fail_unless(tmp_ctx == NULL, "Talloc context already initialized.");
tmp_ctx = talloc_new(NULL);
fail_unless(tmp_ctx != NULL, "Cannot create talloc context.");
kr = talloc_zero(tmp_ctx, struct krb5child_req);
fail_unless(kr != NULL, "Cannot create krb5child_req structure.");
pd = create_pam_data(tmp_ctx);
fail_unless(pd != NULL, "Cannot create pam_data structure.");
krb5_ctx = talloc_zero(tmp_ctx, struct krb5_ctx);
fail_unless(pd != NULL, "Cannot create krb5_ctx structure.");
pd->user = discard_const(USERNAME);
kr->uid = atoi(UID);
kr->upn = discard_const(PRINCIPAL_NAME);
pd->cli_pid = atoi(PID);
krb5_ctx->opts = talloc_zero_array(tmp_ctx, struct dp_option, KRB5_OPTS);
fail_unless(krb5_ctx->opts != NULL, "Cannot created options.");
for (i = 0; i < KRB5_OPTS; i++) {
krb5_ctx->opts[i].opt_name = default_krb5_opts[i].opt_name;
krb5_ctx->opts[i].type = default_krb5_opts[i].type;
krb5_ctx->opts[i].def_val = default_krb5_opts[i].def_val;
}
ret = dp_opt_set_string(krb5_ctx->opts, KRB5_REALM, REALM);
fail_unless(ret == EOK, "Failed to set Realm");
ret = dp_opt_set_string(krb5_ctx->opts, KRB5_CCACHEDIR, CCACHE_DIR);
fail_unless(ret == EOK, "Failed to set Ccache dir");
kr->homedir = HOME_DIRECTORY;
kr->pd = pd;
kr->krb5_ctx = krb5_ctx;
}
示例13: iscsi_free_discovery_addresses
static void
iscsi_free_discovery_addresses(struct iscsi_context *iscsi, struct iscsi_discovery_address *addresses)
{
while (addresses != NULL) {
struct iscsi_discovery_address *next = addresses->next;
iscsi_free(iscsi, discard_const(addresses->target_name));
addresses->target_name = NULL;
iscsi_free(iscsi, discard_const(addresses->target_address));
addresses->target_address = NULL;
addresses->next = NULL;
iscsi_free(iscsi, addresses);
addresses = next;
}
}
示例14: wbsrv_samba3_priv_pipe_dir
NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
{
const char *path = s3call->wbconn->listen_socket->service->priv_socket_path;
s3call->response.result = WINBINDD_OK;
s3call->response.extra_data.data = discard_const(path);
s3call->response.length += strlen(path) + 1;
return NT_STATUS_OK;
}
示例15: START_TEST
END_TEST
START_TEST(test_parse_args)
{
struct pa_testcase {
const char *argstr;
const char **parsed;
};
TALLOC_CTX *test_ctx;
int i, ii;
int ret;
char **parsed;
char **only_ret;
char **only_exp;
char **both;
test_ctx = talloc_new(NULL);
/* Positive tests */
const char *parsed1[] = { "foo", NULL };
const char *parsed2[] = { "foo", "a", NULL };
const char *parsed3[] = { "foo", "b", NULL };
const char *parsed4[] = { "foo", "a c", NULL };
const char *parsed5[] = { "foo", "a", "d", NULL };
const char *parsed6[] = { "foo", "a", "e", NULL };
const char *parsed7[] = { "foo", "a", "f", NULL };
const char *parsed8[] = { "foo", "a\tg", NULL };
struct pa_testcase tc[] = {
{ "foo", parsed1 },
{ "foo a", parsed2 },
{ "foo b", parsed3 },
{ "foo a\\ c", parsed4 },
{ "foo a d ", parsed5 },
{ "foo a e ", parsed6 },
{ "foo a f ", parsed7 },
{ "foo a\\\tg", parsed8 },
{ NULL, NULL }
};
for (i=0; tc[i].argstr != NULL; i++) {
parsed = parse_args(tc[i].argstr);
fail_if(parsed == NULL && tc[i].parsed != NULL,
"Could not parse correct argument string '%s'\n");
ret = diff_string_lists(test_ctx, parsed, discard_const(tc[i].parsed),
&only_ret, &only_exp, &both);
fail_unless(ret == EOK, "diff_string_lists returned error [%d]", ret);
fail_unless(only_ret[0] == NULL, "The parser returned more data than expected\n");
fail_unless(only_exp[0] == NULL, "The parser returned less data than expected\n");
for (ii = 0; parsed[ii]; ii++) free(parsed[ii]);
free(parsed);
}
talloc_free(test_ctx);
}