
On Tue, Feb 23, 2016 at 01:19:38PM +0000, Daniel P. Berrange wrote:
On Thu, Feb 18, 2016 at 07:40:12AM -0500, John Ferlan wrote:
On 02/12/2016 08:59 AM, Ján Tomko wrote:
Just like safewrite, but calls strlen first to figure out the length of the string. --- src/conf/virchrdev.c | 2 +- src/libvirt_private.syms | 1 + src/lxc/lxc_process.c | 4 ++-- src/network/leaseshelper.c | 2 +- src/openvz/openvz_conf.c | 15 ++++++--------- src/qemu/qemu_domain.c | 2 +- src/util/vircommand.c | 4 ++-- src/util/virfile.c | 9 ++++++++- src/util/virfile.h | 1 + src/util/virlog.c | 6 +++--- src/util/virpidfile.c | 4 ++-- src/util/virxml.c | 17 ++++++----------- tools/vsh.c | 4 +--- 13 files changed, 35 insertions(+), 36 deletions(-)
Conflicted about this one - the difference between the two appears to be 'safewrite' will write a some length of a string (e.g. a counted length) while safewrite_str writes the entire string. To make things more interesting some safewrite calls use sizeof instead of strlen, but in reality are just writing everything in the buffer.
So, perhaps 'safewrite_all' or 'safewrite_full' better describes the new functionality?
I don't think we need any new function actually.
Just add this to existing safewrite() method:
if (len == -1) len = strlen(data)
and then update the callers which pass a NULL terminated string to just pass -1. This matches our behaviour with virBuffer APIs which acccept a length of -1.
In fact for the case where the caller passes a literal string we could add #define safewritelit(fd_, literal_string_) \ safewrite(fd_, "" literal_string_ "", sizeof(literal_string_) - 1) which moves the performance hit of strlen() to be compile time instead of runtime. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|