On Wed, 17.04.13 09:33, Peeters Simon (peeters.si...@gmail.com) wrote:

> while reading random patches in cgit I saw
> (in commit 6606089752df90f3eeb4924af109046f1c73554c)
> 
> ...
> > diff --git a/src/shared/util.h b/src/shared/util.h
> > index 3aac165..cfb5493 100644
> > --- a/src/shared/util.h
> > +++ b/src/shared/util.h
> > @@ -684,3 +684,15 @@ int unlink_noerrno(const char *path);
> > _new_ = alloca(_len_); \
> > (void *) memset(_new_, 0, _len_); \
> > })
> > +
> > +#define strappenda(a, b) \
> > + ({ \
> > + const char *_a_ = (a), *_b_ = (b); \
> > + char *_c_; \
> > + size_t _x_, _y_; \
> > + _x_ = strlen(_a_); \
> > + _y_ = strlen(_b_); \
> > + _c_ = alloca(_x_ + _y_ + 1); \
> > + strcpy(stpcpy(_c_, _a_), _b_); \
> 
> shouldn't this be more like:
> strcat(strcpy(_c_, _a_), _b_);

Nah, stpcpy() is the best thing since sliced bread for concatenating
strings. Together with mempcpy() and mempset() it's really useful, and a
ton more efficient than strcat().

strcat() always iterates through the first string to find the end,
before appending, and stpcpy() doesn't need that at all anymore.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to