* Changed first parameter from int fd to FILE *f in the following functions:
* clixon_xml_parse_file(), clixon_json_parse_file(), yang_parse_file() * See [Bytewise read() of files is slow #146](https://github.com/clicon/clixon/issues/146)
This commit is contained in:
parent
7a0838da3a
commit
c31b1c471b
21 changed files with 113 additions and 99 deletions
|
|
@ -186,7 +186,6 @@ nacm_load_external(clicon_handle h)
|
|||
cxobj *xt = NULL;
|
||||
struct stat st;
|
||||
FILE *f = NULL;
|
||||
int fd;
|
||||
|
||||
filename = clicon_option_str(h, "CLICON_NACM_FILE");
|
||||
if (filename == NULL || strlen(filename)==0){
|
||||
|
|
@ -209,9 +208,8 @@ nacm_load_external(clicon_handle h)
|
|||
goto done;
|
||||
if (yang_spec_parse_module(h, "ietf-netconf-acm", NULL, yspec) < 0)
|
||||
goto done;
|
||||
fd = fileno(f);
|
||||
/* Read configfile */
|
||||
if (clixon_xml_parse_file(fd, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
if (clixon_xml_parse_file(f, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
if (xt == NULL){
|
||||
clicon_err(OE_XML, 0, "No xml tree in %s", filename);
|
||||
|
|
|
|||
|
|
@ -168,17 +168,17 @@ load_extraxml(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
int fd = -1;
|
||||
FILE *fp = NULL;
|
||||
yang_stmt *yspec = NULL;
|
||||
|
||||
if (filename == NULL)
|
||||
return 1;
|
||||
if ((fd = open(filename, O_RDONLY)) < 0){
|
||||
if ((fp = fopen(filename, "r")) < 0){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if (clixon_xml_parse_file(fd, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
if (clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
/* Replace parent w first child */
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
|
|
@ -186,8 +186,8 @@ load_extraxml(clicon_handle h,
|
|||
/* Merge user reset state */
|
||||
retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret);
|
||||
done:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -771,7 +771,7 @@ load_config_file(clicon_handle h,
|
|||
cg_var *cv;
|
||||
char *opstr;
|
||||
char *varstr;
|
||||
int fd = -1;
|
||||
FILE *fp = NULL;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *x;
|
||||
cbuf *cbxml;
|
||||
|
|
@ -804,11 +804,11 @@ load_config_file(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
/* Open and parse local file into xml */
|
||||
if ((fd = open(filename, O_RDONLY)) < 0){
|
||||
if ((fp = fopen(filename, "r")) < 0){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &xt, NULL) < 0)
|
||||
if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
if (xt == NULL)
|
||||
goto done;
|
||||
|
|
@ -831,8 +831,8 @@ load_config_file(clicon_handle h,
|
|||
done:
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue