* 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

@ -97,7 +97,7 @@ main(int argc,
int len;
char *buf = NULL;
int ret;
int fd = 0; /* unless overriden by argv[1] */
FILE *fp = stdin; /* unless overriden by argv[1] */
char *yang_file_dir = NULL;
yang_stmt *yspec = NULL;
char *path = NULL;
@ -135,8 +135,8 @@ main(int argc,
break;
case 'f': /* XML file */
filename = optarg;
if ((fd = open(filename, O_RDONLY)) < 0){
clicon_err(OE_UNIX, errno, "open(%s)", optarg);
if ((fp = fopen(filename, "r")) < 0){
clicon_err(OE_UNIX, errno, "fopen(%s)", optarg);
goto done;
}
break;
@ -212,10 +212,10 @@ main(int argc,
}
/*
* If fd=0, then continue reading from stdin (after CR)
* If fd>0, reading from file opened as argv[1]
* If fp=stdin, then continue reading from stdin (after CR)
* XXX Note 0 above, stdin here
*/
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &x, NULL) < 0){
if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &x, NULL) < 0){
fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
return -1;
}
@ -297,8 +297,8 @@ main(int argc,
xml_free(x);
if (xcfg)
xml_free(xcfg);
if (fd > 0)
close(fd);
if (fp)
fclose(fp);
if (h)
clicon_handle_exit(h);
return retval;