diff --git a/CHANGELOG.md b/CHANGELOG.md index 5672d37a..ff87fc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,8 +44,17 @@ Users may have to change how they access the system * New clixon-config@2020-11-03.yang revision * Added option: `CLICON_RESTCONF_CONFIG` for reading restconf daemon config frm datastore +### C/CLI-API changes on existing features + +Developers may need to change their code + +* 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) + ### Minor changes +* Improved performance of parsing files as described in [Bytewise read() of files is slow #146](https://github.com/clicon/clixon/issues/146), thanks: @hjelmeland * Added new backend plugin: ca_pre-demon called if backend is daemonized just prior to forking. * Added XPATH functions `position` diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index eefb1887..1dec9a1e 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -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); diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 8839e269..84db9b4f 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -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; diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index d044bb7a..f04113e5 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -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; } diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 5ad4381b..1044f3c0 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -370,7 +370,7 @@ example_statedata(clicon_handle h, cvec *nsc1 = NULL; cvec *nsc2 = NULL; yang_stmt *yspec = NULL; - int fd; + FILE *fp = NULL; if (!_state) goto ok; @@ -395,15 +395,14 @@ example_statedata(clicon_handle h, } else{ cxobj *x1; - if ((fd = open(_state_file, O_RDONLY)) < 0){ + if ((fp = fopen(_state_file, "r")) < 0){ clicon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) goto done; - 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; - close(fd); if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0) goto done; for (i=0; i= 3 diff --git a/lib/clixon/clixon_yang_parse_lib.h b/lib/clixon/clixon_yang_parse_lib.h index 48c05efd..cfe3d09f 100644 --- a/lib/clixon/clixon_yang_parse_lib.h +++ b/lib/clixon/clixon_yang_parse_lib.h @@ -51,7 +51,7 @@ /* * Prototypes */ -yang_stmt *yang_parse_file(int fd, const char *name, yang_stmt *ysp); +yang_stmt *yang_parse_file(FILE *fp, const char *name, yang_stmt *ysp); yang_stmt *yang_parse_filename(const char *filename, yang_stmt *ysp); int yang_spec_parse_module(clicon_handle h, const char *module, const char *revision, yang_stmt *yspec); diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 5651ed61..9273db5a 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -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, "", &x0, NULL)) < 0) + else if ((ret = clixon_xml_parse_file(fp, yb, yspec, "", &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) diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 97a13658..4bcdfd0d 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -1367,14 +1367,14 @@ clixon_json_parse_string(char *str, * eg: name="a:b" -> prefix="a", name="b" * But this is not done if yspec=NULL, and is not part of the JSON spec * - * @param[in] fd File descriptor to the JSON file (ASCII string) + * @param[in] fp File descriptor to the JSON file (ASCII string) * @param[in] yspec Yang specification, or NULL * @param[in,out] xt Pointer to (XML) parse tree. If empty, create. * @param[out] xerr Reason for invalid returned as netconf err msg * * @code * cxobj *xt = NULL; - * if (clixon_json_parse_file(0, YB_MODULE, yspec, &xt) < 0) + * if (clixon_json_parse_file(stdin, YB_MODULE, yspec, &xt) < 0) * err; * xml_free(xt); * @endcode @@ -1390,7 +1390,7 @@ clixon_json_parse_string(char *str, * @see RFC7951 */ int -clixon_json_parse_file(int fd, +clixon_json_parse_file(FILE *fp, yang_bind yb, yang_stmt *yspec, cxobj **xt, @@ -1404,7 +1404,7 @@ clixon_json_parse_file(int fd, char *ptr; char ch; int len = 0; - + if (xt==NULL){ clicon_err(OE_XML, EINVAL, "xt is NULL"); return -1; @@ -1416,7 +1416,7 @@ clixon_json_parse_file(int fd, memset(jsonbuf, 0, jsonbuflen); ptr = jsonbuf; while (1){ - if ((ret = read(fd, &ch, 1)) < 0){ + if ((ret = fread(&ch, 1, 1, fp)) < 0){ clicon_err(OE_XML, errno, "read"); break; } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index a9106d50..aa340596 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -204,19 +204,19 @@ parse_configfile_one(const char *filename, cxobj **xconfig) { int retval = -1; - int fd = -1; + FILE *fp = NULL; cxobj *xt = NULL; cxobj *xerr = NULL; cxobj *xa; cbuf *cbret = NULL; int ret; - if ((fd = open(filename, O_RDONLY)) < 0){ + if ((fp = fopen(filename, "r")) < 0){ clicon_err(OE_UNIX, errno, "open configure file: %s", filename); return -1; } clicon_debug(2, "%s: Reading config file %s", __FUNCTION__, filename); - if ((ret = clixon_xml_parse_file(fd, yspec?YB_MODULE:YB_NONE, yspec, NULL, &xt, &xerr)) < 0) + if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, NULL, &xt, &xerr)) < 0) goto done; if (ret == 0){ if ((cbret = cbuf_new()) ==NULL){ @@ -249,8 +249,8 @@ parse_configfile_one(const char *filename, done: if (xt) xml_free(xt); - if (fd != -1) - close(fd); + if (fp) + fclose(fp); if (cbret) cbuf_free(cbret); if (xerr) diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index b156ce36..6ac20eab 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -436,7 +436,7 @@ clixon_xml_changelog_init(clicon_handle h) { int retval = -1; char *filename; - int fd = -1; + FILE *fp = NULL; cxobj *xt = NULL; yang_stmt *yspec; int ret; @@ -445,11 +445,11 @@ clixon_xml_changelog_init(clicon_handle h) yspec = clicon_dbspec_yang(h); if ((filename = clicon_option_str(h, "CLICON_XML_CHANGELOG_FILE")) != NULL){ - if ((fd = open(filename, O_RDONLY)) < 0){ - clicon_err(OE_UNIX, errno, "open(%s)", filename); + if ((fp = fopen(filename, "r")) < 0){ + clicon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } - 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; if (xml_rootchild(xt, 0, &xt) < 0) goto done; @@ -477,8 +477,8 @@ clixon_xml_changelog_init(clicon_handle h) cbuf_free(cbret); if (xret) xml_free(xret); - if (fd != -1) - close(fd); + if (fp) + fclose(fp); if (xt) xml_free(xt); return retval; diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 9ed13812..2d48f08f 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -578,9 +578,9 @@ FSM(char *tag, * @code * cxobj *xt = NULL; * cxobj *xerr = NULL; - * int fd; - * fd = open(filename, O_RDONLY); - * if ((ret = clixon_xml_parse_file(fd, YB_MODULE, yspec, "", &xt, &xerr)) < 0) + * FILE *f; + * f = fopen(filename, "r"); + * if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, "", &xt, &xerr)) < 0) * err; * xml_free(xt); * @endcode @@ -590,7 +590,7 @@ FSM(char *tag, * @note May block on file I/O */ int -clixon_xml_parse_file(int fd, +clixon_xml_parse_file(FILE *fp, yang_bind yb, yang_stmt *yspec, char *endtag, @@ -626,9 +626,8 @@ clixon_xml_parse_file(int fd, memset(xmlbuf, 0, xmlbuflen); ptr = xmlbuf; while (1){ - if ((ret = read(fd, &ch, 1)) < 0){ - clicon_err(OE_XML, errno, "read: [pid:%d]", - (int)getpid()); + if ((ret = fread(&ch, 1, 1, fp)) < 0){ + clicon_err(OE_XML, errno, "read"); break; } if (ret != 0){ diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index e2b36a2e..11521858 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -704,7 +704,7 @@ yang_parse_str(char *str, * @note this function simply parse a yang spec, no dependencies or checks */ yang_stmt * -yang_parse_file(int fd, +yang_parse_file(FILE *fp, const char *name, yang_stmt *yspec) { @@ -723,7 +723,7 @@ yang_parse_file(int fd, memset(buf, 0, len); i = 0; /* position in buf */ while (1){ /* read the whole file */ - if ((ret = read(fd, &c, 1)) < 0){ + if ((ret = fread(&c, 1, 1, fp)) < 0){ clicon_err(OE_XML, errno, "read"); break; } @@ -872,7 +872,7 @@ yang_parse_filename(const char *filename, yang_stmt *yspec) { yang_stmt *ymod = NULL; - int fd = -1; + FILE *fp = NULL; struct stat st; clicon_debug(1, "%s %s", __FUNCTION__, filename); @@ -880,15 +880,15 @@ yang_parse_filename(const char *filename, clicon_err(OE_YANG, errno, "%s not found", filename); goto done; } - if ((fd = open(filename, O_RDONLY)) < 0){ - clicon_err(OE_YANG, errno, "open(%s)", filename); + if ((fp = fopen(filename, "r")) == NULL){ + clicon_err(OE_YANG, errno, "fopen(%s)", filename); goto done; } - if ((ymod = yang_parse_file(fd, filename, yspec)) < 0) + if ((ymod = yang_parse_file(fp, filename, yspec)) < 0) goto done; done: - if (fd != -1) - close(fd); + if (fp) + fclose(fp); return ymod; /* top-level (sub)module */ } diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index c29131c9..daea215b 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -250,14 +250,14 @@ main(int argc, char **argv) usage(argv0); } if (argc == 2){ - int fd; - if ((fd = open(xmlfilename, O_RDONLY)) < 0){ - clicon_err(OE_UNIX, errno, "open(%s)", xmlfilename); + FILE *fp; + if ((fp = fopen(xmlfilename, "r")) < 0){ + clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename); goto done; } - 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; - close(fd); + fclose(fp); } else if (clixon_xml_parse_string(argv[2], YB_MODULE, yspec, &xt, NULL) < 0) diff --git a/util/clixon_util_json.c b/util/clixon_util_json.c index 1d40cf8d..d30f5e4d 100644 --- a/util/clixon_util_json.c +++ b/util/clixon_util_json.c @@ -137,7 +137,7 @@ main(int argc, return -1; } } - if ((ret = clixon_json_parse_file(0, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0) + if ((ret = clixon_json_parse_file(stdin, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ xml_print(stderr, xerr); diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index 209b9acd..d42ebad9 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -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; diff --git a/util/clixon_util_socket.c b/util/clixon_util_socket.c index e51238e2..8c737962 100644 --- a/util/clixon_util_socket.c +++ b/util/clixon_util_socket.c @@ -87,7 +87,7 @@ main(int argc, char *retdata = NULL; int jsonin = 0; char *input_filename = NULL; - int fd = 0; /* stdin */ + FILE *fp = stdin; cxobj *xt = NULL; cxobj *xc; cxobj *xerr = NULL; @@ -138,14 +138,14 @@ main(int argc, usage(argv[0]); } if (input_filename){ - if ((fd = open(input_filename, O_RDONLY)) < 0){ + if ((fp = fopen(input_filename, "r")) < 0){ clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } } /* 2. Parse data (xml/json) */ if (jsonin){ - if ((ret = clixon_json_parse_file(fd, YB_NONE, NULL, &xt, &xerr)) < 0) + if ((ret = clixon_json_parse_file(fp, YB_NONE, NULL, &xt, &xerr)) < 0) goto done; if (ret == 0){ fprintf(stderr, "Invalid JSON\n"); @@ -153,7 +153,7 @@ main(int argc, } } else{ - 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){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } @@ -176,6 +176,8 @@ main(int argc, fprintf(stdout, "%s\n", retdata); retval = 0; done: + if (fp) + fclose(fp); if (xerr) xml_free(xerr); if (xt) diff --git a/util/clixon_util_xml.c b/util/clixon_util_xml.c index d651db97..79af8021 100644 --- a/util/clixon_util_xml.c +++ b/util/clixon_util_xml.c @@ -154,8 +154,8 @@ main(int argc, int output = 0; clicon_handle h; struct stat st; - int fd = 0; /* base file, stdin */ - int tfd = -1; /* top file */ + FILE *fp = stdin; /* base file, stdin */ + FILE *tfp = NULL; /* top file */ cxobj *xcfg = NULL; cbuf *cbret = NULL; cxobj *xtop = NULL; /* Top tree if any */ @@ -263,11 +263,11 @@ main(int argc, * Always validated */ if (top_input_filename){ - if ((tfd = open(top_input_filename, O_RDONLY)) < 0){ - clicon_err(OE_YANG, errno, "open(%s)", top_input_filename); + if ((tfp = fopen(top_input_filename, "r")) < 0){ + clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); goto done; } - if ((ret = clixon_xml_parse_file(tfd, YB_MODULE, yspec, NULL, &xtop, &xerr)) < 0){ + if ((ret = clixon_xml_parse_file(tfp, YB_MODULE, yspec, NULL, &xtop, &xerr)) < 0){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } @@ -288,14 +288,14 @@ main(int argc, xt = xbot; } if (input_filename){ - if ((fd = open(input_filename, O_RDONLY)) < 0){ + if ((fp = fopen(input_filename, "r")) < 0){ clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } } /* 2. Parse data (xml/json) */ if (jsonin){ - if ((ret = clixon_json_parse_file(fd, top_input_filename?YB_PARENT:YB_MODULE, yspec, &xt, &xerr)) < 0) + if ((ret = clixon_json_parse_file(fp, top_input_filename?YB_PARENT:YB_MODULE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ clixon_netconf_error(xerr, "util_xml", NULL); @@ -309,7 +309,7 @@ main(int argc, yb = YB_MODULE; else yb = YB_PARENT; - if ((ret = clixon_xml_parse_file(fd, yb, yspec, NULL, &xt, &xerr)) < 0){ + if ((ret = clixon_xml_parse_file(fp, yb, yspec, NULL, &xt, &xerr)) < 0){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } @@ -345,6 +345,10 @@ main(int argc, } retval = 0; done: + if (tfp) + fclose(tfp); + if (fp) + fclose(fp); if (nsc) cvec_free(nsc); if (cbret) diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index 58de8f55..943912b3 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -126,7 +126,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 *xpath = NULL; @@ -168,7 +168,7 @@ main(int argc, break; case 'f': /* XML file */ filename = optarg; - if ((fd = open(filename, O_RDONLY)) < 0){ + if ((fp = fopen(filename, "r")) < 0){ clicon_err(OE_UNIX, errno, "open(%s)", argv[1]); goto done; } @@ -295,10 +295,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, &x0, NULL) < 0){ + if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &x0, NULL) < 0){ fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason); return -1; } @@ -375,7 +375,7 @@ main(int argc, free(buf); if (x0) xml_free(x0); - if (fd > 0) - close(fd); + if (fp) + fclose(fp); return retval; } diff --git a/util/clixon_util_yang.c b/util/clixon_util_yang.c index d3261ab6..8138cbfc 100644 --- a/util/clixon_util_yang.c +++ b/util/clixon_util_yang.c @@ -106,7 +106,7 @@ main(int argc, char **argv) clicon_debug_init(dbg, NULL); if ((yspec = yspec_new()) == NULL) goto done; - if (yang_parse_file(0, "yang test", yspec) == NULL){ + if (yang_parse_file(stdin, "yang test", yspec) == NULL){ fprintf(stderr, "yang parse error %s\n", clicon_err_reason); return -1; }