aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/ChangeLog6
-rw-r--r--extension/filefuncs.3am12
-rw-r--r--extension/filefuncs.c14
3 files changed, 24 insertions, 8 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index f581eef3..ca47bf65 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2012-11-21 Arnold D. Robbins <arnold@skeeve.com>
+
+ * filefuncs.c (do_stat): Optional third argument indicates to
+ use stat(2) instead of lstat(2).
+ * filefuncs.3am: Document same.
+
2012-11-19 Arnold D. Robbins <arnold@skeeve.com>
* readdir.c: Simplify code to always print file type and not
diff --git a/extension/filefuncs.3am b/extension/filefuncs.3am
index e0caba05..23800c47 100644
--- a/extension/filefuncs.3am
+++ b/extension/filefuncs.3am
@@ -1,4 +1,4 @@
-.TH FILEFUNCS 3am "Aug 08 2012" "Free Software Foundation" "GNU Awk Extension Modules"
+.TH FILEFUNCS 3am "Nov 21 2012" "Free Software Foundation" "GNU Awk Extension Modules"
.SH NAME
filefuncs \- provide some file related functionality to gawk
.SH SYNOPSIS
@@ -7,7 +7,7 @@ filefuncs \- provide some file related functionality to gawk
.sp
result = chdir("/some/directory")
.sp
-result = stat("/some/path", statdata)
+result = stat("/some/path", statdata [, follow])
.sp
flags = or(FTS_PHYSICAL, ...)
.br
@@ -33,12 +33,16 @@ The
.B stat()
function provides a hook into the
.IR stat (2)
-system call. In fact, it uses
-.IR lstat (2).
+system call.
It returns zero
upon success or less than zero upon error.
In the latter case it updates
.BR ERRNO .
+By default, it uses
+.IR lstat (2).
+However, if passed a third argument, it uses
+.IR stat (2),
+instead.
.PP
In all cases, it clears the
.B statdata
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index 391ed11a..c8ef0534 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -341,11 +341,13 @@ do_stat(int nargs, awk_value_t *result)
awk_array_t array;
int ret;
struct stat sbuf;
+ int (*statfunc)(const char *path, struct stat *sbuf) = lstat; /* default */
assert(result != NULL);
- if (do_lint && nargs != 2) {
- lintwarn(ext_id, _("stat: called with wrong number of arguments"));
+ if (nargs != 2 && nargs != 3) {
+ if (do_lint)
+ lintwarn(ext_id, _("stat: called with wrong number of arguments"));
return make_number(-1, result);
}
@@ -355,6 +357,10 @@ do_stat(int nargs, awk_value_t *result)
warning(ext_id, _("stat: bad parameters"));
return make_number(-1, result);
}
+
+ if (nargs == 3) {
+ statfunc = stat;
+ }
name = file_param.str_value.str;
array = array_param.array_cookie;
@@ -362,8 +368,8 @@ do_stat(int nargs, awk_value_t *result)
/* always empty out the array */
clear_array(array);
- /* lstat the file, if error, set ERRNO and return */
- ret = lstat(name, & sbuf);
+ /* stat the file, if error, set ERRNO and return */
+ ret = statfunc(name, & sbuf);
if (ret < 0) {
update_ERRNO_int(errno);
return make_number(ret, result);