1
/* Copyright 2002-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* 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.
17
#include "apr_arch_file_io.h"
18
#include "apr_file_io.h"
20
static apr_status_t apr_file_transfer_contents(const char *from_path,
23
apr_fileperms_t to_perms,
29
apr_fileperms_t perms;
31
/* Open source file. */
32
status = apr_file_open(&s, from_path, APR_READ, APR_OS_DEFAULT, pool);
36
/* Maybe get its permissions. */
37
if (to_perms == APR_FILE_SOURCE_PERMS) {
38
status = apr_file_info_get(&finfo, APR_FINFO_PROT, s);
39
if (status != APR_SUCCESS && status != APR_INCOMPLETE) {
40
apr_file_close(s); /* toss any error */
43
perms = finfo.protection;
49
status = apr_file_open(&d, to_path, flags, perms, pool);
51
apr_file_close(s); /* toss any error */
55
/* Copy bytes till the cows come home. */
58
apr_size_t bytes_this_time = sizeof(buf);
59
apr_status_t read_err;
60
apr_status_t write_err;
63
read_err = apr_file_read(s, buf, &bytes_this_time);
64
if (read_err && !APR_STATUS_IS_EOF(read_err)) {
65
apr_file_close(s); /* toss any error */
66
apr_file_close(d); /* toss any error */
71
write_err = apr_file_write_full(d, buf, bytes_this_time, NULL);
73
apr_file_close(s); /* toss any error */
74
apr_file_close(d); /* toss any error */
78
if (read_err && APR_STATUS_IS_EOF(read_err)) {
79
status = apr_file_close(s);
81
apr_file_close(d); /* toss any error */
85
/* return the results of this close: an error, or success */
86
return apr_file_close(d);
92
APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path,
94
apr_fileperms_t perms,
97
return apr_file_transfer_contents(from_path, to_path,
98
(APR_WRITE | APR_CREATE | APR_TRUNCATE),
103
APR_DECLARE(apr_status_t) apr_file_append(const char *from_path,
105
apr_fileperms_t perms,
108
return apr_file_transfer_contents(from_path, to_path,
109
(APR_WRITE | APR_CREATE | APR_APPEND),