本文整理汇总了C++中wmem_strdup_printf函数的典型用法代码示例。如果您正苦于以下问题:C++ wmem_strdup_printf函数的具体用法?C++ wmem_strdup_printf怎么用?C++ wmem_strdup_printf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wmem_strdup_printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NSTime__tostring
WSLUA_METAMETHOD NSTime__tostring(lua_State* L) {
NSTime nstime = checkNSTime(L,1);
gchar *str;
long secs = (long)nstime->secs;
gint nsecs = nstime->nsecs;
gboolean negative_zero = FALSE;
/* Time is defined as sec + nsec/10^9, both parts can be negative.
* Translate this into the more familiar sec.nsec notation instead. */
if (secs > 0 && nsecs < 0) {
/* sign mismatch: (2, -3ns) -> 1.7 */
nsecs += NS_PER_S;
secs--;
} else if (secs < 0 && nsecs > 0) {
/* sign mismatch: (-2, 3ns) -> -1.7 */
nsecs = NS_PER_S - nsecs;
secs--;
} else if (nsecs < 0) {
/* Drop sign, the integer part already has it: (-2, -3ns) -> -2.3 */
nsecs = -nsecs;
/* In case the integer part is zero, it does not has a sign, so remember
* that it must be explicitly added. */
negative_zero = secs == 0;
}
if (negative_zero) {
str = wmem_strdup_printf(NULL, "-0.%09d", nsecs);
} else {
str = wmem_strdup_printf(NULL, "%ld.%09d", secs, nsecs);
}
lua_pushstring(L, str);
wmem_free(NULL, str);
WSLUA_RETURN(1); /* The string representing the nstime. */
}
示例2: time_stamp
/* -------------------------- */
static int
time_stamp(tvbuff_t *tvb, proto_tree *nasdaq_itch_tree, int id, int offset, int size)
{
if (nasdaq_itch_tree) {
guint32 ms, val;
const char *display = "";
const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size);
ms = val = (guint32)strtoul(str_value, NULL, 10);
switch (size) {
case 3:
display = wmem_strdup_printf(wmem_packet_scope(), " %03u" , val);
break;
case 5:
ms = val *1000;
case 8: /* 0 86 400 000 */
display = wmem_strdup_printf(wmem_packet_scope(), " %u (%02u:%02u:%02u.%03u)", val,
ms/3600000, (ms % 3600000)/60000, (ms % 60000)/1000, ms %1000);
break;
}
proto_tree_add_uint_format_value(nasdaq_itch_tree, id, tvb, offset, size, val, "%s", display);
}
return offset + size;
}
示例3: wmem_test_strutls
static void
wmem_test_strutls(void)
{
wmem_allocator_t *allocator;
const char *orig_str;
char *new_str;
char **split_str;
allocator = wmem_allocator_new(WMEM_ALLOCATOR_STRICT);
orig_str = "TEST1";
new_str = wmem_strdup(allocator, orig_str);
g_assert_cmpstr(new_str, ==, orig_str);
new_str[0] = 'X';
g_assert_cmpstr(new_str, >, orig_str);
wmem_strict_check_canaries(allocator);
orig_str = "TEST123456789";
new_str = wmem_strndup(allocator, orig_str, 6);
g_assert_cmpstr(new_str, ==, "TEST12");
g_assert_cmpstr(new_str, <, orig_str);
new_str[0] = 'X';
g_assert_cmpstr(new_str, >, orig_str);
wmem_strict_check_canaries(allocator);
new_str = wmem_strdup_printf(allocator, "abc %s %% %d", "boo", 23);
g_assert_cmpstr(new_str, ==, "abc boo % 23");
new_str = wmem_strdup_printf(allocator, "%s", STRING_80);
g_assert_cmpstr(new_str, ==, STRING_80);
wmem_strict_check_canaries(allocator);
new_str = wmem_strconcat(allocator, "ABC", NULL);
g_assert_cmpstr(new_str, ==, "ABC");
new_str = wmem_strconcat(allocator, "ABC", "DEF", NULL);
g_assert_cmpstr(new_str, ==, "ABCDEF");
wmem_strict_check_canaries(allocator);
new_str = wmem_strconcat(allocator, "", "", "ABCDEF", "", "GH", NULL);
g_assert_cmpstr(new_str, ==, "ABCDEFGH");
wmem_strict_check_canaries(allocator);
split_str = wmem_strsplit(allocator, "A-C", "-", 2);
g_assert_cmpstr(split_str[0], ==, "A");
g_assert_cmpstr(split_str[1], ==, "C");
split_str = wmem_strsplit(allocator, "--aslkf-asio--asfj-as--", "-", 10);
g_assert_cmpstr(split_str[0], ==, "aslkf");
g_assert_cmpstr(split_str[1], ==, "asio");
g_assert_cmpstr(split_str[2], ==, "asfj");
g_assert_cmpstr(split_str[3], ==, "as");
split_str = wmem_strsplit(allocator, "--aslkf-asio--asfj-as--", "-", 4);
g_assert_cmpstr(split_str[0], ==, "aslkf");
g_assert_cmpstr(split_str[1], ==, "asio");
g_assert_cmpstr(split_str[2], ==, "-asfj-as--");
wmem_strict_check_canaries(allocator);
orig_str = "TeStAsCiIsTrDoWn";
new_str = wmem_ascii_strdown(allocator, orig_str, -1);
g_assert_cmpstr(new_str, ==, "testasciistrdown");
wmem_destroy_allocator(allocator);
}
示例4: dissect_UDPR1
static void
dissect_UDPR1(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
gchar** info_string)
{
const gchar *status_string;
guint32 seq_num, status;
status = tvb_get_letohl(tvb, 0);
status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
if (status_string) {
*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Status: %s", status_string);
} else {
*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Undefined error code %d", status);
}
/* Get the transaction identifier */
seq_num = tvb_get_letohl(tvb, 4);
adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
if (! adwin_tree)
return;
SET_PACKET_TYPE(adwin_tree, APT_UDPR1);
ADWIN_ADD_LE(adwin_tree, status, 0, 4);
ADWIN_ADD_LE(adwin_tree, packet_index, 4, 4);
ADWIN_ADD_LE(adwin_tree, val1, 8, 4);
ADWIN_ADD_LE(adwin_tree, val1f, 8, 4);
ADWIN_ADD_LE(adwin_tree, val2, 12, 4);
ADWIN_ADD_LE(adwin_tree, val3, 16, 4);
ADWIN_ADD_LE(adwin_tree, val4, 20, 4);
ADWIN_ADD_LE(adwin_debug_tree, unused, 24, 8);
}
示例5: lbttcp_transport_source_string
char * lbttcp_transport_source_string(const address * source_address, guint16 source_port, guint32 session_id)
{
char * bufptr = NULL;
if (session_id == 0)
{
bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT, address_to_str(wmem_packet_scope(), source_address), source_port);
}
else
{
bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT ":%08x", address_to_str(wmem_packet_scope(), source_address), source_port, session_id);
}
return (bufptr);
}
示例6: dissect_UDPR2
static void
dissect_UDPR2(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
gchar** info_string)
{
const gchar *status_string;
guint32 i, status, seq_num;
status = tvb_get_letohl(tvb, 0);
status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
if (status_string) {
*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Status: %s", status_string);
} else {
*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Undefined error code %d", status);
}
/* Get the transaction identifier */
seq_num = tvb_get_letohl(tvb, 4);
adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
if (! adwin_tree)
return;
SET_PACKET_TYPE(adwin_tree, APT_UDPR2);
ADWIN_ADD_LE(adwin_tree, status, 0, 4);
ADWIN_ADD_LE(adwin_tree, packet_index, 4, 4);
if (! global_adwin_dissect_data) {
proto_tree_add_text(adwin_debug_tree, tvb, 8, 250 * 4, "Data");
return;
}
for (i = 0; i < 250; i++) {
proto_item *item;
guint32 offset = 8 + i * (int)sizeof(guint32);
gint32 value = tvb_get_letohl(tvb, offset);
void * fvalue = &value;
proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
"Data[%3d]: %10d - %10f - 0x%08x",
i, value, *(float*)fvalue, value);
item = ADWIN_ADD_LE(adwin_debug_tree, data_int, offset, 4);
PROTO_ITEM_SET_HIDDEN(item);
item = ADWIN_ADD_LE(adwin_debug_tree, data_float, offset, 4);
PROTO_ITEM_SET_HIDDEN(item);
item = ADWIN_ADD_LE(adwin_debug_tree, data_hex, offset, 4);
PROTO_ITEM_SET_HIDDEN(item);
}
}
示例7: parseByteString
void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
{
char *szValue;
int iOffset = *pOffset;
gint32 iLen = tvb_get_letohl(tvb, iOffset);
iOffset += 4;
if (iLen == -1)
{
proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
proto_item_append_text(item, "[OpcUa Null ByteString]");
proto_item_set_end(item, tvb, *pOffset + 4);
}
else if (iLen == 0)
{
proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
proto_item_append_text(item, "[OpcUa Empty ByteString]");
proto_item_set_end(item, tvb, *pOffset + 4);
}
else if (iLen > 0)
{
proto_tree_add_item(tree, hfIndex, tvb, iOffset, iLen, ENC_NA);
iOffset += iLen; /* eat the whole bytestring */
}
else
{
proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
szValue = wmem_strdup_printf(wmem_packet_scope(), "[Invalid ByteString] Invalid length: %d", iLen);
proto_item_append_text(item, "%s", szValue);
proto_item_set_end(item, tvb, *pOffset + 4);
}
*pOffset = iOffset;
}
示例8: dissect_bt_dht_error
/* dissect a bt dht error from tvb, start at offset. it's like "li201e9:error msge" */
static int
dissect_bt_dht_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, const char **result, const char *label )
{
proto_item *ti;
proto_tree *sub_tree;
const char *error_no, *error_msg;
error_no = NULL;
error_msg = NULL;
ti = proto_tree_add_item( tree, hf_bt_dht_error, tvb, offset, 0, ENC_NA );
sub_tree = proto_item_add_subtree( ti, ett_bt_dht_error);
/* we have confirmed that the first byte is 'l' */
offset += 1;
/* dissect bt-dht error number and message */
offset = dissect_bencoded_int( tvb, pinfo, sub_tree, offset, &error_no, "Error ID" );
offset = dissect_bencoded_string( tvb, pinfo, sub_tree, offset, &error_msg, FALSE, "Error Message" );
proto_item_set_text( ti, "%s: error %s, %s", label, error_no, error_msg );
col_append_fstr( pinfo->cinfo, COL_INFO, "error_no=%s error_msg=%s ", error_no, error_msg );
*result = wmem_strdup_printf(wmem_packet_scope(), "error %s, %s", error_no, error_msg );
return offset;
}
示例9: call_dop_oid_callback
static int
call_dop_oid_callback(const char *base_string, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, const char *col_info, void* data)
{
char* binding_param;
binding_param = wmem_strdup_printf(wmem_packet_scope(), "%s.%s", base_string, binding_type ? binding_type : "");
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", col_info);
if (dissector_try_string(dop_dissector_table, binding_param, tvb, pinfo, tree, data)) {
offset = tvb_reported_length (tvb);
} else {
proto_item *item=NULL;
proto_tree *next_tree=NULL;
item = proto_tree_add_text(tree, tvb, 0, tvb_length_remaining(tvb, offset), "Dissector for parameter %s OID:%s not implemented. Contact Wireshark developers if you want this supported", base_string, binding_type ? binding_type : "<empty>");
if (item) {
next_tree = proto_item_add_subtree(item, ett_dop_unknown);
}
offset = dissect_unknown_ber(pinfo, tvb, offset, next_tree);
expert_add_info(pinfo, item, &ei_dop_unknown_binding_parameter);
}
return offset;
}
示例10: wmem_strdup_printf
static const gchar *gen_olc_key(guint16 lc_num, address *dst_addr, address *src_addr)
{
return wmem_strdup_printf(wmem_packet_scope(), "%s/%s/%u",
address_to_str(wmem_packet_scope(), dst_addr),
address_to_str(wmem_packet_scope(), src_addr),
lc_num);
}
示例11: ct_port_to_str
char *get_hostlist_filter(hostlist_talker_t *host)
{
char *sport, *src_addr;
char *str;
sport = ct_port_to_str(host->ptype, host->port);
src_addr = address_to_str(NULL, &host->myaddress);
if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == AT_USB) {
char *new_addr;
new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
wmem_free(NULL, src_addr);
src_addr = new_addr;
}
str = g_strdup_printf("%s==%s%s%s%s%s",
hostlist_get_filter_name(host, CONV_FT_ANY_ADDRESS),
src_addr,
sport?" && ":"",
sport?hostlist_get_filter_name(host, CONV_FT_ANY_PORT):"",
sport?"==":"",
sport?sport:"");
g_free(sport);
wmem_free(NULL, src_addr);
return str;
}
示例12: cmpp_msg_id
static void
cmpp_msg_id(proto_tree *tree, tvbuff_t *tvb, gint field, gint offset)
{
guint8 month,day,hour,minute,second;
guint32 ismg_code;
proto_item *pi;
proto_tree *sub_tree;
char *strval;
pi = proto_tree_add_item(tree, field, tvb, offset, 8, ENC_BIG_ENDIAN);
sub_tree = proto_item_add_subtree(pi, ett_msg_id);
month = (tvb_get_guint8(tvb, offset) & 0xF0) >> 4;
day = (tvb_get_ntohs(tvb, offset) & 0x0F80) >> 7;
hour = (tvb_get_guint8(tvb, offset + 1) & 0x7C) >> 2;
minute = (tvb_get_ntohs(tvb, offset + 1) & 0x03F0) >> 4;
second = (tvb_get_ntohs(tvb, offset + 2) & 0x0FC0) >> 6;
strval = wmem_strdup_printf(wmem_packet_scope(), "%02u/%02u %02u:%02u:%02u", month, day,
hour, minute, second);
ismg_code = (tvb_get_ntohl(tvb, offset + 3) & 0x3FFFFF00) >> 16;
proto_tree_add_string(sub_tree, hf_msg_id_timestamp, tvb, offset, 4, strval);
proto_tree_add_uint(sub_tree, hf_msg_id_ismg_code, tvb, offset + 3, 3, ismg_code);
cmpp_uint2(sub_tree, tvb, hf_msg_id_sequence_id, offset + 6);
}
示例13: xmpp_error
static void
xmpp_error(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element)
{
proto_item *error_item;
proto_tree *error_tree;
xmpp_element_t *text_element, *cond_element;
xmpp_attr_info attrs_info[] = {
{"type", &hf_xmpp_error_type, TRUE, TRUE, NULL, NULL},
{"code", &hf_xmpp_error_code, FALSE, TRUE, NULL, NULL},
{"condition", &hf_xmpp_error_condition, TRUE, TRUE, NULL, NULL} /*TODO: validate list to the condition element*/
};
gchar *error_info;
xmpp_attr_t *fake_condition = NULL;
error_info = wmem_strdup(wmem_packet_scope(), "Stanza error");
error_item = proto_tree_add_item(tree, hf_xmpp_error, tvb, element->offset, element->length, ENC_BIG_ENDIAN);
error_tree = proto_item_add_subtree(error_item, ett_xmpp_query_item);
cond_element = xmpp_steal_element_by_attr(element, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
if(cond_element)
{
fake_condition = xmpp_ep_init_attr_t(cond_element->name, cond_element->offset, cond_element->length);
g_hash_table_insert(element->attrs, (gpointer)"condition", fake_condition);
error_info = wmem_strdup_printf(wmem_packet_scope(), "%s: %s;", error_info, cond_element->name);
}
xmpp_display_attrs(error_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
while((text_element = xmpp_steal_element_by_name(element, "text")) != NULL)
{
xmpp_error_text(error_tree, tvb, text_element);
error_info = wmem_strdup_printf(wmem_packet_scope(), "%s Text: %s", error_info, text_element->data?text_element->data->value:"");
}
expert_add_info_format(pinfo, error_item, &ei_xmpp_response, "%s", error_info);
xmpp_unknown(error_tree, tvb, pinfo, element);
}
示例14: xmpp_failure_text
static void
xmpp_failure_text(proto_tree *tree, tvbuff_t *tvb, xmpp_element_t *element)
{
xmpp_attr_t *lang = xmpp_get_attr(element,"xml:lang");
proto_tree_add_text(tree, tvb, element->offset, element->length, "TEXT%s: %s",
lang?wmem_strdup_printf(wmem_packet_scope(), "(%s)",lang->value):"",
element->data?element->data->value:"");
}
示例15: NSTime__tostring
WSLUA_METAMETHOD NSTime__tostring(lua_State* L) {
NSTime nstime = checkNSTime(L,1);
gchar *str;
str = wmem_strdup_printf(NULL, "%ld.%09d", (long)nstime->secs, nstime->nsecs);
lua_pushstring(L, str);
wmem_free(NULL, str);
WSLUA_RETURN(1); /* The string representing the nstime. */
}