[PATCH 10/16] docs: hacking: document preferred strdup alternatives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recommend g_str(n)dup instead of VIR_STRDUP.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 docs/hacking.html.in | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index d4f1c2baad..d6a4f04ad0 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -1274,18 +1274,14 @@ BAD:
     </p>
 
 <pre>
-  VIR_STRDUP(char *dst, const char *src);
-  VIR_STRNDUP(char *dst, const char *src, size_t n);
+    dst = g_strcpy(src);
+    dst = g_strncpy(src, n)
 </pre>
     <p>
-      You should avoid using strdup or strndup directly as they do not report
-      out-of-memory error, and do not allow a NULL source. Use
-      VIR_STRDUP or VIR_STRNDUP macros instead, which return 0 for
-      NULL source, 1 for successful copy, and -1 for allocation
-      failure with the error already reported. In very
-      specific cases, when you don't want to report the out-of-memory error, you
-      can use VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare
-      and usually considered a flaw.
+      You should avoid using strdup or strndup directly as they do not handle
+      out-of-memory errors, and do not allow a NULL source.
+      Use <code>g_strcpy</code> and <code>g_strncpy</code> from GLib which
+      abort on OOM and handle NULL source by returning NULL.
     </p>
 
     <h2><a id="strbuf">Variable length string buffer</a></h2>
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux