Apache HTTPD
open.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_arch_file_io.h"
18#include "apr_file_io.h"
19#include "apr_lib.h"
20#include "apr_portable.h"
21#include "apr_strings.h"
22#include "apr_arch_inherit.h"
23#include <string.h>
24
30
31
32
34{
35 int oflags = 0;
37 int rv;
38 ULONG action;
40
42 return APR_ENOTIMPL;
43 }
44
45 dafile->pool = pool;
46 dafile->isopen = FALSE;
47 dafile->eof_hit = FALSE;
48 dafile->buffer = NULL;
49 dafile->flags = flag;
50 dafile->blocking = BLK_ON;
51
52 if ((flag & APR_FOPEN_READ) && (flag & APR_FOPEN_WRITE)) {
54 } else if (flag & APR_FOPEN_READ) {
56 } else if (flag & APR_FOPEN_WRITE) {
58 } else {
59 dafile->filedes = -1;
60 return APR_EACCES;
61 }
62
63 dafile->buffered = (flag & APR_FOPEN_BUFFERED) > 0;
64
65 if (dafile->buffered) {
68 rv = apr_thread_mutex_create(&dafile->mutex, 0, pool);
69
70 if (rv)
71 return rv;
72 }
73
74 if (flag & APR_FOPEN_CREATE) {
76
77 if (!(flag & APR_FOPEN_EXCL) && !(flag & APR_FOPEN_TRUNCATE)) {
79 }
80 }
81
83 return APR_EACCES;
84
87 } else if ((oflags & 0xFF) == 0) {
89 }
90
91 rv = DosOpen(fname, &(dafile->filedes), &action, 0, 0, oflags, mflags, NULL);
92
93 if (rv == 0 && (flag & APR_FOPEN_APPEND)) {
95 rv = DosSetFilePtr(dafile->filedes, 0, FILE_END, &newptr );
96
97 if (rv)
98 DosClose(dafile->filedes);
99 }
100
101 if (rv != 0)
102 return APR_FROM_OS_ERROR(rv);
103
104 dafile->isopen = TRUE;
105 dafile->fname = apr_pstrdup(pool, fname);
106 dafile->filePtr = 0;
107 dafile->bufpos = 0;
108 dafile->dataRead = 0;
109 dafile->direction = 0;
110 dafile->pipe = FALSE;
111
112 if (!(flag & APR_FOPEN_NOCLEANUP)) {
114 }
115
116 *new = dafile;
117 return APR_SUCCESS;
118}
119
120
121
123{
124 ULONG rc;
126
127 if (file && file->isopen) {
128 /* XXX: flush here is not mutex protected */
131
132 if (rc == 0) {
133 file->isopen = FALSE;
134
137 }
138 /* else we return the status of the flush attempt
139 * when all else succeeds
140 */
141 } else {
142 return APR_FROM_OS_ERROR(rc);
143 }
144 }
145
146 if (file->buffered)
148
149 return status;
150}
151
152
153
155{
157 return APR_FROM_OS_ERROR(rc);
158}
159
160
161
163 apr_pool_t *p)
164{
166
169
170 if (rc == 0 || rc == ERROR_FILE_NOT_FOUND) {
172 }
173 }
174
175 return APR_FROM_OS_ERROR(rc);
176}
177
178
179
181{
182 *thefile = file->filedes;
183 return APR_SUCCESS;
184}
185
186
187
189{
191
192 (*file) = apr_palloc(pool, sizeof(apr_file_t));
193 (*file)->pool = pool;
194 (*file)->filedes = *dafile;
195 (*file)->isopen = TRUE;
196 (*file)->eof_hit = FALSE;
197 (*file)->flags = flags;
198 (*file)->pipe = FALSE;
199 (*file)->buffered = (flags & APR_FOPEN_BUFFERED) > 0;
200
201 if ((*file)->buffered) {
202 apr_status_t rv;
203
204 (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
205 (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
206 rv = apr_thread_mutex_create(&(*file)->mutex, 0, pool);
207
208 if (rv)
209 return rv;
210 }
211
212 return APR_SUCCESS;
213}
214
215
217{
218 if (!fptr->isopen || fptr->eof_hit == 1) {
219 return APR_EOF;
220 }
221 return APR_SUCCESS;
222}
223
224
228{
229 apr_os_file_t fd = 2;
230
232}
233
234
238{
239 apr_os_file_t fd = 1;
240
242}
243
244
248{
249 apr_os_file_t fd = 0;
250
252}
253
254
256{
258}
259
260
262{
264}
265
266
268{
270}
271
273
274
275
277{
278 int rv;
279 ULONG state;
280
281 rv = DosQueryFHState(thefile->filedes, &state);
282
283 if (rv == 0 && (state & OPEN_FLAGS_NOINHERIT) != 0) {
285 }
286
287 return APR_FROM_OS_ERROR(rv);
288}
289
290
291
293{
294 int rv;
295 ULONG state;
296
297 rv = DosQueryFHState(thefile->filedes, &state);
298
299 if (rv == 0 && (state & OPEN_FLAGS_NOINHERIT) == 0) {
301 }
302
303 return APR_FROM_OS_ERROR(rv);
304}
#define TRUE
Definition abts.h:38
#define FALSE
Definition abts.h:35
APR File I/O Handling.
APR general purpose library routines.
APR Portability Routines.
APR Strings library.
request_rec int int apr_table_t const char * path
#define APR_EOF
Definition apr_errno.h:461
#define APR_EACCES
Definition apr_errno.h:641
#define APR_ENOTIMPL
Definition apr_errno.h:476
apr_file_t * fd
const char apr_ssize_t int flags
Definition apr_encode.h:168
apr_redis_t * rc
Definition apr_redis.h:173
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
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_FROM_OS_ERROR(e)
Definition apr_errno.h:1214
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_int32_t apr_fileperms_t
apr_file_t * thefile
const char apr_int32_t flag
const char apr_file_t * file
const char * to_path
const char apr_int32_t apr_fileperms_t perm
#define APR_FOPEN_TRUNCATE
Definition apr_file_io.h:58
#define APR_FOPEN_NONBLOCK
Definition apr_file_io.h:88
#define APR_FOPEN_NOCLEANUP
Definition apr_file_io.h:74
#define APR_FOPEN_APPEND
Definition apr_file_io.h:57
#define APR_FOPEN_DELONCLOSE
Definition apr_file_io.h:66
#define APR_FOPEN_EXCL
Definition apr_file_io.h:63
#define APR_FOPEN_BUFFERED
Definition apr_file_io.h:65
#define APR_FOPEN_WRITE
Definition apr_file_io.h:55
#define APR_FOPEN_READ
Definition apr_file_io.h:54
#define APR_FOPEN_CREATE
Definition apr_file_io.h:56
const char * fname
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
int apr_os_file_t
int int status
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
#define APR_FILE_DEFAULT_BUFSIZE
apr_status_t apr_file_cleanup(void *thefile)
Definition open.c:25
apr_int32_t flags
apr_thread_mutex_t * mutex
apr_pool_t * pool