diff options
author | Michal Privoznik <mprivozn@redhat.com> | 2013-04-03 14:51:20 +0200 |
---|---|---|
committer | Michal Privoznik <mprivozn@redhat.com> | 2013-05-05 12:08:54 +0200 |
commit | c3abb5c45988a0d7583f059974513722d82e2c2b (patch) | |
tree | 366577b16e98c0e805058c8edae8d69dedc6579a /HACKING | |
parent | b1434b36b14daa9e410cd8293afd386c84ed315d (diff) | |
download | libvirt-c3abb5c45988a0d7583f059974513722d82e2c2b.tar.gz |
virstring: Introduce VIR_STRDUP and VIR_STRNDUP
The code adaptation is not done right now, but in subsequent patches.
Hence I am not implementing syntax-check rule as it would break
compilation. Developers are strongly advised to use these new macros.
They are similar to VIR_ALLOC() logic: VIR_STRDUP(dst, src) returns zero
on success, -1 otherwise. In case you don't want to report OOM error,
use the _QUIET variant of a macro.
Diffstat (limited to 'HACKING')
-rw-r--r-- | HACKING | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -719,6 +719,17 @@ sizeof(dest) returns something meaningful). Note that this is a macro, so arguments could be evaluated more than once. This is equivalent to virStrncpy(dest, src, strlen(src), sizeof(dest)). + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); + +You should avoid using strdup or strndup directly as they do not report +out-of-memory error. Use VIR_STRDUP or VIR_STRNDUP macros instead. Note, that +these two behave similar to VIR_ALLOC: on success zero is returned, otherwise +the result is -1 and dst is guaranteed to be NULL. 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. + Variable length string buffer ============================= |