[systemd-devel] typo? path-util: unify code for detecting OS trees
Peeters Simon
peeters.simon at gmail.com
Wed Apr 17 10:27:22 PDT 2013
>> 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().
oh, did no know about that one, it indeed seems to be the best thing
since sliced bread then.
My apologies for the noise.
More information about the systemd-devel
mailing list