Fix for dumping objects to a buffer instead of file descriptor
Attached is a patch to fix two problems with dumping objects to a buffer in= stead of a file descriptor. One was a problem in detecting the end of the buffer in the newline code. The other was a problem with clearing the whole buffer before printing each= object.
This commit is contained in:
parent
24d577c93d
commit
ca883b61bc
|
@ -929,6 +929,9 @@ void nl_cache_dump_filter(struct nl_cache *cache,
|
||||||
if (!ops->oo_dump[type])
|
if (!ops->oo_dump[type])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (params->dp_buf)
|
||||||
|
memset(params->dp_buf, 0, params->dp_buflen);
|
||||||
|
|
||||||
nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
|
nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
|
||||||
if (filter && !nl_object_match_filter(obj, filter))
|
if (filter && !nl_object_match_filter(obj, filter))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -259,6 +259,9 @@ int nl_object_is_marked(struct nl_object *obj)
|
||||||
*/
|
*/
|
||||||
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
|
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
|
||||||
{
|
{
|
||||||
|
if (params->dp_buf)
|
||||||
|
memset(params->dp_buf, 0, params->dp_buflen);
|
||||||
|
|
||||||
dump_from_ops(obj, params);
|
dump_from_ops(obj, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -824,7 +824,7 @@ void nl_new_line(struct nl_dump_params *params)
|
||||||
else if (params->dp_buf)
|
else if (params->dp_buf)
|
||||||
strncat(params->dp_buf, " ",
|
strncat(params->dp_buf, " ",
|
||||||
params->dp_buflen -
|
params->dp_buflen -
|
||||||
sizeof(params->dp_buf) - 1);
|
strlen(params->dp_buf) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,7 +844,8 @@ static void dump_one(struct nl_dump_params *parms, const char *fmt,
|
||||||
parms->dp_cb(parms, buf);
|
parms->dp_cb(parms, buf);
|
||||||
else
|
else
|
||||||
strncat(parms->dp_buf, buf,
|
strncat(parms->dp_buf, buf,
|
||||||
parms->dp_buflen - strlen(parms->dp_buf) - 1);
|
parms->dp_buflen -
|
||||||
|
strlen(parms->dp_buf) - 1);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1053,9 +1054,6 @@ void dump_from_ops(struct nl_object *obj, struct nl_dump_params *params)
|
||||||
params->dp_pre_dump = 1;
|
params->dp_pre_dump = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->dp_buf)
|
|
||||||
memset(params->dp_buf, 0, params->dp_buflen);
|
|
||||||
|
|
||||||
if (obj->ce_ops->oo_dump[type])
|
if (obj->ce_ops->oo_dump[type])
|
||||||
obj->ce_ops->oo_dump[type](obj, params);
|
obj->ce_ops->oo_dump[type](obj, params);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue