Index: XMLChangeLog =================================================================== RCS file: /cvsroot/xmlgawk/xmlgawk/XMLChangeLog,v retrieving revision 1.13 diff -b -u -p -r1.13 XMLChangeLog --- XMLChangeLog 14 Mar 2005 16:35:51 -0000 1.13 +++ XMLChangeLog 14 Mar 2005 17:25:55 -0000 @@ -1,3 +1,19 @@ +Mon Mar 14 17:20:21 UTC 2005 Andrew J. Schorr + + * awk.h (update_ERRNO_saved): Declare new function that allows the + caller to specify the errno value used for the error string. + * eval.c (update_ERRNO_saved): New function to use saved errno value + instead of the current value. + (update_ERRNO): Implement by calling update_ERRNO_saved. + * io.c (close_redir): Save errno value and call update_ERRNO_saved + instead of update_ERRNO. + (do_getline): Call update_ERRNO_saved instead of update_ERRNO. + But do not call update_ERRNO if get_a_record returns with errcode + set to -1. + (get_xml_record): If the XML parser indicated an error, and the + errcode pointer is non-NULL, set errcode to -1 so that getline + will return -1. + Mon Mar 14 16:25:31 UTC 2005 Andrew J. Schorr * io.c (get_xml_record): Set ERRNO to have same value as XMLERROR. Index: awk.h =================================================================== RCS file: /cvsroot/xmlgawk/xmlgawk/awk.h,v retrieving revision 1.5 diff -b -u -p -r1.5 awk.h --- awk.h 13 Mar 2005 19:52:39 -0000 1.5 +++ awk.h 14 Mar 2005 17:25:55 -0000 @@ -1029,6 +1029,7 @@ extern void set_XMLMODE P((void)); extern void set_LINT P((void)); extern void set_TEXTDOMAIN P((void)); extern void update_ERRNO P((void)); +extern void update_ERRNO_saved P((int)); extern const char *redflags2str P((int)); extern const char *flags2str P((int)); extern const char *genflags2str P((int flagval, const struct flagtab *tab)); Index: eval.c =================================================================== RCS file: /cvsroot/xmlgawk/xmlgawk/eval.c,v retrieving revision 1.3 diff -b -u -p -r1.3 eval.c --- eval.c 13 Mar 2005 19:52:39 -0000 1.3 +++ eval.c 14 Mar 2005 17:25:56 -0000 @@ -2406,16 +2406,22 @@ assign_val(NODE **lhs_p, NODE *rhs) /* update_ERRNO --- update the value of ERRNO */ void -update_ERRNO() +update_ERRNO_saved(int errcode) { char *cp; - cp = strerror(errno); + cp = strerror(errcode); cp = gettext(cp); unref(ERRNO_node->var_value); ERRNO_node->var_value = make_string(cp, strlen(cp)); } +void +update_ERRNO() +{ + return update_ERRNO_saved(errno); +} + /* comp_func --- array index comparison function for qsort */ static int Index: io.c =================================================================== RCS file: /cvsroot/xmlgawk/xmlgawk/io.c,v retrieving revision 1.6 diff -b -u -p -r1.6 io.c --- io.c 14 Mar 2005 16:35:51 -0000 1.6 +++ io.c 14 Mar 2005 17:25:56 -0000 @@ -967,7 +967,8 @@ close_redir(register struct redirect *rp /* SVR4 awk checks and warns about status of close */ if (status != 0) { - char *s = strerror(errno); + int save_errno = errno; + char *s = strerror(save_errno); /* * Too many people have complained about this. @@ -984,7 +985,7 @@ close_redir(register struct redirect *rp if (! do_traditional) { /* set ERRNO too so that program can get at it */ - update_ERRNO(); + update_ERRNO_saved(save_errno); } } @@ -2291,7 +2292,7 @@ do_getline(NODE *tree) rp = redirect(tree->rnode, &redir_error); if (rp == NULL && redir_error) { /* failed redirect */ if (! do_traditional) - update_ERRNO(); + update_ERRNO_saved(redir_error); return tmp_number((AWKNUM) -1.0); } @@ -2302,8 +2303,8 @@ do_getline(NODE *tree) errcode = 0; cnt = get_a_record(&s, iop, &errcode); if (errcode != 0) { - if (! do_traditional) - update_ERRNO(); + if (! do_traditional && (errcode != -1)) + update_ERRNO_saved(errcode); return tmp_number((AWKNUM) -1.0); } @@ -3065,6 +3066,8 @@ get_xml_record(char **out, /* poi static const char oops[] = "XML Puller: unknown error"; XMLERROR_node->var_value = make_string(oops, strlen(oops)); } + if (errcode) + *errcode = -1; ERRNO_node->var_value = dupnode(XMLERROR_node->var_value); SET_NUMBER(XMLROW, iop->xml.puller->row); SET_NUMBER(XMLCOL, iop->xml.puller->col);