aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/ChangeLog4
-rw-r--r--doc/gawk.info168
-rw-r--r--doc/gawk.texi29
-rw-r--r--extension/ChangeLog6
-rw-r--r--extension/readdir.3am46
-rw-r--r--extension/readdir.c113
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am1
-rw-r--r--test/Makefile.in1
-rw-r--r--test/readdir.awk4
10 files changed, 119 insertions, 258 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 4c21c6fc..a8810fad 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2012-11-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawk.texi: In API chapter, update behavior of readdir extension.
+
2012-11-16 Arnold D. Robbins <arnold@skeeve.com>
* gawk.texi: Minor edits in API chapter.
diff --git a/doc/gawk.info b/doc/gawk.info
index b74c023c..e99a6e81 100644
--- a/doc/gawk.info
+++ b/doc/gawk.info
@@ -24522,21 +24522,20 @@ File: gawk.info, Node: Extension Sample Readdir, Next: Extension Sample Revout
16.6.5 Reading Directories
--------------------------
-The `readdir' extension adds an input parser for directories, and adds
-a single function named `readdir_do_ftype()'. The usage is as follows:
+The `readdir' extension adds an input parser for directories. The
+usage is as follows:
@load "readdir"
- readdir_do_ftype("stat") # or "dirent" or "never"
-
When this extension is in use, instead of skipping directories named
on the command line (or with `getline'), they are read, with each entry
returned as a record.
- The record consists of at least two fields: the inode number and the
-filename, separated by a forward slash character. On systems where the
-directory entry contains the file type, the record has a third field
-which is a single letter indicating the type of the file:
+ The record consists of three fields. The first two are the inode
+number and the filename, separated by a forward slash character. On
+systems where the directory entry contains the file type, the record
+has a third field which is a single letter indicating the type of the
+file:
Letter File Type
--------------------------------------------------------------------------
@@ -24549,27 +24548,14 @@ Letter File Type
`s' Socket
`u' Anything else (unknown)
- On systems without the file type information, calling
-`readdir_do_ftype("stat")' causes the extension to use the `lstat()'
-system call to retrieve the appropriate information. That is not the
-default, because `lstat()' is a potentially expensive operation. By
-calling `readdir_do_ftype("never")' one can ensure that the file type
-information is never displayed, even when readily available in the
-directory entry.
-
- The third option, `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.
-
- The `readdir_do_ftype()' function sets `ERRNO' if called without
-arguments or with invalid arguments.
+ On systems without the file type information, the third field is
+always `u'.
NOTE: On GNU/Linux systems, there are filesystems that don't
support the `d_type' entry (see the readdir(3) manual page), and
- so the file type is always `u'. Therefore, using
- `readdir_do_ftype("stat")' is advisable even on GNU/Linux systems.
- In this case, the `readdir' extension falls back to using
- `lstat()' when it encounters an unknown file type.
+ so the file type is always `u'. You can use the `filefuncs'
+ extension to call `stat()' in order to get correct type
+ information.
Here is an example:
@@ -32183,70 +32169,70 @@ Node: Extension Sample Fnmatch983690
Node: Extension Sample Fork985416
Node: Extension Sample Ord986630
Node: Extension Sample Readdir987406
-Node: Extension Sample Revout989746
-Node: Extension Sample Rev2way990339
-Node: Extension Sample Read write array991029
-Node: Extension Sample Readfile992912
-Node: Extension Sample API Tests993667
-Node: Extension Sample Time994192
-Node: gawkextlib995499
-Node: Language History997880
-Node: V7/SVR3.1999402
-Node: SVR41001723
-Node: POSIX1003165
-Node: BTL1004173
-Node: POSIX/GNU1004907
-Node: Common Extensions1010442
-Node: Ranges and Locales1011549
-Ref: Ranges and Locales-Footnote-11016167
-Ref: Ranges and Locales-Footnote-21016194
-Ref: Ranges and Locales-Footnote-31016454
-Node: Contributors1016675
-Node: Installation1020971
-Node: Gawk Distribution1021865
-Node: Getting1022349
-Node: Extracting1023175
-Node: Distribution contents1024867
-Node: Unix Installation1030089
-Node: Quick Installation1030706
-Node: Additional Configuration Options1032668
-Node: Configuration Philosophy1034145
-Node: Non-Unix Installation1036487
-Node: PC Installation1036945
-Node: PC Binary Installation1038244
-Node: PC Compiling1040092
-Node: PC Testing1043036
-Node: PC Using1044212
-Node: Cygwin1048397
-Node: MSYS1049397
-Node: VMS Installation1049911
-Node: VMS Compilation1050514
-Ref: VMS Compilation-Footnote-11051521
-Node: VMS Installation Details1051579
-Node: VMS Running1053214
-Node: VMS Old Gawk1054821
-Node: Bugs1055295
-Node: Other Versions1059147
-Node: Notes1064462
-Node: Compatibility Mode1065049
-Node: Additions1065832
-Node: Accessing The Source1066759
-Node: Adding Code1068185
-Node: New Ports1074227
-Node: Derived Files1078362
-Ref: Derived Files-Footnote-11083670
-Ref: Derived Files-Footnote-21083704
-Ref: Derived Files-Footnote-31084304
-Node: Future Extensions1084402
-Node: Basic Concepts1085889
-Node: Basic High Level1086570
-Ref: figure-general-flow1086841
-Ref: figure-process-flow1087440
-Ref: Basic High Level-Footnote-11090669
-Node: Basic Data Typing1090854
-Node: Glossary1094209
-Node: Copying1119520
-Node: GNU Free Documentation License1157077
-Node: Index1182214
+Node: Extension Sample Revout988910
+Node: Extension Sample Rev2way989503
+Node: Extension Sample Read write array990193
+Node: Extension Sample Readfile992076
+Node: Extension Sample API Tests992831
+Node: Extension Sample Time993356
+Node: gawkextlib994663
+Node: Language History997044
+Node: V7/SVR3.1998566
+Node: SVR41000887
+Node: POSIX1002329
+Node: BTL1003337
+Node: POSIX/GNU1004071
+Node: Common Extensions1009606
+Node: Ranges and Locales1010713
+Ref: Ranges and Locales-Footnote-11015331
+Ref: Ranges and Locales-Footnote-21015358
+Ref: Ranges and Locales-Footnote-31015618
+Node: Contributors1015839
+Node: Installation1020135
+Node: Gawk Distribution1021029
+Node: Getting1021513
+Node: Extracting1022339
+Node: Distribution contents1024031
+Node: Unix Installation1029253
+Node: Quick Installation1029870
+Node: Additional Configuration Options1031832
+Node: Configuration Philosophy1033309
+Node: Non-Unix Installation1035651
+Node: PC Installation1036109
+Node: PC Binary Installation1037408
+Node: PC Compiling1039256
+Node: PC Testing1042200
+Node: PC Using1043376
+Node: Cygwin1047561
+Node: MSYS1048561
+Node: VMS Installation1049075
+Node: VMS Compilation1049678
+Ref: VMS Compilation-Footnote-11050685
+Node: VMS Installation Details1050743
+Node: VMS Running1052378
+Node: VMS Old Gawk1053985
+Node: Bugs1054459
+Node: Other Versions1058311
+Node: Notes1063626
+Node: Compatibility Mode1064213
+Node: Additions1064996
+Node: Accessing The Source1065923
+Node: Adding Code1067349
+Node: New Ports1073391
+Node: Derived Files1077526
+Ref: Derived Files-Footnote-11082834
+Ref: Derived Files-Footnote-21082868
+Ref: Derived Files-Footnote-31083468
+Node: Future Extensions1083566
+Node: Basic Concepts1085053
+Node: Basic High Level1085734
+Ref: figure-general-flow1086005
+Ref: figure-process-flow1086604
+Ref: Basic High Level-Footnote-11089833
+Node: Basic Data Typing1090018
+Node: Glossary1093373
+Node: Copying1118684
+Node: GNU Free Documentation License1156241
+Node: Index1181378

End Tag Table
diff --git a/doc/gawk.texi b/doc/gawk.texi
index be040076..692811c0 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -31672,21 +31672,18 @@ printf("The string value of 65 is %s\n", chr(65))
@node Extension Sample Readdir
@subsection Reading Directories
-The @code{readdir} extension adds an input parser for directories, and
-adds a single function named @code{readdir_do_ftype()}.
+The @code{readdir} extension adds an input parser for directories.
The usage is as follows:
@example
@@load "readdir"
-
-readdir_do_ftype("stat") # or "dirent" or "never"
@end example
When this extension is in use, instead of skipping directories named
on the command line (or with @code{getline}),
they are read, with each entry returned as a record.
-The record consists of at least two fields: the inode number and the
+The record consists of three fields. The first two are the inode number and the
filename, separated by a forward slash character.
On systems where the directory entry contains the file type, the record
has a third field which is a single letter indicating the type of the
@@ -31704,28 +31701,14 @@ file:
@item @code{u} @tab Anything else (unknown)
@end multitable
-On systems without the file type information, calling
-@samp{readdir_do_ftype("stat")} causes the extension to use the
-@code{lstat()} system call to retrieve the appropriate information. That
-is not the default, because @code{lstat()} is a potentially expensive
-operation. By calling @samp{readdir_do_ftype("never")} one can ensure
-that the file type information is never displayed, even when readily
-available in the directory entry.
-
-The third option, @samp{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.
-
-The @code{readdir_do_ftype()} function sets @code{ERRNO} if called
-without arguments or with invalid arguments.
+On systems without the file type information, the third field is always
+@samp{u}.
@quotation NOTE
On GNU/Linux systems, there are filesystems that don't support the
@code{d_type} entry (see the @i{readdir}(3) manual page), and so the file
-type is always @samp{u}. Therefore, using @samp{readdir_do_ftype("stat")}
-is advisable even on GNU/Linux systems. In this case, the @code{readdir}
-extension falls back to using @code{lstat()} when it encounters an
-unknown file type.
+type is always @samp{u}. You can use the @code{filefuncs} extension to call
+@code{stat()} in order to get correct type information.
@end quotation
Here is an example:
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 12cbfcba..f581eef3 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2012-11-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * readdir.c: Simplify code to always print file type and not
+ use stat().
+ * readdir.3am: Document same.
+
2012-11-16 Arnold D. Robbins <arnold@skeeve.com>
* testext.c: In awk code, use printf(...) instead of the form
diff --git a/extension/readdir.3am b/extension/readdir.3am
index 9d60b054..297e24be 100644
--- a/extension/readdir.3am
+++ b/extension/readdir.3am
@@ -1,26 +1,22 @@
-.TH READDIR 3am "Sep 11 2012" "Free Software Foundation" "GNU Awk Extension Modules"
+.TH READDIR 3am "Nov 18 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("stat") # or "dirent" or "never"
.ft R
.SH DESCRIPTION
The
.I readdir
extension
-adds an input parser for directories, and
-adds a single function named
-.BR readdir_do_ftype() .
+adds an input parser for directories.
.PP
When this extension is in use, instead of skipping directories named
on the command line (or with
.BR getline ),
they are read, with each entry returned as a record.
.PP
-The record consists of at least two fields: the inode number and the
+The record consists of three fields. The first two are the inode number and the
filename, separated by a forward slash character.
On systems where the directory entry contains the file type, the record
has a third field which is a single letter indicating the type of the
@@ -42,28 +38,8 @@ for a socket, and
.B u
(unknown) for anything else.
.PP
-On systems without the file type information, calling
-.B readdir_do_ftype("stat")
-causes the extension to use
-.IR lstat (2)
-to retrieve the appropriate information. This is not the default, since
-.IR lstat (2)
-is a potentially expensive operation. By calling
-.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,
-.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.
+On systems without the file type information, the third field is always
+.BR u .
.SH NOTES
On GNU/Linux systems, there are filesystems that don't support the
.B d_type
@@ -71,13 +47,11 @@ entry (see
.IR readdir (3)),
and so the file type is always
.BR u .
-Therefore, using
-.B readdir_do_ftype("stat")
-is advisable even on GNU/Linux systems. In this case, the
-.I readdir
-extension will fall back to using
-.IR lstat (2)
-when it encounters an unknown file type.
+You can use the
+.I filefuncs
+extension to call
+.I stat()
+in order to get correct type information.
... .SH BUGS
.SH EXAMPLE
.ft CW
diff --git a/extension/readdir.c b/extension/readdir.c
index de430194..05ac8b90 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -6,6 +6,7 @@
* Written 7/2012
*
* Andrew Schorr and Arnold Robbins: further fixes 8/2012.
+ * Simplified 11/2012.
*/
/*
@@ -64,34 +65,18 @@ static awk_bool_t (*init_func)(void) = init_readdir;
int plugin_is_GPL_compatible;
-enum {
- NEVER_DO_INFO,
- USE_DIRENT_INFO,
- USE_STAT_INFO
-} do_ftype =
-#ifdef DT_BLK
- USE_DIRENT_INFO
-#else
- NEVER_DO_INFO
-#endif
- ;
-
/* data type for the opaque pointer: */
typedef struct open_directory {
DIR *dp;
char *buf;
- const char *path; /* directory path */
- char *dbuf; /* buffer for <directory>/<name> needed for lstat */
} open_directory_t;
/* ftype --- return type of file as a single character string */
static const char *
-ftype(struct dirent *entry, open_directory_t *the_dir)
+ftype(struct dirent *entry)
{
- struct stat sbuf;
-
#ifdef DT_BLK
switch (entry->d_type) {
case DT_BLK: return "b";
@@ -102,48 +87,11 @@ ftype(struct dirent *entry, open_directory_t *the_dir)
case DT_REG: return "f";
case DT_SOCK: return "s";
default:
- case DT_UNKNOWN:
- /*
- * Could be that filesystem doesn't support d_type,
- * even if the OS does. (E.g., XFS on GNU/Linux).
- * So let lstat() do it.
- */
- break;
- }
-#endif
-
- 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
- * filesystem.
- */
- return NULL;
-
- /* Should we set ERRNO here? */
- sprintf(the_dir->dbuf, "%s/%s", the_dir->path, entry->d_name);
- if (lstat(the_dir->dbuf, & sbuf) < 0)
- return "u";
-
- switch (sbuf.st_mode & S_IFMT) {
- case S_IFREG: return "f";
- case S_IFBLK: return "b";
- case S_IFCHR: return "c";
- case S_IFDIR: return "d";
-#ifdef S_IFSOCK
- case S_IFSOCK: return "s";
-#endif
-#ifdef S_IFIFO
- case S_IFIFO: return "p";
-#endif
-#ifdef S_IFLNK
- case S_IFLNK: return "l";
-#endif
-#ifdef S_IFDOOR /* Solaris weirdness */
- case S_IFDOOR: return "D";
-#endif /* S_IFDOOR */
+ case DT_UNKNOWN: return "u";
}
+#else
return "u";
+#endif
}
/* dir_get_record --- get one record at a time out of a directory */
@@ -156,6 +104,7 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode,
struct dirent *dirent;
int len;
open_directory_t *the_dir;
+ const char *ftstr;
/*
* The caller sets *errcode to 0, so we should set it only if an
@@ -188,11 +137,8 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode,
dirent->d_name);
#endif
- if (do_ftype != NEVER_DO_INFO) {
- const char *ftstr = ftype(dirent, the_dir);
- if (ftstr)
- len += sprintf(the_dir->buf + len, "/%s", ftstr);
- }
+ ftstr = ftype(dirent);
+ len += sprintf(the_dir->buf + len, "/%s", ftstr);
*out = the_dir->buf;
@@ -214,7 +160,6 @@ dir_close(awk_input_buf_t *iobuf)
closedir(the_dir->dp);
free(the_dir->buf);
- free(the_dir->dbuf);
free(the_dir);
iobuf->fd = -1;
@@ -263,8 +208,6 @@ dir_take_control_of(awk_input_buf_t *iobuf)
the_dir->dp = dp;
size = sizeof(struct dirent) + 21 /* max digits in inode */ + 2 /* slashes */;
emalloc(the_dir->buf, char *, size, "dir_take_control_of");
- emalloc(the_dir->dbuf, char *, strlen(iobuf->name)+size+2, "dir_take_control_of");
- the_dir->path = iobuf->name;
iobuf->opaque = the_dir;
iobuf->get_record = dir_get_record;
@@ -302,46 +245,8 @@ init_readdir()
return 1;
}
-/* do_readdir_do_ftype --- enable / disable ftype where need to do stat */
-
-static awk_value_t *
-do_readdir_do_ftype(int nargs, awk_value_t *result)
-{
- awk_value_t flag;
-
- 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)
- lintwarn(ext_id, _("readdir_do_ftype: called with more than one argument"));
-
- 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;
- }
-
- 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 {
- update_ERRNO_int(EINVAL);
- make_number(0.0, result);
- }
-
-out:
- return result;
-}
-
static awk_ext_func_t func_table[] = {
- { "readdir_do_ftype", do_readdir_do_ftype, 1 },
+ { NULL, NULL, 0 }
};
/* define the dl_load function using the boilerplate macro */
diff --git a/test/ChangeLog b/test/ChangeLog
index 8d9c814e..2b669517 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2012-11-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (readdir): Add a 'this could fail message'.
+ * readdir.awk: Revise to match simplified behavior of the extension.
+
2012-11-13 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (GAWK_EXTRA_TESTS): Move to sorted order of tests.
diff --git a/test/Makefile.am b/test/Makefile.am
index 0f78c442..fc1a1076 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1680,6 +1680,7 @@ assignconst:
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
readdir:
+ @echo This test can fail on some filesystems.
@echo $@
@ls -fli $(top_srcdir) | sed 1d | $(AWK) -f $(srcdir)/readdir0.awk > $@.ok
@$(AWK) -f $(srcdir)/readdir.awk $(top_srcdir) > _$@
diff --git a/test/Makefile.in b/test/Makefile.in
index 28fc43ce..040b49f2 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -2061,6 +2061,7 @@ assignconst:
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
readdir:
+ @echo This test can fail on some filesystems.
@echo $@
@ls -fli $(top_srcdir) | sed 1d | $(AWK) -f $(srcdir)/readdir0.awk > $@.ok
@$(AWK) -f $(srcdir)/readdir.awk $(top_srcdir) > _$@
diff --git a/test/readdir.awk b/test/readdir.awk
index 2e3df453..d407bbce 100644
--- a/test/readdir.awk
+++ b/test/readdir.awk
@@ -1,7 +1,3 @@
@load "readdir"
-BEGIN {
- readdir_do_ftype("stat")
-}
-
{ print }