summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2012-04-01 17:07:45 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2012-04-01 17:07:45 -0400
commit3438b2129cd933e430349a6bd66a1933071c92c2 (patch)
tree13846c11f27fd037e4e3025cfbd9601c4ba8f975
parent4d26f7436c0acf8617c4736f110f06e2f4531bbd (diff)
downloadgawk-3438b2129cd933e430349a6bd66a1933071c92c2.tar.gz
Update ERRNO API.
-rw-r--r--ChangeLog17
-rw-r--r--TODO.xgawk12
-rw-r--r--awk.h6
-rw-r--r--doc/ChangeLog7
-rw-r--r--doc/gawk.texi32
-rw-r--r--eval.c22
-rw-r--r--ext.c3
-rw-r--r--extension/ChangeLog8
-rw-r--r--extension/filefuncs.c4
-rw-r--r--extension/fork.c4
-rw-r--r--extension/readfile.c8
-rw-r--r--extension/rwarray.c4
-rw-r--r--io.c22
13 files changed, 100 insertions, 49 deletions
diff --git a/ChangeLog b/ChangeLog
index fb1b247e..f9786dfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2012-04-01 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * TODO.xgawk: Move ERRNO item into "done" section.
+ * awk.h (update_ERRNO, update_ERRNO_saved): Remove declarations.
+ (update_ERRNO_int, enum errno_translate, update_ERRNO_string,
+ unset_ERRNO): Add new declarations.
+ * eval.c (update_ERRNO_saved): Renamed to update_ERRNO_int.
+ (update_ERRNO_string, unset_ERRNO): New functions.
+ * ext.c (do_ext): Use new update_ERRNO_string function.
+ * io.c (ERRNO_node): Remove redundant extern declaration (in awk.h).
+ (after_beginfile, nextfile): Replace update_ERRNO() with
+ update_ERRNO_int(errno).
+ (inrec): Replace update_ERRNO_saved with update_ERRNO_int.
+ (do_close): Use new function update_ERRNO_string.
+ (close_redir, do_getline_redir, do_getline): Replace update_ERRNO_saved
+ with update_ERRNO_int.
+
2012-03-27 Andrew J. Schorr <aschorr@telemetry-investments.com>
* TODO.xgawk: Update to reflect debate about how to support Cygwin
diff --git a/TODO.xgawk b/TODO.xgawk
index 0198a451..56b13e11 100644
--- a/TODO.xgawk
+++ b/TODO.xgawk
@@ -13,6 +13,12 @@ Done:
- Implement @load
+- Patch ERRNO handling to create a simple API for use by extensions:
+ extern void update_ERRNO_int(int)
+ enum errno_translate { TRANSLATE, DONT_TRANSLATE };
+ extern void update_ERRNO_string(const char *string, enum errno_translate);
+ extern void unset_ERRNO(void);
+
To do (not necessarily in this order):
@@ -49,12 +55,6 @@ To do (not necessarily in this order):
- Add tests for standard extensions.
-- Patch ERRNO handling to create a simple API for use by extensions:
- extern void update_ERRNO_int(int)
- enum errno_translate { TRANSLATE, DONT_TRANSLATE };
- extern void update_ERRNO_string(const char *string, enum errno_translate);
- extern void unset_ERRNO(void);
-
- Develop a libgawk shared library for use by extensions. In particular,
a few existing extensions use a hash API for mapping string handles to
structures. In xgawk, we had this API inside array.c, but it probably
diff --git a/awk.h b/awk.h
index d6707805..26c87177 100644
--- a/awk.h
+++ b/awk.h
@@ -1376,8 +1376,10 @@ extern void set_CONVFMT(void);
extern void set_BINMODE(void);
extern void set_LINT(void);
extern void set_TEXTDOMAIN(void);
-extern void update_ERRNO(void);
-extern void update_ERRNO_saved(int);
+extern void update_ERRNO_int(int);
+enum errno_translate { TRANSLATE, DONT_TRANSLATE };
+extern void update_ERRNO_string(const char *string, enum errno_translate);
+extern void unset_ERRNO(void);
extern void update_NR(void);
extern void update_NF(void);
extern void update_FNR(void);
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 815644ca..568d7c78 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-01 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * gawk.texi: Replace documentation of removed functions update_ERRNO and
+ update_ERRNO_saved with descriptions new functions update_ERRNO_int,
+ update_ERRNO_string and unset_ERRNO. And fix a couple of examples
+ to use update_ERRNO_int instead of update_ERRNO.
+
2012-03-26 Arnold D. Robbins <arnold@skeeve.com>
* gawk.texi: Minor style edits.
diff --git a/doc/gawk.texi b/doc/gawk.texi
index eaad54d2..7b46026b 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -29460,21 +29460,29 @@ This is a convenience macro that calls @code{get_actual_argument()}.
@cindex functions, return values@comma{} setting
@cindex @code{ERRNO} variable
-@cindex @code{update_ERRNO()} internal function
-@cindex internal function, @code{update_ERRNO()}
-@item void update_ERRNO(void)
+@cindex @code{update_ERRNO_int()} internal function
+@cindex internal function, @code{update_ERRNO_int()}
+@item void update_ERRNO_int(int errno_saved)
This function is called from within a C extension function to set
-the value of @command{gawk}'s @code{ERRNO} variable, based on the current
-value of the C @code{errno} global variable.
+the value of @command{gawk}'s @code{ERRNO} variable, based on the error
+value provided as the argument.
It is provided as a convenience.
@cindex @code{ERRNO} variable
-@cindex @code{update_ERRNO_saved()} internal function
-@cindex internal function, @code{update_ERRNO_saved()}
-@item void update_ERRNO_saved(int errno_saved)
+@cindex @code{update_ERRNO_string()} internal function
+@cindex internal function, @code{update_ERRNO_string()}
+@item void update_ERRNO_string(const char *string, enum errno_translate)
This function is called from within a C extension function to set
-the value of @command{gawk}'s @code{ERRNO} variable, based on the error
-value provided as the argument.
+the value of @command{gawk}'s @code{ERRNO} variable to a given string.
+The second argument determines whether the string is translated before being
+installed into @code{ERRNO}. It is provided as a convenience.
+
+@cindex @code{ERRNO} variable
+@cindex @code{unset_ERRNO()} internal function
+@cindex internal function, @code{unset_ERRNO()}
+@item void unset_ERRNO(void)
+This function is called from within a C extension function to set
+the value of @command{gawk}'s @code{ERRNO} variable to a null string.
It is provided as a convenience.
@cindex @code{ENVIRON} array
@@ -29838,7 +29846,7 @@ is updated.
(void) force_string(newdir);
ret = chdir(newdir->stptr);
if (ret < 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
@end example
Finally, the function returns the return value to the @command{awk} level:
@@ -29907,7 +29915,7 @@ If there's an error, it sets @code{ERRNO} and returns:
(void) force_string(file);
ret = lstat(file->stptr, & sbuf);
if (ret < 0) @{
- update_ERRNO();
+ update_ERRNO_int(errno);
return make_number((AWKNUM) ret);
@}
@end example
diff --git a/eval.c b/eval.c
index 78598b21..82cca9ed 100644
--- a/eval.c
+++ b/eval.c
@@ -988,10 +988,10 @@ set_TEXTDOMAIN()
*/
}
-/* update_ERRNO_saved --- update the value of ERRNO based on argument */
+/* update_ERRNO_int --- update the value of ERRNO based on argument */
void
-update_ERRNO_saved(int errcode)
+update_ERRNO_int(int errcode)
{
char *cp;
@@ -1004,12 +1004,24 @@ update_ERRNO_saved(int errcode)
ERRNO_node->var_value = make_string(cp, strlen(cp));
}
-/* update_ERRNO --- update the value of ERRNO based on errno */
+/* update_ERRNO_string --- update ERRNO with optionally translated string */
void
-update_ERRNO()
+update_ERRNO_string(const char *string, enum errno_translate translate)
{
- update_ERRNO_saved(errno);
+ if (translate == TRANSLATE)
+ string = gettext(string);
+ unref(ERRNO_node->var_value);
+ ERRNO_node->var_value = make_string(string, strlen(string));
+}
+
+/* unset_ERRNO --- eliminate the value of ERRNO */
+
+void
+unset_ERRNO(void)
+{
+ unref(ERRNO_node->var_value);
+ ERRNO_node->var_value = Nnull_string;
}
/* update_NR --- update the value of NR */
diff --git a/ext.c b/ext.c
index 39e512fb..3c30b1a2 100644
--- a/ext.c
+++ b/ext.c
@@ -254,8 +254,7 @@ do_ext(int nargs)
{
const char *emsg = _("Operation Not Supported");
- unref(ERRNO_node->var_value);
- ERRNO_node->var_value = make_string(emsg, strlen(emsg));
+ update_ERRNO_string(emsg, DONT_TRANSLATE);
return make_number((AWKNUM) -1);
}
diff --git a/extension/ChangeLog b/extension/ChangeLog
index e0a6245b..dc017d30 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-01 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * filefuncs.c (do_chdir, do_stat): Replace update_ERRNO() with
+ update_ERRNO_int(errno).
+ * fork.c (do_fork, do_waitpid): Ditto.
+ * readfile.c (do_readfile): Ditto.
+ * rwarray.c (do_writea, do_reada): Ditto.
+
2012-03-25 Andrew J. Schorr <aschorr@telemetry-investments.com>
* Makefile.am: Major cleanup. Use libtool options -module and
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index dd1b29a8..63010c35 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -48,7 +48,7 @@ do_chdir(int nargs)
(void) force_string(newdir);
ret = chdir(newdir->stptr);
if (ret < 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
return make_number((AWKNUM) ret);
}
@@ -183,7 +183,7 @@ do_stat(int nargs)
(void) force_string(file);
ret = lstat(file->stptr, & sbuf);
if (ret < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
return make_number((AWKNUM) ret);
}
diff --git a/extension/fork.c b/extension/fork.c
index 88353879..8b8558e6 100644
--- a/extension/fork.c
+++ b/extension/fork.c
@@ -44,7 +44,7 @@ do_fork(int nargs)
ret = fork();
if (ret < 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
else if (ret == 0) {
/* update PROCINFO in the child */
@@ -83,7 +83,7 @@ do_waitpid(int nargs)
options = WNOHANG|WUNTRACED;
ret = waitpid(pid, NULL, options);
if (ret < 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
} else if (do_lint)
lintwarn("wait: called with no arguments");
diff --git a/extension/readfile.c b/extension/readfile.c
index c9b1efc3..9c18601d 100644
--- a/extension/readfile.c
+++ b/extension/readfile.c
@@ -59,18 +59,18 @@ do_readfile(int nargs)
ret = stat(filename->stptr, & sbuf);
if (ret < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
goto done;
} else if ((sbuf.st_mode & S_IFMT) != S_IFREG) {
errno = EINVAL;
ret = -1;
- update_ERRNO();
+ update_ERRNO_int(errno);
goto done;
}
if ((fd = open(filename->stptr, O_RDONLY|O_BINARY)) < 0) {
ret = -1;
- update_ERRNO();
+ update_ERRNO_int(errno);
goto done;
}
@@ -80,7 +80,7 @@ do_readfile(int nargs)
if ((ret = read(fd, text, sbuf.st_size)) != sbuf.st_size) {
(void) close(fd);
ret = -1;
- update_ERRNO();
+ update_ERRNO_int(errno);
goto done;
}
diff --git a/extension/rwarray.c b/extension/rwarray.c
index 8175c7c0..f4f8cd58 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -115,7 +115,7 @@ do_writea(int nargs)
done1:
ret = -1;
- update_ERRNO();
+ update_ERRNO_int(errno);
unlink(file->stptr);
done0:
@@ -297,7 +297,7 @@ do_reada(int nargs)
done1:
ret = -1;
- update_ERRNO();
+ update_ERRNO_int(errno);
done0:
close(fd);
diff --git a/io.c b/io.c
index e3327f17..b2d29825 100644
--- a/io.c
+++ b/io.c
@@ -230,7 +230,6 @@ extern int output_is_tty;
extern NODE *ARGC_node;
extern NODE *ARGV_node;
extern NODE *ARGIND_node;
-extern NODE *ERRNO_node;
extern NODE **fields_arr;
@@ -308,7 +307,7 @@ after_beginfile(IOBUF **curfile)
errcode = iop->errcode;
iop->errcode = 0;
errno = 0;
- update_ERRNO();
+ update_ERRNO_int(errno);
iop_close(iop);
*curfile = NULL;
if (errcode == EISDIR && ! do_traditional) {
@@ -382,7 +381,7 @@ nextfile(IOBUF **curfile, int skipping)
fd = devopen(fname, binmode("r"));
errcode = errno;
if (! do_traditional)
- update_ERRNO();
+ update_ERRNO_int(errno);
/* This is a kludge. */
unref(FILENAME_node->var_value);
@@ -404,7 +403,7 @@ nextfile(IOBUF **curfile, int skipping)
/* FNR is init'ed to 0 */
errno = 0;
if (! do_traditional)
- update_ERRNO();
+ update_ERRNO_int(errno);
unref(FILENAME_node->var_value);
FILENAME_node->var_value = make_string("-", 1);
FILENAME_node->var_value->flags |= MAYBE_NUM; /* be pedantic */
@@ -415,7 +414,7 @@ nextfile(IOBUF **curfile, int skipping)
if (iop->fd == INVALID_HANDLE) {
errcode = errno;
errno = 0;
- update_ERRNO();
+ update_ERRNO_int(errno);
(void) iop_close(iop);
*curfile = NULL;
fatal(_("cannot open file `%s' for reading (%s)"),
@@ -462,7 +461,7 @@ inrec(IOBUF *iop, int *errcode)
if (cnt == EOF) {
retval = 1;
if (*errcode > 0)
- update_ERRNO_saved(*errcode);
+ update_ERRNO_int(*errcode);
} else {
NR += 1;
FNR += 1;
@@ -990,8 +989,7 @@ do_close(int nargs)
if (! do_traditional) {
/* update ERRNO manually, using errno = ENOENT is a stretch. */
cp = _("close of redirection that was never opened");
- unref(ERRNO_node->var_value);
- ERRNO_node->var_value = make_string(cp, strlen(cp));
+ update_ERRNO_string(cp, DONT_TRANSLATE);
}
DEREF(tmp);
@@ -1111,7 +1109,7 @@ close_redir(struct redirect *rp, int exitwarn, two_way_close_type how)
if (! do_traditional) {
/* set ERRNO too so that program can get at it */
- update_ERRNO_saved(save_errno);
+ update_ERRNO_int(save_errno);
}
}
@@ -2228,7 +2226,7 @@ do_getline_redir(int intovar, int redirtype)
if (rp == NULL) {
if (redir_error) { /* failed redirect */
if (! do_traditional)
- update_ERRNO_saved(redir_error);
+ update_ERRNO_int(redir_error);
}
return make_number((AWKNUM) -1.0);
}
@@ -2240,7 +2238,7 @@ do_getline_redir(int intovar, int redirtype)
cnt = get_a_record(&s, iop, &errcode);
if (errcode != 0) {
if (! do_traditional && (errcode != -1))
- update_ERRNO_saved(errcode);
+ update_ERRNO_int(errcode);
return make_number((AWKNUM) -1.0);
}
@@ -2288,7 +2286,7 @@ do_getline(int intovar, IOBUF *iop)
cnt = get_a_record(&s, iop, &errcode);
if (errcode != 0) {
if (! do_traditional && (errcode != -1))
- update_ERRNO_saved(errcode);
+ update_ERRNO_int(errcode);
if (intovar)
(void) POP_ADDRESS();
return make_number((AWKNUM) -1.0);