apr  1.7.0
About: APR (Apache Portable Runtime) project offers software libraries that provide a predictable and consistent interface to underlying platform-specific implementations (APR core library).
  Fossies Dox: apr-1.7.0.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

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 #include "apr_lib.h"
21 #include <ctype.h>
22 
23 /* OS/2 Exceptions:
24  *
25  * Note that trailing spaces and trailing periods are never recorded
26  * in the file system.
27  *
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 ;)
33  */
34 
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,
38  /* " * / : < > ? */
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,
40  /* \ */
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,
42  /* | */
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
49 };
50 
51 
52 #define IS_SLASH(c) (c == '/' || c == '\\')
53 
54 
56 {
57  char drive = apr_toupper(path[0]);
58 
59  if (drive >= 'A' && drive <= 'Z' && path[1] == ':' && IS_SLASH(path[2]))
60  return APR_SUCCESS;
61 
62  return APR_EBADPATH;
63 }
64 
65 
67  apr_int32_t flags, apr_pool_t *p)
68 {
69  char path[APR_PATH_MAX];
70  char *pos;
71  ULONG rc;
72  ULONG bufsize = sizeof(path) - 3;
73 
74  path[0] = drive;
75  path[1] = ':';
76  path[2] = '/';
77 
78  rc = DosQueryCurrentDir(apr_toupper(drive) - 'A', path+3, &bufsize);
79 
80  if (rc) {
81  return APR_FROM_OS_ERROR(rc);
82  }
83 
84  if (!(flags & APR_FILEPATH_NATIVE)) {
85  for (pos=path; *pos; pos++) {
86  if (*pos == '\\')
87  *pos = '/';
88  }
89  }
90 
91  *rootpath = apr_pstrdup(p, path);
92  return APR_SUCCESS;
93 }
94 
95 
97 {
98  if (root[0] && apr_islower(root[0]) && root[1] == ':') {
99  *rootpath = apr_pstrdup(p, root);
100  (*rootpath)[0] = apr_toupper((*rootpath)[0]);
101  }
102  else {
103  *rootpath = root;
104  }
105  return APR_SUCCESS;
106 }
107 
108 
109 APR_DECLARE(apr_status_t) apr_filepath_get(char **defpath, apr_int32_t flags,
110  apr_pool_t *p)
111 {
112  char path[APR_PATH_MAX];
113  ULONG drive;
114  ULONG drivemap;
115  ULONG rv, pathlen = sizeof(path) - 3;
116  char *pos;
117 
118  DosQueryCurrentDisk(&drive, &drivemap);
119  path[0] = '@' + drive;
120  strcpy(path+1, ":\\");
121  rv = DosQueryCurrentDir(drive, path+3, &pathlen);
122 
123  *defpath = apr_pstrdup(p, path);
124 
125  if (!(flags & APR_FILEPATH_NATIVE)) {
126  for (pos=*defpath; *pos; pos++) {
127  if (*pos == '\\')
128  *pos = '/';
129  }
130  }
131 
132  return APR_SUCCESS;
133 }
134 
135 
136 
137 APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p)
138 {
139  ULONG rv = 0;
140 
141  if (path[1] == ':')
142  rv = DosSetDefaultDisk(apr_toupper(path[0]) - '@');
143 
144  if (rv == 0)
145  rv = DosSetCurrentDir(path);
146 
147  return APR_FROM_OS_ERROR(rv);
148 }
APR_FILEPATH_NATIVE
#define APR_FILEPATH_NATIVE
Definition: apr_file_info.h:305
p
const char apr_int32_t apr_pool_t * p
Definition: apr_file_info.h:337
apr_strings.h
APR Strings library.
IS_SLASH
#define IS_SLASH(c)
Definition: filesys.c:52
rootpath
const char * rootpath
Definition: apr_file_info.h:355
c_is_fnchar
const char c_is_fnchar[256]
Definition: filesys.c:35
APR_DECLARE
APR_DECLARE(apr_status_t)
Definition: filesys.c:67
apr_lib.h
APR general purpose library routines.
apr_islower
#define apr_islower(c)
Definition: apr_lib.h:213
path
const char * path
Definition: apr_escape.h:187
apr_pool_t
Definition: apr_pools.c:577
apr_status_t
int apr_status_t
Definition: apr_errno.h:44
apr_toupper
#define apr_toupper(c)
Definition: apr_lib.h:233
APR_SUCCESS
#define APR_SUCCESS
Definition: apr_errno.h:225
filepath_root_case
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
Definition: filesys.c:21
bufsize
char apr_size_t bufsize
Definition: apr_errno.h:52
APR_EBADPATH
#define APR_EBADPATH
Definition: apr_errno.h:332
filepath_root_test
apr_status_t filepath_root_test(char *path, apr_pool_t *p)
Definition: filesys.c:55
flags
const char apr_ssize_t int flags
Definition: apr_encode.h:162
filepath_drive_get
apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p)
Definition: filesys.c:66
APR_FROM_OS_ERROR
#define APR_FROM_OS_ERROR(e)
Definition: apr_errno.h:1214