Apache HTTPD
framework
httpd-2.4.62
srclib
apr
file_io
os2
filedup.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_strings.h
"
21
#include <string.h>
22
#include "apr_arch_inherit.h"
23
24
static
apr_status_t
file_dup
(
apr_file_t
**
new_file
,
apr_file_t
*
old_file
,
apr_pool_t
*
p
)
25
{
26
int
rv;
27
apr_file_t
*
dup_file
;
28
29
if
(*
new_file
==
NULL
) {
30
dup_file
= (
apr_file_t
*)
apr_palloc
(
p
,
sizeof
(
apr_file_t
));
31
32
if
(
dup_file
==
NULL
) {
33
return
APR_ENOMEM
;
34
}
35
36
dup_file
->
filedes
= -1;
37
}
else
{
38
dup_file
= *
new_file
;
39
}
40
41
dup_file
->pool =
p
;
42
rv =
DosDupHandle
(
old_file
->
filedes
, &
dup_file
->filedes);
43
44
if
(rv) {
45
return
APR_FROM_OS_ERROR
(rv);
46
}
47
48
dup_file
->fname =
apr_pstrdup
(
dup_file
->pool,
old_file
->
fname
);
49
dup_file
->buffered =
old_file
->
buffered
;
50
dup_file
->isopen =
old_file
->
isopen
;
51
dup_file
->flags =
old_file
->
flags
&
~APR_INHERIT
;
52
/* TODO - dup pipes correctly */
53
dup_file
->pipe =
old_file
->
pipe
;
54
55
if
(*
new_file
==
NULL
) {
56
apr_pool_cleanup_register
(
dup_file
->pool,
dup_file
,
apr_file_cleanup
,
57
apr_pool_cleanup_null
);
58
*
new_file
=
dup_file
;
59
}
60
61
return
APR_SUCCESS
;
62
}
63
64
65
66
APR_DECLARE
(
apr_status_t
)
apr_file_dup
(
apr_file_t
**
new_file
,
apr_file_t
*
old_file
,
apr_pool_t
*
p
)
67
{
68
if
(*
new_file
) {
69
apr_file_close
(*
new_file
);
70
(*new_file)->filedes = -1;
71
}
72
73
return
file_dup
(
new_file
,
old_file
,
p
);
74
}
75
76
77
78
APR_DECLARE
(
apr_status_t
)
apr_file_dup2
(
apr_file_t
*
new_file
,
apr_file_t
*
old_file
,
apr_pool_t
*
p
)
79
{
80
return
file_dup
(&
new_file
,
old_file
,
p
);
81
}
82
83
84
85
APR_DECLARE
(
apr_status_t
)
apr_file_setaside
(
apr_file_t
**
new_file
,
86
apr_file_t
*
old_file
,
87
apr_pool_t
*
p
)
88
{
89
*
new_file
= (
apr_file_t
*)
apr_pmemdup
(
p
,
old_file
,
sizeof
(
apr_file_t
));
90
(*new_file)->pool =
p
;
91
92
if
(
old_file
->
buffered
) {
93
(*new_file)->buffer =
apr_palloc
(
p
,
old_file
->
bufsize
);
94
(*new_file)->bufsize =
old_file
->
bufsize
;
95
96
if
(
old_file
->
direction
== 1) {
97
memcpy
((*new_file)->buffer,
old_file
->
buffer
,
old_file
->
bufpos
);
98
}
99
else
{
100
memcpy
((*new_file)->buffer,
old_file
->
buffer
,
old_file
->
dataRead
);
101
}
102
103
if
(
old_file
->
mutex
) {
104
apr_thread_mutex_create
(&((*new_file)->mutex),
105
APR_THREAD_MUTEX_DEFAULT
,
p
);
106
apr_thread_mutex_destroy
(
old_file
->
mutex
);
107
}
108
}
109
110
if
(
old_file
->
fname
) {
111
(*new_file)->fname =
apr_pstrdup
(
p
,
old_file
->
fname
);
112
}
113
114
if
(!(
old_file
->
flags
&
APR_FOPEN_NOCLEANUP
)) {
115
apr_pool_cleanup_kill
(
old_file
->
pool
, (
void
*)
old_file
,
116
apr_file_cleanup
);
117
apr_pool_cleanup_register
(
p
, (
void
*)(*
new_file
),
118
apr_file_cleanup
,
119
apr_file_cleanup
);
120
}
121
122
old_file
->
filedes
= -1;
123
return
APR_SUCCESS
;
124
}
apr_file_io.h
APR File I/O Handling.
apr_lib.h
APR general purpose library routines.
apr_strings.h
APR Strings library.
APR_ENOMEM
#define APR_ENOMEM
Definition
apr_errno.h:683
APR_DECLARE
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
size
apr_size_t size
Definition
apr_allocator.h:115
APR_FROM_OS_ERROR
#define APR_FROM_OS_ERROR(e)
Definition
apr_errno.h:1214
APR_SUCCESS
#define APR_SUCCESS
Definition
apr_errno.h:225
apr_status_t
int apr_status_t
Definition
apr_errno.h:44
old_file
apr_file_t * old_file
Definition
apr_file_io.h:625
APR_FOPEN_NOCLEANUP
#define APR_FOPEN_NOCLEANUP
Definition
apr_file_io.h:74
p
apr_pool_t * p
Definition
md_event.c:32
NULL
return NULL
Definition
mod_so.c:359
file_dup
static apr_status_t file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_pool_t *p)
Definition
filedup.c:24
apr_file_cleanup
apr_status_t apr_file_cleanup(void *thefile)
Definition
open.c:25
apr_file_t
Definition
apr_arch_file_io.h:97
apr_file_t::direction
int direction
Definition
apr_arch_file_io.h:117
apr_file_t::flags
apr_int32_t flags
Definition
apr_arch_file_io.h:101
apr_file_t::bufpos
apr_size_t bufpos
Definition
apr_arch_file_io.h:114
apr_file_t::pipe
int pipe
Definition
apr_arch_file_io.h:46
apr_file_t::isopen
int isopen
Definition
apr_arch_file_io.h:41
apr_file_t::mutex
apr_thread_mutex_t * mutex
Definition
apr_arch_file_io.h:57
apr_file_t::filedes
int filedes
Definition
apr_arch_file_io.h:99
apr_file_t::dataRead
apr_off_t dataRead
Definition
apr_arch_file_io.h:116
apr_file_t::buffer
char * buffer
Definition
apr_arch_file_io.h:113
apr_file_t::pool
apr_pool_t * pool
Definition
apr_arch_file_io.h:98
apr_file_t::fname
char * fname
Definition
apr_arch_file_io.h:100
apr_file_t::buffered
int buffered
Definition
apr_arch_file_io.h:105
apr_file_t::bufsize
apr_size_t bufsize
Definition
apr_arch_file_io.h:115
apr_pool_t
Definition
apr_pools.c:562
Generated by
1.9.8