Annotation of parser3/src/main/pa_common.C, revision 1.5

1.1       paf         1: /*
1.5     ! paf         2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru>
        !             5: 
        !             6:        $Id: pa_string.C,v 1.35 2001/03/10 12:12:51 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifdef HAVE_CONFIG_H
                     10: #      include "pa_config.h"
                     11: #endif
                     12: 
1.2       paf        13: #include <fcntl.h>
                     14: #include <sys/types.h>
                     15: #include <sys/stat.h>
                     16: #include <io.h>
1.1       paf        17: #include <stdio.h>
                     18: 
                     19: #include "pa_common.h"
1.2       paf        20: #include "pa_types.h"
1.4       paf        21: #include "pa_exception.h"
1.1       paf        22: 
                     23: #ifdef WIN32
                     24: 
                     25: int __vsnprintf(char *b, size_t s, const char *f, va_list l) {
                     26:        int r=_vsnprintf(b, --s, f, l);
                     27:        b[s]=0;
                     28:        return r;
                     29: }
                     30: int __snprintf(char *b, size_t s, const char *f, ...) {
                     31:        va_list l;
                     32:     va_start(l, f);
                     33:     int r=__vsnprintf(b, s, f, l);
                     34:     va_end(l);
                     35:        return r;
                     36: }
                     37: 
                     38: #endif
1.2       paf        39: 
1.4       paf        40: char *file_read(Pool& pool, char *fname, bool fail_on_read_problem) {
1.2       paf        41:     int f;
                     42:     struct stat finfo;
                     43:     if (fname && !stat(fname,&finfo) && (f=open(fname,O_RDONLY
                     44: #ifdef WIN32
                     45:                |O_TEXT
                     46: #endif
                     47:                ))>=0){
                     48:                /*if(exclusive)
                     49:                        flock(f, LOCK_EX);*/
                     50: 
                     51:                char *result=static_cast<char *>(pool.malloc(finfo.st_size+1));
                     52:                int read_size=read(f,result,finfo.st_size);
                     53:                if(read_size>=0 && read_size<=finfo.st_size) 
                     54:                        result[read_size]='\0';
                     55:                /*if(exclusive)
                     56:                        flock(f, LOCK_UN);*/
                     57:                close(f);
                     58:                return result;//prepare_config(result, remove_empty_lines);
                     59:     }
1.4       paf        60:        if(fail_on_read_problem)
                     61:                POOL_THROW(0,0,
                     62:                        0,
                     63:                        "use: can not read '%s' file", fname);
1.2       paf        64:     return NULL;
                     65: }

E-mail: