#include "apr.h"
#include "apr_arch_file_io.h"
#include "apr_strings.h"
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
{
*rootpath = apr_pstrdup(p, root);
return APR_SUCCESS;
}
apr_status_t filepath_has_drive(const char *rootpath, int only, apr_pool_t *p)
{
char *s;
if (rootpath) {
s = strchr (rootpath, ':');
if (only)
return (s && (s != rootpath) && !s[1]);
else
return (s && (s != rootpath));
}
return 0;
}
apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p)
{
char *s1, *s2;
if (path1 && path2) {
s1 = strchr (path1, ':');
s2 = strchr (path2, ':');
if (s1 && s2 && ((s1-path1) == (s2-path2))) {
return strnicmp (s1, s2, s1-path1);
}
}
return -1;
}
APR_DECLARE(apr_status_t) apr_filepath_get(char **rootpath, apr_int32_t flags,
apr_pool_t *p)
{
char path[APR_PATH_MAX];
char *ptr;
if (!getcwdpath(path, NULL, 0)) {
if (errno == ERANGE)
return APR_ENAMETOOLONG;
else
return errno;
}
ptr = strpbrk(path, "\\/:");
if (!ptr) {
return APR_ENOENT;
}
if (*ptr == ':') {
ptr = path;
}
*rootpath = apr_pstrdup(p, ptr);
if (!(flags & APR_FILEPATH_NATIVE)) {
for (ptr = *rootpath; *ptr; ++ptr) {
if (*ptr == '\\')
*ptr = '/';
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_filepath_set(const char *rootpath,
apr_pool_t *p)
{
if (chdir2(rootpath) != 0)
return errno;
return APR_SUCCESS;
}