Annotation of parser3/src/include/pa_file.h, revision 1.1

1.1     ! moko        1: /** @file
        !             2:        Parser: file and file system related functions.
        !             3: 
        !             4:        Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
        !             5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
        !             6: */
        !             7: 
        !             8: #ifndef PA_FILE_H
        !             9: #define PA_FILE_H
        !            10: 
        !            11: #define IDENT_PA_FILE_H "$Id$"
        !            12: 
        !            13: #include "pa_common.h"
        !            14: 
        !            15: #ifdef _MSC_VER
        !            16: 
        !            17: //access
        !            18: #define F_OK 0
        !            19: #define X_OK 1
        !            20: #define W_OK 2
        !            21: #define R_OK 4
        !            22: 
        !            23: #define stat __stat64
        !            24: #define pa_fstat _fstat64
        !            25: 
        !            26: int pa_stat(const char *pathname, struct stat *buffer);
        !            27: int pa_open(const char *pathname, int flags, int mode=0);
        !            28: FILE *pa_fopen(const char *pathname, const char *mode);
        !            29: 
        !            30: #define pa_lseek _lseeki64
        !            31: 
        !            32: #else
        !            33: 
        !            34: #define pa_stat stat
        !            35: #define pa_fstat fstat
        !            36: 
        !            37: #define pa_open open
        !            38: #define pa_fopen fopen
        !            39: 
        !            40: #define pa_lseek lseek
        !            41: 
        !            42: #endif
        !            43: 
        !            44: #ifdef WIN32
        !            45: bool is_os_absolute_path(const String& path);
        !            46: bool is_os_absolute_path(const char* path);
        !            47: #else
        !            48: inline bool is_os_absolute_path(const String&) { return false; }
        !            49: inline bool is_os_absolute_path(const char*) { return false; }
        !            50: #endif
        !            51: 
        !            52: #define FILE_BUFFER_SIZE (128*0x400)
        !            53: 
        !            54: int pa_lock_shared_blocking(int fd);
        !            55: int pa_lock_exclusive_blocking(int fd);
        !            56: int pa_lock_exclusive_nonblocking(int fd);
        !            57: int pa_unlock(int fd);
        !            58: 
        !            59: const char *pa_filename(const char *path);
        !            60: 
        !            61: void create_dir_for_file(const String& file_spec);
        !            62: 
        !            63: int pa_get_valid_file_options_count(HashStringValue& options);
        !            64: 
        !            65: typedef void (*File_read_action)(struct stat& finfo, int f, const String& file_spec, void *context);
        !            66: 
        !            67: /**
        !            68:        shared-lock specified file, 
        !            69:        do actions under lock.
        !            70:        if fail_on_read_problem is true[default] throws an exception
        !            71:        
        !            72:        @returns true if read OK
        !            73: */
        !            74: bool file_read_action_under_lock(const String& file_spec,
        !            75:                                const char* action_name, File_read_action action, void *context,
        !            76:                                bool as_text=false,
        !            77:                                bool fail_on_read_problem=true);
        !            78: 
        !            79: /**
        !            80:        read specified text file
        !            81:        if fail_on_read_problem is true[default] throws an exception
        !            82: 
        !            83:        WARNING: charset is used for http header case conversion, it's not a charset of input file!
        !            84: */
        !            85: char *file_read_text(Request_charsets& charsets, const String& file_spec, bool fail_on_read_problem = true);
        !            86: char *file_load_text(Request& r, const String& file_spec, bool fail_on_read_problem = true, HashStringValue* options = 0, bool transcode_result = true);
        !            87: 
        !            88: struct File_read_result {
        !            89:        bool success;
        !            90:        char* str; size_t length;
        !            91:        HashStringValue* headers;
        !            92: };
        !            93: 
        !            94: // read specified binary file; if fail_on_read_problem is true[default] throws an exception
        !            95: File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem = true, char* buf = 0, uint64_t offset = 0, size_t limit = 0);
        !            96: 
        !            97: // load specified file; if fail_on_read_problem is true[default] throws an exception
        !            98: File_read_result file_load(Request& r, const String& file_spec, bool as_text, HashStringValue* options=0, bool fail_on_read_problem=true, bool transcode_text_result=true);
        !            99: 
        !           100: typedef void (*File_write_action)(int f, void *context);
        !           101: 
        !           102: /**
        !           103:        lock specified file exclusively, do actions under lock.
        !           104:        throws an exception in case of problems
        !           105:        
        !           106:        if block=false does non-blocking lock
        !           107:        @returns true if locked OK, or false if non-blocking locking failed
        !           108: */
        !           109: bool file_write_action_under_lock(
        !           110:                                const String& file_spec,
        !           111:                                const char* action_name,
        !           112:                                File_write_action action,
        !           113:                                void *context,
        !           114:                                bool as_text=false,
        !           115:                                bool do_append=false,
        !           116:                                bool do_block=true,
        !           117:                                bool fail_on_lock_problem=true);
        !           118: 
        !           119: // write data to specified file; throws an exception in case of problems
        !           120: void file_write(
        !           121:                                Request_charsets& charsets,
        !           122:                                const String& file_spec,
        !           123:                                const char* data,
        !           124:                                size_t size,
        !           125:                                bool as_text,
        !           126:                                bool do_append=false,
        !           127:                                Charset* asked_charset=0);
        !           128: 
        !           129: // delete specified file; throws an exception in case of problems
        !           130: bool file_delete(const String& file_spec, bool fail_on_problem=true, bool keep_empty_dirs=false);
        !           131: 
        !           132: // move specified file; throw an exception in case of problems
        !           133: void file_move(const String& old_spec, const String& new_spec, bool keep_empty_dirs=false);
        !           134: 
        !           135: bool entry_exists(const char* fname, struct stat *afinfo=0);
        !           136: bool entry_exists(const String& file_spec);
        !           137: bool file_exist(const String& file_spec);
        !           138: bool dir_exists(const String& file_spec);
        !           139: const String* file_exist(const String& path, const String& name);
        !           140: bool file_executable(const String& file_spec);
        !           141: 
        !           142: bool file_stat(const String& file_spec, uint64_t& rsize, time_t& ratime, time_t& rmtime, time_t& rctime, bool fail_on_read_problem=true);
        !           143: size_t check_file_size(uint64_t size, const String* file_spec);
        !           144: 
        !           145: size_t stdout_write(const void *buf, size_t size);
        !           146: 
        !           147: void check_safe_mode(struct stat finfo, const String& file_spec, const char* fname); 
        !           148: 
        !           149: ssize_t file_block_read(const int f, void* buffer, const size_t size);
        !           150: 
        !           151: #endif

E-mail: