Annotation of parser3/src/main/pa_common.C, revision 1.3
1.1 paf 1: /*
1.3 ! paf 2: $Id: pa_common.C,v 1.2 2001/02/20 18:45:53 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.1 paf 17:
18: #ifdef WIN32
19:
20: int __vsnprintf(char *b, size_t s, const char *f, va_list l) {
21: int r=_vsnprintf(b, --s, f, l);
22: b[s]=0;
23: return r;
24: }
25: int __snprintf(char *b, size_t s, const char *f, ...) {
26: va_list l;
27: va_start(l, f);
28: int r=__vsnprintf(b, s, f, l);
29: va_end(l);
30: return r;
31: }
32:
33: #endif
1.2 paf 34:
35: char *file_read(Pool& pool, char *fname) {
36: int f;
37: struct stat finfo;
38: if (fname && !stat(fname,&finfo) && (f=open(fname,O_RDONLY
39: #ifdef WIN32
40: |O_TEXT
41: #endif
42: ))>=0){
43: /*if(exclusive)
44: flock(f, LOCK_EX);*/
45:
46: char *result=static_cast<char *>(pool.malloc(finfo.st_size+1));
47: int read_size=read(f,result,finfo.st_size);
48: if(read_size>=0 && read_size<=finfo.st_size)
49: result[read_size]='\0';
50: /*if(exclusive)
51: flock(f, LOCK_UN);*/
52: close(f);
53: return result;//prepare_config(result, remove_empty_lines);
54: }
55: return NULL;
56: }
E-mail: