Annotation of parser3/src/lib/sdbm/apr-impl/apr_file_io.C, revision 1.1

1.1     ! paf         1: /** @file
        !             2:        Parser: implementation of apr functions.
        !             3: 
        !             4:        Copyright(c) 2003 ArtLebedev Group (http://www.artlebedev.com)
        !             5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
        !             6: */
        !             7: 
        !             8: static const char* IDENT="$Date: 2003/11/03 11:24:53 $";
        !             9: 
        !            10: #include "apr_file_io.h"
        !            11: 
        !            12: #include "pa_memory.h"
        !            13: #include "pa_os.h"
        !            14: 
        !            15: struct apr_file_t: public PA_Cleaned {
        !            16:     int handle;
        !            17: 
        !            18:        ~apr_file_t() {
        !            19:                if(handle>0) {
        !            20:                        close(handle);  handle=-1;
        !            21:                }
        !            22:        }
        !            23: };
        !            24: 
        !            25: APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new_file, const char *fname,
        !            26:                                    apr_int32_t flag, apr_fileperms_t perm,
        !            27:                                                                   apr_pool_t *cont)
        !            28: {
        !            29:     int oflags = 0;
        !            30: #if APR_HAS_THREADS
        !            31:     apr_status_t rv;
        !            32: #endif
        !            33: 
        !            34:     (*new_file) = new apr_file_t;
        !            35: //    (*new_file)->flags = flag;
        !            36:     (*new_file)->handle = -1;
        !            37: 
        !            38:     if ((flag & APR_READ) && (flag & APR_WRITE)) {
        !            39:         oflags = O_RDWR;
        !            40:     }
        !            41:     else if (flag & APR_READ) {
        !            42:         oflags = O_RDONLY;
        !            43:     }
        !            44:     else if (flag & APR_WRITE) {
        !            45:         oflags = O_WRONLY;
        !            46:     }
        !            47:     else {
        !            48:         return APR_EACCES; 
        !            49:     }
        !            50: 
        !            51:        if (flag & APR_CREATE) {
        !            52:         oflags |= O_CREAT; 
        !            53:         if (flag & APR_EXCL) {
        !            54:             oflags |= O_EXCL;
        !            55:         }
        !            56:     }
        !            57:     if ((flag & APR_EXCL) && !(flag & APR_CREATE)) {
        !            58:         return APR_EACCES;
        !            59:     }   
        !            60: 
        !            61:     if (flag & APR_APPEND) {
        !            62:         oflags |= O_APPEND;
        !            63:     }
        !            64:     if (flag & APR_TRUNCATE) {
        !            65:         oflags |= O_TRUNC;
        !            66:     }
        !            67: #ifdef O_BINARY
        !            68:     if (flag & APR_BINARY) {
        !            69:         oflags |= O_BINARY;
        !            70:     }
        !            71: #endif
        !            72:     
        !            73:        (*new_file)->handle = open(fname, oflags, /*apr_unix_perms2mode*/(perm));
        !            74:     return APR_SUCCESS;
        !            75: }
        !            76: 
        !            77: APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file)
        !            78: {
        !            79:        delete file;
        !            80:        return APR_SUCCESS;
        !            81: }
        !            82: 
        !            83: APR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *file, int type)
        !            84: {
        !            85:        if(type & APR_FLOCK_NONBLOCK)
        !            86:                pa_lock_exclusive_nonblocking(file->handle);
        !            87: 
        !            88:        if ((type & APR_FLOCK_TYPEMASK) == APR_FLOCK_SHARED)
        !            89:                return pa_lock_shared_blocking(file->handle);
        !            90: 
        !            91:        return pa_lock_exclusive_blocking(file->handle);
        !            92: }
        !            93: 
        !            94: APR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *file)
        !            95: {
        !            96:        return pa_unlock(file->handle);
        !            97: }
        !            98: 
        !            99: APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, 
        !           100:                                           apr_int32_t wanted,
        !           101:                                           apr_file_t *file)
        !           102: {
        !           103:        return APR_SUCCESS;
        !           104: }
        !           105: 
        !           106: 
        !           107: APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *file, 
        !           108:                                    apr_seek_where_t where,
        !           109:                                    apr_off_t *offset)
        !           110: {
        !           111:        return APR_SUCCESS;
        !           112: }
        !           113: 
        !           114: 
        !           115: APR_DECLARE(apr_status_t) apr_file_read_full(apr_file_t *file, void *buf,
        !           116:                                         apr_size_t nbytes,
        !           117:                                         apr_size_t *bytes_read)
        !           118: {
        !           119:        return APR_SUCCESS;
        !           120: }
        !           121: 
        !           122: 
        !           123: APR_DECLARE(apr_status_t) apr_file_write_full(apr_file_t *file, const void *buf,
        !           124:                                          apr_size_t nbytes, 
        !           125:                                          apr_size_t *bytes_written)
        !           126: {
        !           127:        return APR_SUCCESS;
        !           128: }

E-mail: