/* * pocli_pmemobj_tx_strdup -- pmemobj_tx_strdup() command */ static enum pocli_ret pocli_pmemobj_tx_strdup(struct pocli_ctx *ctx, struct pocli_args *args) { if (args->argc != 4) return POCLI_ERR_ARGS; if (pmemobj_tx_stage() != TX_STAGE_WORK) return pocli_err(ctx, POCLI_ERR_ARGS, "cannot use in stage different than TX_STAGE_WORK\n"); PMEMoid *oidp = NULL; uint64_t type_num; enum pocli_ret ret; ret = pocli_args_obj(ctx, args, 1, &oidp); if (ret) return ret; if (oidp == &ctx->root) return pocli_err(ctx, POCLI_ERR_ARGS, "cannot use root object\n"); ret = pocli_args_number(args, 3, &type_num); if (ret) return ret; *oidp = pmemobj_tx_strdup(args->argv[2], type_num); pocli_printf(ctx, "%s(%s, %llu): off = 0x%llx uuid = 0x%llx\n", args->argv[0], args->argv[2], type_num, oidp->off, oidp->pool_uuid_lo); return ret; }
#define TEST_STR_1 "Test string 1" #define TEST_STR_2 "Test string 2" #define MAX_FUNC 2 typedef void (*fn_tx_strdup)(TOID(char) *str, const char *s, unsigned type_num); static unsigned counter; /* * tx_strdup -- duplicate a string using pmemobj_tx_strdup */ static void tx_strdup(TOID(char) *str, const char *s, unsigned type_num) { TOID_ASSIGN(*str, pmemobj_tx_strdup(s, type_num)); } /* * tx_strdup_macro -- duplicate a string using macro */ static void tx_strdup_macro(TOID(char) *str, const char *s, unsigned type_num) { TOID_ASSIGN(*str, TX_STRDUP(s, type_num)); } fn_tx_strdup do_tx_strdup[MAX_FUNC] = {tx_strdup, tx_strdup_macro}; /* * do_tx_strdup_commit -- duplicate a string and commit the transaction