📄 apr_file_io.h
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */#ifndef APR_FILE_IO_H#define APR_FILE_IO_H#include "apr.h"#include "apr_pools.h"#include "apr_time.h"#include "apr_errno.h"#include "apr_file_info.h"#define APR_WANT_STDIO /* for SEEK_* */#define APR_WANT_IOVEC#include "apr_want.h"#ifdef __cplusplusextern "C" {#endif /* __cplusplus *//** * @package APR File handling *//* Flags for apr_file_open */#define APR_READ 1 /* Open the file for reading */#define APR_WRITE 2 /* Open the file for writing */#define APR_CREATE 4 /* Create the file if not there */#define APR_APPEND 8 /* Append to the end of the file */#define APR_TRUNCATE 16 /* Open the file and truncate to 0 length */#define APR_BINARY 32 /* Open the file in binary mode */#define APR_EXCL 64 /* Open should fail if APR_CREATE and file exists. */#define APR_BUFFERED 128 /* Open the file for buffered I/O */#define APR_DELONCLOSE 256 /* Delete the file after close */#define APR_XTHREAD 512 /* Platform dependent tag to open the file for use across multiple threads *//* flags for apr_file_seek */#define APR_SET SEEK_SET#define APR_CUR SEEK_CUR#define APR_END SEEK_END/* should be same as whence type in lseek, POSIX defines this as int */typedef apr_int32_t apr_seek_where_t;/** * Structure for referencing files. * @defvar apr_file_t */typedef struct apr_file_t apr_file_t;/* File lock types/flags */#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 new_file 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. * </PRE> * @param perm Access permissions for file. * @param cont The pool to use. * @deffunc apr_status_t apr_file_open(apr_file_t **new_file, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *cont) * @tip If perm is APR_OS_DEFAULT and the file is being created, appropriate * default permissions will be used. *arg1 must point to a valid file_t, * or NULL (in which case it will be allocated) */APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new_file, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *cont);/** * Close the specified file. * @param file The file descriptor to close. * @deffunc apr_status_t apr_file_close(apr_file_t *file) */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 cont The pool to use. * @deffunc apr_status_t apr_file_remove(const char *path, apr_pool_t *cont) * @tip 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 *cont);/** * 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. * @tip If a file exists at the new location, then it will be overwritten. * Moving files or directories across devices may not be possible. * @deffunc apr_status_t apr_file_rename(const char *from_path, const char *to_path, apr_pool_t *pool) */APR_DECLARE(apr_status_t) apr_file_rename(const char *from_path, const char *to_path, apr_pool_t *pool);/** * Are we at the end of the file * @param fptr The apr file we are testing. * @tip Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise. * @deffunc apr_status_t apr_file_eof(apr_file_t *fptr) */APR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr);/** * Is there an error on the stream? * @param fptr The apr file we are testing. * @tip Returns -1 if the error indicator is set, APR_SUCCESS otherwise. * @deffunc apr_status_t apr_file_error(apr_file_t *fptr) */APR_DECLARE(apr_status_t) apr_file_error(apr_file_t *fptr);/** * open standard error as an apr file pointer. * @param thefile The apr file to use as stderr. * @param cont The pool to allocate the file out of. * @deffunc apr_status_t apr_file_open_stderr(apr_file_t **thefile, apr_pool_t *cont) */APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, apr_pool_t *cont);/** * open standard output as an apr file pointer. * @param thefile The apr file to use as stdout. * @param cont The pool to allocate the file out of. * @deffunc apr_status_t apr_file_open_stdout(apr_file_t **thefile, apr_pool_t *cont) */APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, apr_pool_t *cont);/** * Read data from the specified file. * @param thefile The file descriptor to read from. * @param buf The buffer to store the data to. * @param nbytes On entry, the number of bytes to read; on exit, the number of bytes read. * @tip apr_file_read will read up to the specified number of bytes, but never * more. If there isn't enough data to fill that number of bytes, all * of the available data is read. The third argument is modified to * reflect the number of bytes read. If a char was put back into the * stream via ungetc, it will be the first character returned. * * It is possible for both bytes to be read and an APR_EOF or other * error to be returned. * * APR_EINTR is never returned. * @deffunc apr_status_t apr_file_read(apr_file_t *thefile, void *buf, apr_size_t *nbytes) */APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size_t *nbytes);/** * Write data to the specified file. * @param thefile The file descriptor to write to. * @param buf The buffer which contains the data. * @param nbytes On entry, the number of bytes to write; on exit, the number * of bytes written. * @tip apr_file_write will write up to the specified number of bytes, but never * more. If the OS cannot write that many bytes, it will write as many * as it can. The third argument is modified to reflect the * number * of bytes written. * * It is possible for both bytes to be written and an error to be returned. * * APR_EINTR is never returned. * @deffunc apr_status_t apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes) */APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes);/** * Write data from iovec array to the specified file. * @param thefile The file descriptor to write to. * @param vec The array from which to get the data to write to the file. * @param nvec The number of elements in the struct iovec array. This must * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function * will fail with APR_EINVAL. * @param nbytes The number of bytes written. * @tip It is possible for both bytes to be written and an error to be returned. * APR_EINTR is never returned. * * apr_file_writev is available even if the underlying operating system * * doesn't provide writev(). * @deffunc apr_status_t apr_file_writev(apr_file_t *thefile, const struct iovec *vec, apr_size_t nvec, apr_size_t *nbytes) */APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec *vec, apr_size_t nvec, apr_size_t *nbytes);/** * Read data from the specified file, ensuring that the buffer is filled * before returning. * @param thefile The file descriptor to read from. * @param buf The buffer to store the data to. * @param nbytes The number of bytes to read. * @param bytes_read If non-NULL, this will contain the number of bytes read.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -