1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include "apr_file_io.h"
19
#include "apr_strings.h"
22
#define IS_SEP(c) (c == '/' || c == '\\')
24
/* Remove trailing separators that don't affect the meaning of PATH. */
25
static const char *path_canonicalize(const char *path, apr_pool_t *pool)
27
/* At some point this could eliminate redundant components. For
28
* now, it just makes sure there is no trailing slash. */
29
apr_size_t len = strlen(path);
30
apr_size_t orig_len = len;
32
while ((len > 0) && IS_SEP(path[len - 1])) {
36
if (len != orig_len) {
37
return apr_pstrndup(pool, path, len);
46
/* Remove one component off the end of PATH. */
47
static char *path_remove_last_component(const char *path, apr_pool_t *pool)
49
const char *newpath = path_canonicalize(path, pool);
52
for (i = strlen(newpath) - 1; i >= 0; i--) {
53
if (IS_SEP(path[i])) {
58
return apr_pstrndup(pool, path, (i < 0) ? 0 : i);
63
apr_status_t apr_dir_make_recursive(const char *path, apr_fileperms_t perm,
66
apr_status_t apr_err = APR_SUCCESS;
68
apr_err = apr_dir_make(path, perm, pool); /* Try to make PATH right out */
70
if (APR_STATUS_IS_EEXIST(apr_err)) { /* It's OK if PATH exists */
74
if (APR_STATUS_IS_ENOENT(apr_err)) { /* Missing an intermediate dir */
77
dir = path_remove_last_component(path, pool);
78
apr_err = apr_dir_make_recursive(dir, perm, pool);
81
apr_err = apr_dir_make(path, perm, pool);