1
/* Copyright 2000-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"
24
static apr_status_t setptr(apr_file_t *thefile, unsigned long pos )
29
if (thefile->direction == 1) {
30
apr_status_t rv = apr_file_flush(thefile);
32
if (rv != APR_SUCCESS) {
36
thefile->bufpos = thefile->direction = thefile->dataRead = 0;
39
newbufpos = pos - (thefile->filePtr - thefile->dataRead);
40
if (newbufpos >= 0 && newbufpos <= thefile->dataRead) {
41
thefile->bufpos = newbufpos;
44
rc = DosSetFilePtr(thefile->filedes, pos, FILE_BEGIN, &thefile->filePtr );
47
thefile->bufpos = thefile->dataRead = 0;
50
return APR_FROM_OS_ERROR(rc);
55
APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t where, apr_off_t *offset)
57
if (!thefile->isopen) {
63
if (thefile->buffered) {
69
rc = setptr(thefile, *offset);
73
rc = setptr(thefile, thefile->filePtr - thefile->dataRead + thefile->bufpos + *offset);
77
rc = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile);
78
if (rc == APR_SUCCESS)
79
rc = setptr(thefile, finfo.size + *offset);
83
*offset = thefile->filePtr - thefile->dataRead + thefile->bufpos;
100
return APR_FROM_OS_ERROR(DosSetFilePtr(thefile->filedes, *offset, where, (ULONG *)offset));
106
APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *fp, apr_off_t offset)
108
int rc = DosSetFileSize(fp->filedes, offset);
111
return APR_FROM_OS_ERROR(rc);
115
return setptr(fp, offset);