[lxc-devel] [PATCH 4/6] utils: Add string and array utility functions

Christian Seiler christian at iwakd.de
Tue Sep 10 13:59:26 UTC 2013


Hi Serge,

> However, a comment about
> +/* Normalize and split path: Leading and trailing / are removed, multiple
> + * / are compactified, .. and . are resolved (.. on the top level is considered
> + * identical to .).
> + * Examples:
> + *     /            ->   { NULL }
> + *     foo/../bar   ->   { bar, NULL }
> + *     ../../       ->   { NULL }
> + *     ./bar/baz/.. ->   { bar, NULL }
> + *     foo//bar     ->   { foo, bar, NULL }
> + */
> +extern char **lxc_normalize_path(const char *path);
> 
> That's fine for what you're doing with cgroup paths, but given the
> function name people might want to start using it for general pathnames.
> If they do, they'll need to separately check path[0] to determine
> whether the normalized path was absolute or not.
> 
> Maybe the comment you have here is clear enough to warn anyone against
> getting confused...  I'm just a bit worried it could bite us later.

I'd be more worried if the function just returned a simple string, i.e.
/foo/.../bar -> foo/bar or so. But since the function also splits it
into components (I've done that because it's more convenient for then
iteratively creating a bunch of directories), the return type itself
should be something that makes people look at the function in more
detail before using it - and they should see the comment. But if you
think the comment needs clarification or maybe you want to rename the
function to be lxc_normalize_and_split_path() or so, I don't have any
objections.

-- Christian




More information about the lxc-devel mailing list