GME  13
apr_arch_file_io.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef FILE_IO_H
00018 #define FILE_IO_H
00019 
00020 #include "apr.h"
00021 #include "apr_private.h"
00022 #include "apr_general.h"
00023 #include "apr_tables.h"
00024 #include "apr_file_io.h"
00025 #include "apr_file_info.h"
00026 #include "apr_errno.h"
00027 #include "apr_lib.h"
00028 #include "apr_thread_mutex.h"
00029 #ifndef WAITIO_USES_POLL
00030 #include "apr_poll.h"
00031 #endif
00032 
00033 /* System headers the file I/O library needs */
00034 #if APR_HAVE_FCNTL_H
00035 #include <fcntl.h>
00036 #endif
00037 #if APR_HAVE_SYS_TYPES_H
00038 #include <sys/types.h>
00039 #endif
00040 #if APR_HAVE_ERRNO_H
00041 #include <errno.h>
00042 #endif
00043 #if APR_HAVE_STRING_H
00044 #include <string.h>
00045 #endif
00046 #if APR_HAVE_STRINGS_H
00047 #include <strings.h>
00048 #endif
00049 #if APR_HAVE_DIRENT_H
00050 #include <dirent.h>
00051 #endif
00052 #ifdef HAVE_SYS_STAT_H
00053 #include <sys/stat.h>
00054 #endif
00055 #if APR_HAVE_UNISTD_H
00056 #include <unistd.h>
00057 #endif
00058 #if APR_HAVE_STDIO_H
00059 #include <stdio.h>
00060 #endif
00061 #if APR_HAVE_STDLIB_H
00062 #include <stdlib.h>
00063 #endif
00064 #if APR_HAVE_SYS_UIO_H
00065 #include <sys/uio.h>
00066 #endif
00067 #if APR_HAVE_SYS_TIME_H
00068 #include <sys/time.h>
00069 #endif
00070 #ifdef BEOS
00071 #include <kernel/OS.h>
00072 #endif
00073 /* Hunting down DEV_BSIZE if not from dirent.h, sys/stat.h etc */
00074 #ifdef HAVE_SYS_PARAM_H
00075 #include <sys/param.h>
00076 #endif
00077 
00078 #if BEOS_BONE
00079 # ifndef BONE7
00080   /* prior to BONE/7 fd_set & select were defined in sys/socket.h */
00081 #  include <sys/socket.h>
00082 # else
00083   /* Be moved the fd_set stuff and also the FIONBIO definition... */
00084 #  include <sys/ioctl.h>
00085 # endif
00086 #endif
00087 /* End System headers */
00088 
00089 #define APR_FILE_DEFAULT_BUFSIZE 4096
00090 /* For backwards-compat */
00091 #define APR_FILE_BUFSIZE  APR_FILE_DEFAULT_BUFSIZE
00092 
00093 struct apr_file_t {
00094     apr_pool_t *pool;
00095     int filedes;
00096     char *fname;
00097     apr_int32_t flags;
00098     int eof_hit;
00099     int is_pipe;
00100     apr_interval_time_t timeout;
00101     int buffered;
00102     enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
00103     int ungetchar;    /* Last char provided by an unget op. (-1 = no char)*/
00104 #ifndef WAITIO_USES_POLL
00105     /* if there is a timeout set, then this pollset is used */
00106     apr_pollset_t *pollset;
00107 #endif
00108     /* Stuff for buffered mode */
00109     char *buffer;
00110     apr_size_t bufpos;        /* Read/Write position in buffer */
00111     apr_size_t bufsize;       /* The size of the buffer */
00112     unsigned long dataRead;   /* amount of valid data read into buffer */
00113     int direction;            /* buffer being used for 0 = read, 1 = write */
00114     apr_off_t filePtr;        /* position in file of handle */
00115 #if APR_HAS_THREADS
00116     struct apr_thread_mutex_t *thlock;
00117 #endif
00118 };
00119 
00120 #if APR_HAS_THREADS
00121 #define file_lock(f)   do { \
00122                            if ((f)->thlock) \
00123                                apr_thread_mutex_lock((f)->thlock); \
00124                        } while (0)
00125 #define file_unlock(f) do { \
00126                            if ((f)->thlock) \
00127                                apr_thread_mutex_unlock((f)->thlock); \
00128                        } while (0)
00129 #else
00130 #define file_lock(f)   do {} while (0)
00131 #define file_unlock(f) do {} while (0)
00132 #endif
00133 
00134 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
00135 #define stat(f,b) stat64(f,b)
00136 #define lstat(f,b) lstat64(f,b)
00137 #define fstat(f,b) fstat64(f,b)
00138 #define lseek(f,o,w) lseek64(f,o,w)
00139 #define ftruncate(f,l) ftruncate64(f,l)
00140 typedef struct stat64 struct_stat;
00141 #else
00142 typedef struct stat struct_stat;
00143 #endif
00144 
00145 /* readdir64_r is only used in specific cases: */
00146 #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
00147     && !defined(READDIR_IS_THREAD_SAFE) && defined(HAVE_READDIR64_R)
00148 #define APR_USE_READDIR64_R
00149 #endif
00150 
00151 struct apr_dir_t {
00152     apr_pool_t *pool;
00153     char *dirname;
00154     DIR *dirstruct;
00155 #ifdef APR_USE_READDIR64_R
00156     struct dirent64 *entry;
00157 #else
00158     struct dirent *entry;
00159 #endif
00160 };
00161 
00162 apr_status_t apr_unix_file_cleanup(void *);
00163 apr_status_t apr_unix_child_file_cleanup(void *);
00164 
00165 mode_t apr_unix_perms2mode(apr_fileperms_t perms);
00166 apr_fileperms_t apr_unix_mode2perms(mode_t mode);
00167 
00168 apr_status_t apr_file_flush_locked(apr_file_t *thefile);
00169 apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted,
00170                                       apr_file_t *thefile);
00171 
00172 
00173 #endif  /* ! FILE_IO_H */
00174