MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlResolvePath

Function xmlResolvePath

ThirdParty/libxml2/vtklibxml2/uri.c:1900–1991  ·  view source on GitHub ↗

* xmlResolvePath: * @ref: the filesystem path * @base: the base value * @out: pointer to result URI * * Resolves a filesystem path from a base path. * * Returns 0 on success, -1 if a memory allocation failed or an error * code if URI or base are invalid. */

Source from the content-addressed store, hash-verified

1898 * code if URI or base are invalid.
1899 */
1900static int
1901xmlResolvePath(const xmlChar *escRef, const xmlChar *base, xmlChar **out) {
1902 const xmlChar *fragment;
1903 xmlChar *tmp = NULL;
1904 xmlChar *ref = NULL;
1905 xmlChar *result = NULL;
1906 int ret = -1;
1907 int i;
1908
1909 if (out == NULL)
1910 return(1);
1911 *out = NULL;
1912
1913 if ((escRef == NULL) || (escRef[0] == 0)) {
1914 if ((base == NULL) || (base[0] == 0))
1915 return(1);
1916 ref = xmlStrdup(base);
1917 if (ref == NULL)
1918 goto err_memory;
1919 *out = ref;
1920 return(0);
1921 }
1922
1923 /*
1924 * If a URI is resolved, we can assume it is a valid URI and not
1925 * a filesystem path. This means we have to unescape the part
1926 * before the fragment.
1927 */
1928 fragment = xmlStrchr(escRef, '#');
1929 if (fragment != NULL) {
1930 tmp = xmlStrndup(escRef, fragment - escRef);
1931 if (tmp == NULL)
1932 goto err_memory;
1933 escRef = tmp;
1934 }
1935
1936 ref = (xmlChar *) xmlURIUnescapeString((char *) escRef, -1, NULL);
1937 if (ref == NULL)
1938 goto err_memory;
1939
1940 if ((base == NULL) || (base[0] == 0))
1941 goto done;
1942
1943 if (xmlIsAbsolutePath(ref))
1944 goto done;
1945
1946 /*
1947 * Remove last segment from base
1948 */
1949 i = xmlStrlen(base);
1950 while ((i > 0) && !xmlIsPathSeparator(base[i-1], 1))
1951 i--;
1952
1953 /*
1954 * Concatenate base and ref
1955 */
1956 if (i > 0) {
1957 int refLen = xmlStrlen(ref);

Callers 1

xmlBuildURISafeFunction · 0.85

Calls 9

xmlStrdupFunction · 0.85
xmlStrchrFunction · 0.85
xmlStrndupFunction · 0.85
xmlURIUnescapeStringFunction · 0.85
xmlIsAbsolutePathFunction · 0.85
xmlStrlenFunction · 0.85
xmlIsPathSeparatorFunction · 0.85
xmlNormalizePathFunction · 0.85
xmlStrcatFunction · 0.85

Tested by

no test coverage detected