📄 apr_file_io.h
字号:
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#ifndef APR_FILE_IO_H#define APR_FILE_IO_H/** * @file apr_file_io.h * @brief APR File I/O Handling */#include "apr.h"#include "apr_pools.h"#include "apr_time.h"#include "apr_errno.h"#include "apr_file_info.h"#include "apr_inherit.h"#define APR_WANT_STDIO /**< for SEEK_* */#define APR_WANT_IOVEC /**< for apr_file_writev */#include "apr_want.h"#ifdef __cplusplusextern "C" {#endif /* __cplusplus *//** * @defgroup apr_file_io File I/O Handling Functions * @ingroup APR * @{ *//** * @defgroup apr_file_open_flags File Open Flags/Routines * @{ *//* Note to implementors: Values in the range 0x00100000--0x80000000 are reserved for platform-specific values. */#define APR_FOPEN_READ 0x00001 /**< Open the file for reading */#define APR_FOPEN_WRITE 0x00002 /**< Open the file for writing */#define APR_FOPEN_CREATE 0x00004 /**< Create the file if not there */#define APR_FOPEN_APPEND 0x00008 /**< Append to the end of the file */#define APR_FOPEN_TRUNCATE 0x00010 /**< Open the file and truncate to 0 length */#define APR_FOPEN_BINARY 0x00020 /**< Open the file in binary mode */#define APR_FOPEN_EXCL 0x00040 /**< Open should fail if APR_CREATE and file exists. */#define APR_FOPEN_BUFFERED 0x00080 /**< Open the file for buffered I/O */#define APR_FOPEN_DELONCLOSE 0x00100 /**< Delete the file after close */#define APR_FOPEN_XTHREAD 0x00200 /**< Platform dependent tag to open the file for use across multiple threads */#define APR_FOPEN_SHARELOCK 0x00400 /**< Platform dependent support for higher level locked read/write access to support writes across process/machines */#define APR_FOPEN_NOCLEANUP 0x00800 /**< Do not register a cleanup when the file is opened */#define APR_FOPEN_SENDFILE_ENABLED 0x01000 /**< Advisory flag that this file should support apr_socket_sendfile operation */#define APR_FOPEN_LARGEFILE 0x04000 /**< Platform dependent flag to enable * large file support, see WARNING below */#define APR_FOPEN_SPARSE 0x08000 /**< Platform dependent flag to enable * sparse file support, see WARNING below *//* backcompat */#define APR_READ APR_FOPEN_READ /**< @deprecated @see APR_FOPEN_READ */#define APR_WRITE APR_FOPEN_WRITE /**< @deprecated @see APR_FOPEN_WRITE */ #define APR_CREATE APR_FOPEN_CREATE /**< @deprecated @see APR_FOPEN_CREATE */ #define APR_APPEND APR_FOPEN_APPEND /**< @deprecated @see APR_FOPEN_APPEND */ #define APR_TRUNCATE APR_FOPEN_TRUNCATE /**< @deprecated @see APR_FOPEN_TRUNCATE */ #define APR_BINARY APR_FOPEN_BINARY /**< @deprecated @see APR_FOPEN_BINARY */ #define APR_EXCL APR_FOPEN_EXCL /**< @deprecated @see APR_FOPEN_EXCL */ #define APR_BUFFERED APR_FOPEN_BUFFERED /**< @deprecated @see APR_FOPEN_BUFFERED */ #define APR_DELONCLOSE APR_FOPEN_DELONCLOSE /**< @deprecated @see APR_FOPEN_DELONCLOSE */ #define APR_XTHREAD APR_FOPEN_XTHREAD /**< @deprecated @see APR_FOPEN_XTHREAD */ #define APR_SHARELOCK APR_FOPEN_SHARELOCK /**< @deprecated @see APR_FOPEN_SHARELOCK */ #define APR_FILE_NOCLEANUP APR_FOPEN_NOCLEANUP /**< @deprecated @see APR_FOPEN_NOCLEANUP */ #define APR_SENDFILE_ENABLED APR_FOPEN_SENDFILE_ENABLED /**< @deprecated @see APR_FOPEN_SENDFILE_ENABLED */ #define APR_LARGEFILE APR_FOPEN_LARGEFILE /**< @deprecated @see APR_FOPEN_LARGEFILE */ /** @warning APR_FOPEN_LARGEFILE flag only has effect on some * platforms where sizeof(apr_off_t) == 4. Where implemented, it * allows opening and writing to a file which exceeds the size which * can be represented by apr_off_t (2 gigabytes). When a file's size * does exceed 2Gb, apr_file_info_get() will fail with an error on the * descriptor, likewise apr_stat()/apr_lstat() will fail on the * filename. apr_dir_read() will fail with APR_INCOMPLETE on a * directory entry for a large file depending on the particular * APR_FINFO_* flags. Generally, it is not recommended to use this * flag. * * @warning APR_FOPEN_SPARSE may, depending on platform, convert a * normal file to a sparse file. Some applications may be unable * to decipher a sparse file, so it's critical that the sparse file * flag should only be used for files accessed only by APR or other * applications known to be able to decipher them. APR does not * guarentee that it will compress the file into sparse segments * if it was previously created and written without the sparse flag. * On platforms which do not understand, or on file systems which * cannot handle sparse files, the flag is ignored by apr_file_open(). *//** @} *//** * @defgroup apr_file_seek_flags File Seek Flags * @{ *//* flags for apr_file_seek *//** Set the file position */#define APR_SET SEEK_SET/** Current */#define APR_CUR SEEK_CUR/** Go to end of file */#define APR_END SEEK_END/** @} *//** * @defgroup apr_file_attrs_set_flags File Attribute Flags * @{ *//* flags for apr_file_attrs_set */#define APR_FILE_ATTR_READONLY 0x01 /**< File is read-only */#define APR_FILE_ATTR_EXECUTABLE 0x02 /**< File is executable */#define APR_FILE_ATTR_HIDDEN 0x04 /**< File is hidden *//** @} *//** * @defgroup apr_file_writev{_full} max iovec size * @{ */#if defined(DOXYGEN)#define APR_MAX_IOVEC_SIZE 1024 /**< System dependent maximum size of an iovec array */#elif defined(IOV_MAX)#define APR_MAX_IOVEC_SIZE IOV_MAX#elif defined(MAX_IOVEC)#define APR_MAX_IOVEC_SIZE MAX_IOVEC#else#define APR_MAX_IOVEC_SIZE 1024#endif/** @} *//** File attributes */typedef apr_uint32_t apr_fileattrs_t;/** Type to pass as whence argument to apr_file_seek. */typedef int apr_seek_where_t;/** * Structure for referencing files. */typedef struct apr_file_t apr_file_t;/* File lock types/flags *//** * @defgroup apr_file_lock_types File Lock Types * @{ */#define APR_FLOCK_SHARED 1 /**< Shared lock. More than one process or thread can hold a shared lock at any given time. Essentially, this is a "read lock", preventing writers from establishing an exclusive lock. */#define APR_FLOCK_EXCLUSIVE 2 /**< Exclusive lock. Only one process may hold an exclusive lock at any given time. This is analogous to a "write lock". */#define APR_FLOCK_TYPEMASK 0x000F /**< mask to extract lock type */#define APR_FLOCK_NONBLOCK 0x0010 /**< do not block while acquiring the file lock *//** @} *//** * Open the specified file. * @param newf The opened file descriptor. * @param fname The full path to the file (using / on all systems) * @param flag Or'ed value of: * <PRE> * APR_READ open for reading * APR_WRITE open for writing * APR_CREATE create the file if not there * APR_APPEND file ptr is set to end prior to all writes * APR_TRUNCATE set length to zero if file exists * APR_BINARY not a text file (This flag is ignored on * UNIX because it has no meaning) * APR_BUFFERED buffer the data. Default is non-buffered * APR_EXCL return error if APR_CREATE and file exists * APR_DELONCLOSE delete the file after closing. * APR_XTHREAD Platform dependent tag to open the file * for use across multiple threads * APR_SHARELOCK Platform dependent support for higher * level locked read/write access to support * writes across process/machines * APR_FILE_NOCLEANUP Do not register a cleanup with the pool * passed in on the <EM>pool</EM> argument (see below). * The apr_os_file_t handle in apr_file_t will not * be closed when the pool is destroyed. * APR_SENDFILE_ENABLED Open with appropriate platform semantics * for sendfile operations. Advisory only, * apr_socket_sendfile does not check this flag. * </PRE> * @param perm Access permissions for file. * @param pool The pool to use. * @remark If perm is APR_OS_DEFAULT and the file is being created, * appropriate default permissions will be used. * @remark By default, the returned file descriptor will not be * inherited by child processes created by apr_proc_create(). This * can be changed using apr_file_inherit_set(). */APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **newf, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *pool);/** * Close the specified file. * @param file The file descriptor to close. */APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file);/** * Delete the specified file. * @param path The full path to the file (using / on all systems) * @param pool The pool to use. * @remark If the file is open, it won't be removed until all * instances are closed. */APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool);/** * Rename the specified file. * @param from_path The full path to the original file (using / on all systems) * @param to_path The full path to the new file (using / on all systems) * @param pool The pool to use. * @warning If a file exists at the new location, then it will be * overwritten. Moving files or directories across devices may not be * possible. */APR_DECLARE(apr_status_t) apr_file_rename(const char *from_path, const char *to_path, apr_pool_t *pool);/** * Copy the specified file to another file. * @param from_path The full path to the original file (using / on all systems) * @param to_path The full path to the new file (using / on all systems) * @param perms Access permissions for the new file if it is created. * In place of the usual or'd combination of file permissions, the * value APR_FILE_SOURCE_PERMS may be given, in which case the source * file's permissions are copied. * @param pool The pool to use. * @remark The new file does not need to exist, it will be created if required. * @warning If the new file already exists, its contents will be overwritten. */APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path, const char *to_path, apr_fileperms_t perms, apr_pool_t *pool);/** * Append the specified file to another file. * @param from_path The full path to the source file (use / on all systems) * @param to_path The full path to the destination file (use / on all systems) * @param perms Access permissions for the destination file if it is created. * In place of the usual or'd combination of file permissions, the * value APR_FILE_SOURCE_PERMS may be given, in which case the source * file's permissions are copied. * @param pool The pool to use. * @remark The new file does not need to exist, it will be created if required. */APR_DECLARE(apr_status_t) apr_file_append(const char *from_path, const char *to_path, apr_fileperms_t perms, apr_pool_t *pool);/** * Are we at the end of the file * @param fptr The apr file we are testing. * @remark Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise. */APR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr);/** * Open standard error as an apr file pointer. * @param thefile The apr file to use as stderr.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -