diff options
author | Ian Jackson <ian.jackson@eu.citrix.com> | 2012-01-13 16:54:11 +0000 |
---|---|---|
committer | Ian Jackson <ian.jackson@eu.citrix.com> | 2012-01-13 16:54:11 +0000 |
commit | 3607a75236b37abe350bf52f4700355be963a60d (patch) | |
tree | 202537d0bdc1bd8fab74287d370721fe67f416a3 /tools/xenstore/xs.c | |
parent | 50c5cd458d3afe161f634bab1127508ad3f9afdc (diff) | |
download | xen-3607a75236b37abe350bf52f4700355be963a60d.tar.gz xen-3607a75236b37abe350bf52f4700355be963a60d.tar.bz2 xen-3607a75236b37abe350bf52f4700355be963a60d.zip |
xenstore: New function xs_path_is_subpath
This utility function compares two paths, textually and reports
whether one is a subpath (a child path) of the other.
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/xenstore/xs.c')
-rw-r--r-- | tools/xenstore/xs.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c index 8e54fe01c9..0a01675a78 100644 --- a/tools/xenstore/xs.c +++ b/tools/xenstore/xs.c @@ -950,6 +950,23 @@ char *xs_get_domain_path(struct xs_handle *h, unsigned int domid) return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL); } +bool xs_path_is_subpath(const char *parent, const char *child) +{ + size_t childlen = strlen(child); + size_t parentlen = strlen(parent); + + if (childlen < parentlen) + return false; + + if (memcmp(child, parent, parentlen)) + return false; + + if (childlen > parentlen && child[parentlen] != '/') + return false; + + return true; +} + bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid) { char *domain = single_with_domid(h, XS_IS_DOMAIN_INTRODUCED, domid); |