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
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.
21 #include "apr_private.h"
22 #include "apr_general.h"
23 #include "apr_tables.h"
24 #include "apr_file_io.h"
25 #include "apr_file_info.h"
26 #include "apr_errno.h"
28 #include "apr_thread_mutex.h"
29 #ifndef WAITIO_USES_POLL
33 /* System headers the file I/O library needs */
37 #if APR_HAVE_SYS_TYPES_H
38 #include <sys/types.h>
46 #if APR_HAVE_STRINGS_H
52 #ifdef HAVE_SYS_STAT_H
64 #if APR_HAVE_SYS_UIO_H
67 #if APR_HAVE_SYS_TIME_H
71 #include <kernel/OS.h>
73 /* Hunting down DEV_BSIZE if not from dirent.h, sys/stat.h etc */
74 #ifdef HAVE_SYS_PARAM_H
75 #include <sys/param.h>
80 /* prior to BONE/7 fd_set & select were defined in sys/socket.h */
81 # include <sys/socket.h>
83 /* Be moved the fd_set stuff and also the FIONBIO definition... */
84 # include <sys/ioctl.h>
87 /* End System headers */
89 #define APR_FILE_DEFAULT_BUFSIZE 4096
90 /* For backwards-compat */
91 #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
100 apr_interval_time_t timeout;
102 enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
103 int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/
104 #ifndef WAITIO_USES_POLL
105 /* if there is a timeout set, then this pollset is used */
106 apr_pollset_t *pollset;
108 /* Stuff for buffered mode */
110 apr_size_t bufpos; /* Read/Write position in buffer */
111 apr_size_t bufsize; /* The size of the buffer */
112 unsigned long dataRead; /* amount of valid data read into buffer */
113 int direction; /* buffer being used for 0 = read, 1 = write */
114 apr_off_t filePtr; /* position in file of handle */
116 struct apr_thread_mutex_t *thlock;
121 #define file_lock(f) do { \
123 apr_thread_mutex_lock((f)->thlock); \
125 #define file_unlock(f) do { \
127 apr_thread_mutex_unlock((f)->thlock); \
130 #define file_lock(f) do {} while (0)
131 #define file_unlock(f) do {} while (0)
134 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
135 #define stat(f,b) stat64(f,b)
136 #define lstat(f,b) lstat64(f,b)
137 #define fstat(f,b) fstat64(f,b)
138 #define lseek(f,o,w) lseek64(f,o,w)
139 #define ftruncate(f,l) ftruncate64(f,l)
140 typedef struct stat64 struct_stat;
142 typedef struct stat struct_stat;
145 /* readdir64_r is only used in specific cases: */
146 #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
147 && !defined(READDIR_IS_THREAD_SAFE) && defined(HAVE_READDIR64_R)
148 #define APR_USE_READDIR64_R
155 #ifdef APR_USE_READDIR64_R
156 struct dirent64 *entry;
158 struct dirent *entry;
162 apr_status_t apr_unix_file_cleanup(void *);
163 apr_status_t apr_unix_child_file_cleanup(void *);
165 mode_t apr_unix_perms2mode(apr_fileperms_t perms);
166 apr_fileperms_t apr_unix_mode2perms(mode_t mode);
168 apr_status_t apr_file_flush_locked(apr_file_t *thefile);
169 apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted,
170 apr_file_t *thefile);
173 #endif /* ! FILE_IO_H */