* 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:
Olof hagsand 2020-11-04 22:21:42 +01:00
parent 7a0838da3a
commit c31b1c471b
21 changed files with 113 additions and 99 deletions

View file

@ -438,7 +438,7 @@ xmldb_readfile(clicon_handle h,
int retval = -1;
cxobj *x0 = NULL;
char *dbfile = NULL;
int fd = -1;
FILE *fp = NULL;
char *format;
int ret;
@ -453,15 +453,15 @@ xmldb_readfile(clicon_handle h,
goto done;
}
/* Parse file into internal XML tree from different formats */
if ((fd = open(dbfile, O_RDONLY)) < 0) {
if ((fp = fopen(dbfile, "r")) < 0) {
clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
goto done;
}
if (strcmp(format, "json")==0){
if ((ret = clixon_json_parse_file(fd, yb, yspec, &x0, NULL)) < 0) /* XXX: ret == 0*/
if ((ret = clixon_json_parse_file(fp, yb, yspec, &x0, NULL)) < 0) /* XXX: ret == 0*/
goto done;
}
else if ((ret = clixon_xml_parse_file(fd, yb, yspec, "</config>", &x0, NULL)) < 0)
else if ((ret = clixon_xml_parse_file(fp, yb, yspec, "</config>", &x0, NULL)) < 0)
goto done;
#ifdef XMLDB_READFILE_FAIL /* The functions calling this function cannot handle a failed parse yet */
if (ret == 0)
@ -495,8 +495,8 @@ xmldb_readfile(clicon_handle h,
}
retval = 1;
done:
if (fd != -1)
close(fd);
if (fp)
fclose(fp);
if (dbfile)
free(dbfile);
if (x0)