util: use glib string allocation/formatting functions

Convert the string duplication APIs to use the g_strdup family of APIs.

We previously used the 'strdup-posix' gnulib module because mingw does
not set errno to ENOMEM on failure

We previously used the 'strndup' gnulib module because this function
does not exist on mingw.

We previously used the 'vasprintf' gnulib module because of many GNU
supported format specifiers not working on non-Linux platforms. glib's
own equivalent standardizes on GNU format specifiers too.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé
2019-09-06 13:10:24 +01:00
parent e85e34f3af
commit bb9a1a14e2
4 changed files with 38 additions and 9 deletions

View File

@@ -1020,6 +1020,14 @@ BAD:
classic libvirt memory allocation APIs and GLib APIs within
a single method. Keep the style consistent, converting existing
code to GLib style in a separate, prior commit.</dd>
<dt>VIR_STRDUP, VIR_STRNDUP</dt>
<dd>Prefer the GLib APIs g_strdup and g_strndup.</dd>
<dt>virAsprintf, virVasprintf</dt>
<dd>The GLib APIs g_strdup_printf / g_strdup_vprint should be used
instead. Don't use g_vasprintf unless having the string length
returned is unavoidable.</dd>
</dl>
<h2><a id="file_handling">File handling</a></h2>