Apache2
apr_arch_file_io.h
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 #ifndef FILE_IO_H
18 #define FILE_IO_H
19 
20 #include "apr.h"
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"
27 #include "apr_lib.h"
28 #include "apr_thread_mutex.h"
29 #ifndef WAITIO_USES_POLL
30 #include "apr_poll.h"
31 #endif
32 #include "apr_time.h"
33 
34 
35 /* System headers the file I/O library needs */
36 #if APR_HAVE_FCNTL_H
37 #include <fcntl.h>
38 #endif
39 #if APR_HAVE_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif
42 #if APR_HAVE_ERRNO_H
43 #include <errno.h>
44 #endif
45 #if APR_HAVE_STRING_H
46 #include <string.h>
47 #endif
48 #if APR_HAVE_STRINGS_H
49 #include <strings.h>
50 #endif
51 #if APR_HAVE_DIRENT_H
52 #include <dirent.h>
53 #endif
54 #ifdef HAVE_SYS_STAT_H
55 #include <sys/stat.h>
56 #endif
57 #if APR_HAVE_UNISTD_H
58 #include <unistd.h>
59 #endif
60 #if APR_HAVE_STDIO_H
61 #include <stdio.h>
62 #endif
63 #if APR_HAVE_STDLIB_H
64 #include <stdlib.h>
65 #endif
66 #if APR_HAVE_SYS_UIO_H
67 #include <sys/uio.h>
68 #endif
69 #if APR_HAVE_SYS_TIME_H
70 #include <sys/time.h>
71 #endif
72 #ifdef BEOS
73 #include <kernel/OS.h>
74 #endif
75 /* Hunting down DEV_BSIZE if not from dirent.h, sys/stat.h etc */
76 #ifdef HAVE_SYS_PARAM_H
77 #include <sys/param.h>
78 #endif
79 
80 #if BEOS_BONE
81 # ifndef BONE7
82  /* prior to BONE/7 fd_set & select were defined in sys/socket.h */
83 # include <sys/socket.h>
84 # else
85  /* Be moved the fd_set stuff and also the FIONBIO definition... */
86 # include <sys/ioctl.h>
87 # endif
88 #endif
89 /* End System headers */
90 
91 #define APR_FILE_DEFAULT_BUFSIZE 4096
92 /* For backwards-compat */
93 #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
94 
95 typedef struct apr_rotating_info_t {
99  int oflags;
100  int manual;
103 
104 struct apr_file_t {
105  apr_pool_t *pool;
106  int filedes;
107  char *fname;
109  int eof_hit;
110  int is_pipe;
112  int buffered;
114  int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/
115 #ifndef WAITIO_USES_POLL
116  /* if there is a timeout set, then this pollset is used */
118 #endif
119  /* Stuff for buffered mode */
120  char *buffer;
121  apr_size_t bufpos; /* Read/Write position in buffer */
122  apr_size_t bufsize; /* The size of the buffer */
123  unsigned long dataRead; /* amount of valid data read into buffer */
124  int direction; /* buffer being used for 0 = read, 1 = write */
125  apr_off_t filePtr; /* position in file of handle */
126 #if APR_HAS_THREADS
127  struct apr_thread_mutex_t *thlock;
128 #endif
130 };
131 
132 #if APR_HAS_THREADS
133 #define file_lock(f) do { \
134  if ((f)->thlock) \
135  apr_thread_mutex_lock((f)->thlock); \
136  } while (0)
137 #define file_unlock(f) do { \
138  if ((f)->thlock) \
139  apr_thread_mutex_unlock((f)->thlock); \
140  } while (0)
141 #else
142 #define file_lock(f) do {} while (0)
143 #define file_unlock(f) do {} while (0)
144 #endif
145 
146 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
147 #define stat(f,b) stat64(f,b)
148 #define lstat(f,b) lstat64(f,b)
149 #define fstat(f,b) fstat64(f,b)
150 #define lseek(f,o,w) lseek64(f,o,w)
151 #define ftruncate(f,l) ftruncate64(f,l)
152 typedef struct stat64 struct_stat;
153 #else
154 typedef struct stat struct_stat;
155 #endif
156 
157 /* readdir64_r is only used in specific cases: */
158 #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
159  && !defined(READDIR_IS_THREAD_SAFE) && defined(HAVE_READDIR64_R)
160 #define APR_USE_READDIR64_R
161 #endif
162 
163 struct apr_dir_t {
164  apr_pool_t *pool;
165  char *dirname;
166  DIR *dirstruct;
167 #ifdef APR_USE_READDIR64_R
168  struct dirent64 *entry;
169 #else
170  struct dirent *entry;
171 #endif
172 };
173 
176 
179 
182  apr_file_t *thefile);
183 
184 
185 #endif /* ! FILE_IO_H */
186 
APR Platform Definitions.
APR Error Codes.
APR File Information.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Poll interface.
APR Table library.
APR Thread Mutex Routines.
APR Time Library.
apr_bucket_brigade ap_input_mode_t mode
Definition: mod_dav.h:2662
int apr_status_t
Definition: apr_errno.h:44
apr_int32_t apr_fileperms_t
Definition: apr_file_info.h:125
int apr_int32_t
Definition: apr.h:347
off_t apr_off_t
Definition: apr.h:396
size_t apr_size_t
Definition: apr.h:394
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
apr_int64_t apr_time_t
Definition: apr_time.h:45
mode_t apr_unix_perms2mode(apr_fileperms_t perms)
struct stat struct_stat
Definition: apr_arch_file_io.h:96
apr_status_t apr_unix_file_cleanup(void *)
struct apr_rotating_info_t apr_rotating_info_t
apr_fileperms_t apr_unix_mode2perms(mode_t mode)
apr_status_t apr_unix_child_file_cleanup(void *)
apr_status_t apr_file_flush_locked(apr_file_t *thefile)
apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted, apr_file_t *thefile)
Definition: apr_arch_file_io.h:135
char * dirname
Definition: apr_arch_file_io.h:137
struct dirent * entry
Definition: apr_arch_file_io.h:139
apr_pool_t * pool
Definition: apr_arch_file_io.h:136
DIR * dirstruct
Definition: apr_arch_file_io.h:138
Definition: apr_arch_file_io.h:107
apr_pollset_t * pollset
Definition: apr_arch_file_io.h:120
int direction
Definition: apr_arch_file_io.h:127
apr_int32_t flags
Definition: apr_arch_file_io.h:111
int is_pipe
Definition: apr_arch_file_io.h:113
apr_interval_time_t timeout
Definition: apr_arch_file_io.h:114
apr_size_t bufpos
Definition: apr_arch_file_io.h:124
apr_off_t filePtr
Definition: apr_arch_file_io.h:128
int filedes
Definition: apr_arch_file_io.h:109
apr_off_t dataRead
Definition: apr_arch_file_io.h:126
int ungetchar
Definition: apr_arch_file_io.h:117
char * buffer
Definition: apr_arch_file_io.h:123
apr_pool_t * pool
Definition: apr_arch_file_io.h:108
@ BLK_OFF
Definition: apr_arch_file_io.h:116
@ BLK_ON
Definition: apr_arch_file_io.h:116
@ BLK_UNKNOWN
Definition: apr_arch_file_io.h:116
apr_rotating_info_t * rotating
Definition: apr_arch_file_io.h:132
struct apr_thread_mutex_t * thlock
Definition: apr_arch_file_io.h:130
char * fname
Definition: apr_arch_file_io.h:110
int buffered
Definition: apr_arch_file_io.h:115
enum apr_file_t::@20 blocking
apr_size_t bufsize
Definition: apr_arch_file_io.h:125
int eof_hit
Definition: apr_arch_file_io.h:112
Definition: apr_file_info.h:174
Definition: apr_arch_poll_private.h:124
Definition: apr_arch_file_io.h:98
apr_interval_time_t timeout
Definition: apr_arch_file_io.h:100
int manual
Definition: apr_arch_file_io.h:103
apr_finfo_t finfo
Definition: apr_arch_file_io.h:99
apr_fileperms_t perm
Definition: apr_arch_file_io.h:104
int oflags
Definition: apr_arch_file_io.h:102
apr_time_t lastcheck
Definition: apr_arch_file_io.h:101
Definition: apr_arch_thread_mutex.h:28