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