uri_absolute_path — determine whether the path in a URI is relative or absolute
URI parsing library (liburi, -luri)
#include <liburi.h>
int uri_absolute_path(
URI *uri)
;
The uri_absolute_path
function determines whether
the path in a parsed URI is absolute or relative. An absolute path is
one begins with a "/
" character.
URIs which do not include a path at all are not considered to be
absolute by this function. Any URI which does include a path and for
which uri_absolute(3) returns
1
will be determined to have an absolute
path. More specifically, any URI which includes either a scheme or a
hostname as well as a path are always considered to have an absolute
path (that is, file:foo
and file:/foo
will give the same results after parsing).
uri
The URI to evaluate.
If successful, uri_absolute_path
returns
1
if uri
contains a URI
with an absolute path, and 0
otherwise.
If an error occurs, uri_absolute
returns
-1
, and sets errno
accordingly.
URI *uri; int result; uri = uri_create_str("http://example.com", NULL); /* result will be 0 because no path is present */ result = uri_absolute_path(uri); uri_destroy(uri); uri = uri_create_str("/project", NULL); /* result will be 1 because an absolute path was parsed */ result = uri_absolute_path(uri); uri_destroy(uri); uri = uri_create_str("results/output", NULL); /* result will be 0 because a relative path was parsed */ result = uri_absolute_path(uri); uri_destroy(uri); uri = uri_create_str("file:output", NULL); /* result will be 1 because a scheme was present, meaning the path * is always interpreted as as being absolute (in this case, "/output") */ result = uri_absolute_path(uri); uri_destroy(uri);
liburi(3), uri_absolute(3).