[systemd-devel] [PATCH] fstab-generator: default to "ro"

Lennart Poettering lennart at poettering.net
Fri Mar 1 09:47:14 PST 2013


On Fri, 01.03.13 18:38, Harald Hoyer (harald.hoyer at gmail.com) wrote:

> >>>> Btw, strjoin() should really handle empty strings as the first argument.
> >>>>
> >>>> strjoin(NULL, ",", "TEST") should result in "TEST" .. shouldn't it?
> >>>>
> >>>> strjoin("", ",", "TEST") ?
> >>>
> >>> We use NULL as the sentinel here for the varargs list. It just stupidly
> >>> concatenates the strings you pass it, one after the other, until we hit
> >>> NULL. If you pass NULL as first arg, then we'd just stop there...
> >>>
> >>> There's strempty() which turns NULL into ""?
> >>>
> >>> Lennart
> >>>
> >>
> >> Still:
> >> strjoin("", ",", "TEST") returns ",TEST" then..
> > 
> > No, that call will crash, since you forgot the NULL sentinel. Examples:
> > 
> > strjoin("", ",", "TEST", NULL) → ",TEST"
> > strjoin("a", "b", "c", NULL) → "abc"
> > strjoin("a", "b", "c", "d", NULL) → "abcd"
> > strjoin("a", "b", "c", "d", "e", NULL) → "abcde"
> > strjoin(NULL) → ""
> > strjoin("", "", "", NULL) → ""
> > strjoin("abc", "xyz", NULL) → "abcxyz"
> > strjoin("abc", NULL, "xyz") → "abc"
> > 
> > That's just trivially simple concatenation, ending at the first
> > NULL. Not sure what you expect instead?
> > 
> > Lennart
> > 
> 
> Oops :) had the wrong thing in my mind :)
> 
> join an array of strings with a separator

Ah, I see. Might make sense to have a strjoin_sep() or so which takes as
first arg the separator string to place between each arg. So far we
didn't need that anywhere... But if this is useful it would totally make
sense to add to src/shared/util.[ch]...

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list