[Libvir] PATCH 2/4: Xen driver support for serial/paralle
jim at meyering.net
Mon Apr 28 09:28:06 UTC 2008
"Daniel P. Berrange" <berrange at redhat.com> wrote:
> On Thu, Apr 24, 2008 at 10:42:34PM +0200, Jim Meyering wrote:
>> "Daniel P. Berrange" <berrange at redhat.com> wrote:
>> It'd be nice to avoid the riskily redundant length,
>> by using a STR* macro that requires a literal string S
>> as argument #2, and uses sizeof(S)-1 as the length argument.
> I defined a new convenience function STRPREFIX(str, prefix)
> which applies strlen(prefix) so we avoid the hardcoding.
> I didn't use sizeof(prefix) because someone might pass a
> non-literal string as the prefix and thta would endup as
> sizeof(char*) rather than the real length.
FYI, with a macro, you can ensure it's a literal by concatenating
the empty string, e.g.,
#define virBufferAddLit(buf_, literal_string_) \
__virBufferAdd (buf_, "" literal_string_ "", sizeof literal_string_ - 1)
but maybe it's not worth being tricky when compilers
are smart enough to convert strlen("literal") to 7.
More information about the libvir-list