]> git.ipfire.org Git - thirdparty/libvirt.git/commit
string: make VIR_STRDUP easier to use
authorEric Blake <eblake@redhat.com>
Tue, 7 May 2013 02:42:44 +0000 (20:42 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 7 May 2013 19:21:31 +0000 (13:21 -0600)
commit6b74a9f5d98e066f8dfdf5d5ccda68230b516246
tree57fd3040d6767dd252de321d5e95219e8342a74c
parentddcfc5492a118624793a6ed48ee9afb5769fc0fb
string: make VIR_STRDUP easier to use

While reviewing proposed VIR_STRDUP conversions, I've already noticed
several places that do:

if (str && VIR_STRDUP(dest, str) < 0)

which can be simplified by allowing str to be NULL (something that
strdup() doesn't allow).  Meanwhile, code that wants to ensure a
non-NULL dest regardless of the source can check for <= 0.

Also, make it part of the VIR_STRDUP contract that macro arguments
are evaluated exactly once.

* src/util/virstring.h (VIR_STRDUP, VIR_STRDUP_QUIET, VIR_STRNDUP)
(VIR_STRNDUP_QUIET): Improve contract.
* src/util/virstring.c (virStrdup, virStrndup): Change return
conventions.
* docs/hacking.html.in: Document this.
* HACKING: Regenerate.

Signed-off-by: Eric Blake <eblake@redhat.com>
HACKING
docs/hacking.html.in
src/util/virstring.c
src/util/virstring.h