Apache HTTPD
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
25{
26 int rv;
28
29 if (*new_file == NULL) {
31
32 if (dup_file == NULL) {
33 return APR_ENOMEM;
34 }
35
36 dup_file->filedes = -1;
37 } else {
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;
52 /* TODO - dup pipes correctly */
53 dup_file->pipe = old_file->pipe;
54
55 if (*new_file == NULL) {
59 }
60
61 return APR_SUCCESS;
62}
63
64
65
67{
68 if (*new_file) {
70 (*new_file)->filedes = -1;
71 }
72
73 return file_dup(new_file, old_file, p);
74}
75
76
77
79{
80 return file_dup(&new_file, old_file, p);
81}
82
83
84
88{
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),
107 }
108 }
109
110 if (old_file->fname) {
111 (*new_file)->fname = apr_pstrdup(p, old_file->fname);
112 }
113
120 }
121
122 old_file->filedes = -1;
123 return APR_SUCCESS;
124}
APR File I/O Handling.
APR general purpose library routines.
APR Strings library.
#define APR_ENOMEM
Definition apr_errno.h:683
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_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_file_t * old_file
#define APR_FOPEN_NOCLEANUP
Definition apr_file_io.h:74
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
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_status_t apr_file_cleanup(void *thefile)
Definition open.c:25
apr_int32_t flags
apr_size_t bufpos
apr_thread_mutex_t * mutex
apr_off_t dataRead
apr_pool_t * pool
apr_size_t bufsize