diff options
-rw-r--r-- | extension/ChangeLog | 5 | ||||
-rw-r--r-- | extension/readdir.3am | 15 | ||||
-rw-r--r-- | extension/readdir.c | 33 | ||||
-rw-r--r-- | test/ChangeLog | 4 | ||||
-rw-r--r-- | test/readdir.awk | 2 |
5 files changed, 41 insertions, 18 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 9b5affc3..350ac972 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,8 @@ +2012-09-07 Arnold D. Robbins <arnold@skeeve.com> + + * readdir.c, readdir.3am: Change argument to readdir_do_ftype() + to be a string. Update the doc accordingly. + 2012-08-28 Andrew J. Schorr <aschorr@telemetry-investments.com> * readdir.c: Have three states, 0, 1, 2 for never, fallback, and diff --git a/extension/readdir.3am b/extension/readdir.3am index e7c6ee4f..4479c61d 100644 --- a/extension/readdir.3am +++ b/extension/readdir.3am @@ -1,11 +1,11 @@ -.TH READDIR 3am "Aug 23 2012" "Free Software Foundation" "GNU Awk Extension Modules" +.TH READDIR 3am "Aug 31 2012" "Free Software Foundation" "GNU Awk Extension Modules" .SH NAME readdir \- directory input parser for gawk .SH SYNOPSIS .ft CW @load "readdir" .sp -readdir_do_ftype(2) # or 0 or 1 +readdir_do_ftype("stat") # or "dirent" or "never" .ft R .SH DESCRIPTION The @@ -43,16 +43,21 @@ for a socket, and (unknown) for anything else. .PP On systems without the file type information, calling -.B readdir_do_ftype(2) +.B readdir_do_ftype("stat") causes the extension to use .IR stat (2) to retrieve the appropriate information. This is not the default, since .IR stat (2) is a potentially expensive operation. By calling -.B readdir_do_ftype(0) +.B readdir_do_ftype("never") one can ensure that the file type information is never displayed, even when readily available in the directory entry. +.PP +The third option, +.B 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. .SH NOTES On GNU/Linux systems, there are filesystems that don't support the .B d_type @@ -61,7 +66,7 @@ entry (see and so the file type is always .BR u . Therefore, using -.B readdir_do_ftype(2) +.B readdir_do_ftype("stat") is advisable even on GNU/Linux systems. In this case, the .I readdir extension will fall back to using diff --git a/extension/readdir.c b/extension/readdir.c index 14039c8b..49a6bf6a 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -4,6 +4,8 @@ * Arnold Robbins * arnold@skeeve.com * Written 7/2012 + * + * Andrew Schorr and Arnold Robbins: further fixes 8/2012. */ /* @@ -62,16 +64,15 @@ static awk_bool_t (*init_func)(void) = init_readdir; int plugin_is_GPL_compatible; -/* - * ftype <= 0: never return file type info - * ftype == 1: return file type info only if it is available in dirent - * ftype >= 2: always return file type info, calling fstat if necessary - */ -static int do_ftype = +enum { + NEVER_DO_INFO, + USE_DIRENT_INFO, + USE_STAT_INFO +} do_ftype = #ifdef DT_BLK - 1 + USE_DIRENT_INFO #else - 0 + NEVER_DO_INFO #endif ; @@ -102,7 +103,7 @@ ftype(struct dirent *entry) } #endif - if (do_ftype < 2) + if (do_ftype < USE_STAT_INFO) /* * Avoid "/u" since user did not insist on file type info, * and it does not seem to be supported by dirent on this @@ -176,7 +177,8 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int *errcode, len = sprintf(the_dir->buf, "%llu/%s", (unsigned long long) dirent->d_ino, dirent->d_name); - if (do_ftype > 0) { + + if (do_ftype != NEVER_DO_INFO) { const char *ftstr = ftype(dirent); if (ftstr) len += sprintf(the_dir->buf + len, "/%s", ftstr); @@ -302,13 +304,20 @@ do_readdir_do_ftype(int nargs, awk_value_t *result) } else if (do_lint && nargs > 3) lintwarn(ext_id, _("readdir_do_ftype: called with more than one argument")); - if (! get_argument(0, AWK_NUMBER, & flag)) { + if (! get_argument(0, AWK_STRING, & flag)) { warning(ext_id, _("readdir_do_ftype: could not get argument")); make_number(0.0, result); goto out; } - do_ftype = flag.num_value; + if (strcmp(flag.str_value.str, "never") == 0) + do_ftype = NEVER_DO_INFO; + else if (strcmp(flag.str_value.str, "dirent") == 0) + do_ftype = USE_DIRENT_INFO; + else if (strcmp(flag.str_value.str, "stat") == 0) + do_ftype = USE_STAT_INFO; + else + make_number(0.0, result); out: return result; diff --git a/test/ChangeLog b/test/ChangeLog index 6b02c6a1..135251af 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2012-09-07 Arnold D. Robbins <arnold@skeeve.com> + + * readdir.awk: Change argument to readdir_do_ftype(). + 2012-08-28 Andrew J. Schorr <aschorr@telemetry-investments.com> * Makefile.am (EXTRA_DIST): Add jarebug.sh. diff --git a/test/readdir.awk b/test/readdir.awk index 3ec664df..2e3df453 100644 --- a/test/readdir.awk +++ b/test/readdir.awk @@ -1,7 +1,7 @@ @load "readdir" BEGIN { - readdir_do_ftype(2) + readdir_do_ftype("stat") } { print } |