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
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.
18 #include "apr_arch_file_io.h"
19 #include "apr_strings.h"
25 * Note that trailing spaces and trailing periods are never recorded
28 * Leading spaces and periods are accepted, however.
29 * The * ? < > codes all have wildcard side effects
30 * The " / \ : are exclusively component separator tokens
31 * The system doesn't accept | for any (known) purpose
32 * Oddly, \x7f _is_ acceptable ;)
35 const char c_is_fnchar[256] =
36 {/* Reject all ctrl codes... */
37 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39 1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,0, 1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,
41 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
43 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
44 /* High bit codes are accepted */
45 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
46 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
47 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
48 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
52 #define IS_SLASH(c) (c == '/' || c == '\\')
55 apr_status_t filepath_root_test(char *path, apr_pool_t *p)
57 char drive = apr_toupper(path[0]);
59 if (drive >= 'A' && drive <= 'Z' && path[1] == ':' && IS_SLASH(path[2]))
66 apr_status_t filepath_drive_get(char **rootpath, char drive,
67 apr_int32_t flags, apr_pool_t *p)
69 char path[APR_PATH_MAX];
72 ULONG bufsize = sizeof(path) - 3;
78 rc = DosQueryCurrentDir(apr_toupper(drive) - 'A', path+3, &bufsize);
81 return APR_FROM_OS_ERROR(rc);
84 if (!(flags & APR_FILEPATH_NATIVE)) {
85 for (pos=path; *pos; pos++) {
91 *rootpath = apr_pstrdup(p, path);
96 apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
98 if (root[0] && apr_islower(root[0]) && root[1] == ':') {
99 *rootpath = apr_pstrdup(p, root);
100 (*rootpath)[0] = apr_toupper((*rootpath)[0]);
109 APR_DECLARE(apr_status_t) apr_filepath_get(char **defpath, apr_int32_t flags,
112 char path[APR_PATH_MAX];
115 ULONG rv, pathlen = sizeof(path) - 3;
118 DosQueryCurrentDisk(&drive, &drivemap);
119 path[0] = '@' + drive;
120 strcpy(path+1, ":\\");
121 rv = DosQueryCurrentDir(drive, path+3, &pathlen);
123 *defpath = apr_pstrdup(p, path);
125 if (!(flags & APR_FILEPATH_NATIVE)) {
126 for (pos=*defpath; *pos; pos++) {
137 APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p)
142 rv = DosSetDefaultDisk(apr_toupper(path[0]) - '@');
145 rv = DosSetCurrentDir(path);
147 return APR_FROM_OS_ERROR(rv);