[PATCH] config-parser: Honor the XDG_CONFIG_DIRS environment variable

Othman, Ossama ossama.othman at intel.com
Mon May 13 20:41:59 PDT 2013


Hi Kristian,

I think it's good to go - however, inlining the patch messed up the
> whitespace.  Ideally, send patches using git send-email, which can be
> configured to use smtp servers, and you can pass --annotate if you
> want to add a message or comment to the patch (put it after the ---
> that indicates the end of the commit message).  Or as a last resort,
> attach the patch.
>

I forgot to attach the patch this last time around.  Sorry about that.
 I'll just resend the patch with git send-email, as you suggest.


> As for the next thing, good catch.  I'd do something like
>
>     for (p = config_dirs; p != NULL; p = next) {
>         next = strchrnul(p, ':');
>         if (*next == ':')
>             next++;
>
>         ...
>
> to keep the for (...) more readable.


Changing the loop termination to "p != NULL" causes an infinite loop since
strchnul() returns a pointer to the null character '\0', not the NULL
pointer.  Also, the moving the next pointer past the colon must be done
after path construction, other the colon ends up at the end of the path.
 How's this instead:

for (p = config_dirs; *p != '\0'; p = next) {
next = strchrnul(p, ':');
snprintf(path, sizeof path,
 "%.*s/weston/%s", (int)(next - p), p, name);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
return fd;

if (*next == ':')
next++;
}

Note that I also had to cast "next - p" in the snprintf() call to int since
the format specifier "%*.s" wants an int but the pointer difference on my
64 bit Ubuntu box is a long int, at least according to the format specifier
warning I get:

foo.c: In function ‘open_config_file’:
foo.c:53:5: warning: field precision specifier ‘.*’ expects argument of
type ‘int’, but argument 4 has type ‘long int’ [-Wformat]

foo.c in this case is a simple test program I wrote.  I assume the cast is
safe since "next - p" should always fall within the range of type int.

Anyway, I'll resend the patch with the above changes with git send-email.

Thanks Kristian!
-Ossama
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130513/41f68020/attachment.html>


More information about the wayland-devel mailing list