aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-03-17 20:10:03 +0200
committerArnold D. Robbins <arnold@skeeve.com>2019-03-17 20:10:03 +0200
commitf961cdf2b5f7392cc1ced4ea0c13510792151e64 (patch)
tree73752d2b91f76ec75e9ac681c5c1f1f1107cabda
parentcc4a81433f96f0c93b5ab2c16673aea9ca2084ea (diff)
downloadegawk-f961cdf2b5f7392cc1ced4ea0c13510792151e64.tar.gz
egawk-f961cdf2b5f7392cc1ced4ea0c13510792151e64.tar.bz2
egawk-f961cdf2b5f7392cc1ced4ea0c13510792151e64.zip
Fix readdir extension to use stat when dir info returns unknown.
-rw-r--r--extension/ChangeLog6
-rw-r--r--extension/readdir.3am26
-rw-r--r--extension/readdir.c10
-rw-r--r--extension/readdir_test.c10
4 files changed, 24 insertions, 28 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index ddce96ab..3f19c4a6 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2019-03-17 Arnold D. Robbins <arnold@skeeve.com>
+
+ * readdir.c: Change to use stat when dir info is 'u'. Bump version.
+ * readdir_test.c: Ditto.
+ * readdir.3am: Document same.
+
2019-02-15 Arnold D. Robbins <arnold@skeeve.com>
* inplace.c (do_inplace_end): Fix error message to use inplace::end.
diff --git a/extension/readdir.3am b/extension/readdir.3am
index 9cec8606..e4f24dff 100644
--- a/extension/readdir.3am
+++ b/extension/readdir.3am
@@ -1,4 +1,4 @@
-.TH READDIR 3am "Feb 02 2018" "Free Software Foundation" "GNU Awk Extension Modules"
+.TH READDIR 3am "Mar 17 2019" "Free Software Foundation" "GNU Awk Extension Modules"
.SH NAME
readdir \- directory input parser for gawk
.SH SYNOPSIS
@@ -34,24 +34,14 @@ for a FIFO,
.B l
for a symbolic link,
.B s
-for a socket, and
-.B u
-(unknown) for anything else.
+for a socket.
.PP
-On systems without the file type information, the third field is always
+On systems without the file type information, the extension falls back
+to calling
+.IR stat (2),
+in order to provide the information.
+Thus the third field should never be
.BR u .
-.SH NOTES
-On GNU/Linux systems, there are filesystems that don't support the
-.B d_type
-entry (see
-.IR readdir (3)),
-and so the file type is always
-.BR u .
-You can use the
-.I filefuncs
-extension to call
-.I stat()
-in order to get correct type information.
.\" .SH BUGS
.SH EXAMPLE
.ft CW
@@ -81,7 +71,7 @@ BEGIN { FS = "/" }
Arnold Robbins,
.BR arnold@skeeve.com .
.SH COPYING PERMISSIONS
-Copyright \(co 2012, 2013, 2018,
+Copyright \(co 2012, 2013, 2018, 2019
Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
diff --git a/extension/readdir.c b/extension/readdir.c
index e8deecdd..cc1cd505 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -7,10 +7,11 @@
*
* Andrew Schorr and Arnold Robbins: further fixes 8/2012.
* Simplified 11/2012.
+ * Improved 3/2019.
*/
/*
- * Copyright (C) 2012-2014, 2018 the Free Software Foundation, Inc.
+ * Copyright (C) 2012-2014, 2018, 2019 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -73,7 +74,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t ext_id;
-static const char *ext_version = "readdir extension: version 1.0";
+static const char *ext_version = "readdir extension: version 2.0";
static awk_bool_t init_readdir(void);
static awk_bool_t (*init_func)(void) = init_readdir;
@@ -103,9 +104,9 @@ ftype(struct dirent *entry, const char *dirname)
case DT_REG: return "f";
case DT_SOCK: return "s";
default:
- case DT_UNKNOWN: return "u";
+ case DT_UNKNOWN: break; // JFS returns 'u', so fall through and stat
}
-#else
+#endif
char fname[PATH_MAX];
struct stat sbuf;
@@ -133,7 +134,6 @@ ftype(struct dirent *entry, const char *dirname)
#endif
}
return "u";
-#endif
}
/* get_inode --- get the inode of a file */
diff --git a/extension/readdir_test.c b/extension/readdir_test.c
index 074d4ede..13bf667c 100644
--- a/extension/readdir_test.c
+++ b/extension/readdir_test.c
@@ -7,10 +7,11 @@
*
* Andrew Schorr and Arnold Robbins: further fixes 8/2012.
* Simplified 11/2012.
+ * Improved 3/2019.
*/
/*
- * Copyright (C) 2012-2014, 2017, 2018 the Free Software Foundation, Inc.
+ * Copyright (C) 2012-2014, 2017, 2018, 2019 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -73,7 +74,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t ext_id;
-static const char *ext_version = "readdir extension: version 2.0";
+static const char *ext_version = "readdir extension: version 3.0";
static awk_bool_t init_readdir(void);
static awk_bool_t (*init_func)(void) = init_readdir;
@@ -108,9 +109,9 @@ ftype(struct dirent *entry, const char *dirname)
case DT_REG: return "f";
case DT_SOCK: return "s";
default:
- case DT_UNKNOWN: return "u";
+ case DT_UNKNOWN: break; // JFS returns 'u', so fall through to stat
}
-#else
+#endif
char fname[PATH_MAX];
struct stat sbuf;
@@ -138,7 +139,6 @@ ftype(struct dirent *entry, const char *dirname)
#endif
}
return "u";
-#endif
}
/* get_inode --- get the inode of a file */