MCPcopy Create free account
hub / github.com/acl-dev/acl / parse_xml_file

Function parse_xml_file

lib_acl/samples/xml/xml7/xml.c:5–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "lib_acl.h"
4
5static int parse_xml_file(const char *filepath)
6{
7 int n;
8 acl_int64 len;
9 char buf[10240];
10 ACL_VSTREAM *in = acl_vstream_fopen(filepath, O_RDONLY, 0600, 8192);
11 const char* outfile = "./out.xml";
12 ACL_VSTREAM *out = acl_vstream_fopen(outfile, O_RDWR | O_CREAT | O_TRUNC, 0600, 8192);
13 ACL_XML2 *xml;
14 const char *mmap_file = "./local.map";
15 const char* ptr;
16
17 if (in == NULL) {
18 printf("open %s error %s\r\n", filepath, acl_last_serror());
19 return -1;
20 }
21
22 if (out == NULL)
23 {
24 printf("open %s error %s\r\n", outfile, acl_last_serror());
25 acl_vstream_close(in);
26 return -1;
27 }
28
29 len = acl_vstream_fsize(in);
30 if (len <= 0) {
31 printf("fsize %s error %s\r\n", filepath, acl_last_serror());
32 acl_vstream_close(in);
33 acl_vstream_close(out);
34 return -1;
35 }
36
37 acl_vstream_printf(">>>file(%s)'s size: %lld\r\n", filepath, len);
38
39 len *= 4;
40
41 xml = acl_xml2_mmap_file(mmap_file, len, 10, NULL);
42
43 len = 0;
44 while (1) {
45 n = acl_vstream_read(in, buf, sizeof(buf) - 1);
46 if (n == ACL_VSTREAM_EOF)
47 break;
48 buf[n] = 0;
49 acl_xml2_update(xml, buf);
50 len += n;
51 }
52
53 acl_vstream_close(in);
54
55 acl_vstream_printf(">>read size: %lld\r\n", len);
56
57 ptr = acl_xml2_build(xml);
58 if (ptr == NULL)
59 printf("acl_xml2_build error\r\n");
60
61 len = acl_vstring_end(xml->vbuf) - ptr;
62 acl_vstream_printf(">>>build xml's size:%lld, strlen: %ld\r\n",

Callers 1

mainFunction · 0.70

Calls 11

acl_vstream_fopenFunction · 0.85
acl_last_serrorFunction · 0.85
acl_vstream_closeFunction · 0.85
acl_vstream_fsizeFunction · 0.85
acl_vstream_printfFunction · 0.85
acl_xml2_mmap_fileFunction · 0.85
acl_vstream_readFunction · 0.85
acl_xml2_updateFunction · 0.85
acl_xml2_buildFunction · 0.85
acl_vstream_writenFunction · 0.85
acl_xml2_freeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…