diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2012-09-11 22:16:38 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2012-09-11 22:16:38 +0300 |
commit | c2db2b9ff8465cb5044e6f22beb229336479be57 (patch) | |
tree | 102cc516d09c1af32e083a034882d5e49e2c2006 | |
parent | 47f2bd34643ceda78773e5abbfa466c2f898a815 (diff) | |
download | egawk-c2db2b9ff8465cb5044e6f22beb229336479be57.tar.gz egawk-c2db2b9ff8465cb5044e6f22beb229336479be57.tar.bz2 egawk-c2db2b9ff8465cb5044e6f22beb229336479be57.zip |
Make readdir set ERRNO more.
-rw-r--r-- | extension/ChangeLog | 5 | ||||
-rw-r--r-- | extension/readdir.3am | 16 | ||||
-rw-r--r-- | extension/readdir.c | 7 |
3 files changed, 22 insertions, 6 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index fcc9d8a8..e37715ae 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,8 @@ +2012-09-11 Arnold D. Robbins <arnold@skeeve.com> + + * readdir.c (do_readdir_do_ftype): Set ERRNO for bad arguments. + * readdir.3a: Document same, minor fixes. + 2012-09-07 Akim Demaille <akim@lrde.epita.fr> * extension/gawkfts.h (__THROW): Define if it is not. diff --git a/extension/readdir.3am b/extension/readdir.3am index 4479c61d..5e03f491 100644 --- a/extension/readdir.3am +++ b/extension/readdir.3am @@ -1,4 +1,4 @@ -.TH READDIR 3am "Aug 31 2012" "Free Software Foundation" "GNU Awk Extension Modules" +.TH READDIR 3am "Sep 11 2012" "Free Software Foundation" "GNU Awk Extension Modules" .SH NAME readdir \- directory input parser for gawk .SH SYNOPSIS @@ -45,9 +45,9 @@ for a socket, and On systems without the file type information, calling .B readdir_do_ftype("stat") causes the extension to use -.IR stat (2) +.IR lstat (2) to retrieve the appropriate information. This is not the default, since -.IR stat (2) +.IR lstat (2) is a potentially expensive operation. By calling .B readdir_do_ftype("never") one can ensure that the file type @@ -55,9 +55,15 @@ information is never displayed, even when readily available in the directory entry. .PP The third option, -.B readdir_do_ftype("dirent") , +.BR readdir_do_ftype("dirent") , takes file type information from the directory entry, if it is available. This is the default on systems that supply this information. +.PP +The +.B readdir_do_ftype() +function will set +.B ERRNO +if called without arguments or with invalid arguments. .SH NOTES On GNU/Linux systems, there are filesystems that don't support the .B d_type @@ -70,7 +76,7 @@ Therefore, using is advisable even on GNU/Linux systems. In this case, the .I readdir extension will fall back to using -.IR stat (2) +.IR lstat (2) when it encounters an unknown file type. ... .SH BUGS .SH EXAMPLE diff --git a/extension/readdir.c b/extension/readdir.c index 49a6bf6a..7140b72b 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -111,6 +111,7 @@ ftype(struct dirent *entry) */ return NULL; + /* Should we set ERRNO here? */ if (lstat(entry->d_name, & sbuf) < 0) return "u"; @@ -299,6 +300,7 @@ do_readdir_do_ftype(int nargs, awk_value_t *result) make_number(1.0, result); if (nargs < 1) { warning(ext_id, _("readdir_do_ftype: called with no arguments")); + update_ERRNO_int(EINVAL); make_number(0.0, result); goto out; } else if (do_lint && nargs > 3) @@ -306,6 +308,7 @@ do_readdir_do_ftype(int nargs, awk_value_t *result) if (! get_argument(0, AWK_STRING, & flag)) { warning(ext_id, _("readdir_do_ftype: could not get argument")); + update_ERRNO_int(EINVAL); make_number(0.0, result); goto out; } @@ -316,8 +319,10 @@ do_readdir_do_ftype(int nargs, awk_value_t *result) do_ftype = USE_DIRENT_INFO; else if (strcmp(flag.str_value.str, "stat") == 0) do_ftype = USE_STAT_INFO; - else + else { + update_ERRNO_int(EINVAL); make_number(0.0, result); + } out: return result; |