Apache HTTPD
filesys.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "apr.h"
18#include "apr_arch_file_io.h"
19#include "apr_strings.h"
20
22{
23/* See the Windows code to figure out what to do here.
24 It probably checks to make sure that the root exists
25 and case it correctly according to the file system.
26*/
27 *rootpath = apr_pstrdup(p, root);
28 return APR_SUCCESS;
29}
30
32{
33 char *s;
34
35 if (rootpath) {
36 s = strchr (rootpath, ':');
37 if (only)
38 /* Test if the path only has a drive/volume and nothing else
39 */
40 return (s && (s != rootpath) && !s[1]);
41 else
42 /* Test if the path includes a drive/volume
43 */
44 return (s && (s != rootpath));
45 }
46 return 0;
47}
48
49apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p)
50{
51 char *s1, *s2;
52
53 if (path1 && path2) {
54 s1 = strchr (path1, ':');
55 s2 = strchr (path2, ':');
56
57 /* Make sure that they both have a drive/volume delimiter
58 and are the same size. Then see if they match.
59 */
60 if (s1 && s2 && ((s1-path1) == (s2-path2))) {
61 return strnicmp (s1, s2, s1-path1);
62 }
63 }
64 return -1;
65}
66
69{
70 char path[APR_PATH_MAX];
71 char *ptr;
72
73 /* use getcwdpath to make sure that we get the volume name*/
74 if (!getcwdpath(path, NULL, 0)) {
75 if (errno == ERANGE)
76 return APR_ENAMETOOLONG;
77 else
78 return errno;
79 }
80 /* Strip off the server name if there is one*/
81 ptr = strpbrk(path, "\\/:");
82 if (!ptr) {
83 return APR_ENOENT;
84 }
85 if (*ptr == ':') {
86 ptr = path;
87 }
88 *rootpath = apr_pstrdup(p, ptr);
89 if (!(flags & APR_FILEPATH_NATIVE)) {
90 for (ptr = *rootpath; *ptr; ++ptr) {
91 if (*ptr == '\\')
92 *ptr = '/';
93 }
94 }
95 return APR_SUCCESS;
96}
97
100{
101 if (chdir2(rootpath) != 0)
102 return errno;
103 return APR_SUCCESS;
104}
105
106
APR Strings library.
request_rec int int apr_table_t const char * path
#define APR_ENAMETOOLONG
Definition apr_errno.h:655
#define APR_ENOENT
Definition apr_errno.h:662
const char apr_ssize_t int flags
Definition apr_encode.h:168
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
#define APR_FILEPATH_NATIVE
const char * rootpath
const char * s
Definition apr_strings.h:95
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
Definition filesys.c:21
apr_status_t filepath_compare_drive(const char *path1, const char *path2, apr_pool_t *p)
Definition filesys.c:49
apr_status_t filepath_has_drive(const char *rootpath, int only, apr_pool_t *p)
Definition filesys.c:31