summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2023-02-27 22:19:19 +0200
committerArnold D. Robbins <arnold@skeeve.com>2023-02-27 22:19:19 +0200
commitd5c88fbbbc92b80f424d35e5fd8cf3ede854dd87 (patch)
tree2ca3a92a4ab8522f0b3df983eee457c52e877de7
parent6e98a8184b52173cf961cc4052bdd81c33b04244 (diff)
downloadgawk-d5c88fbbbc92b80f424d35e5fd8cf3ede854dd87.tar.gz
Squashed commit of the following:
commit 4a145797803d4e16b3461d844464e753bf2ed5cf Author: Arnold D. Robbins <arnold@skeeve.com> Date: Mon Feb 27 21:58:06 2023 +0200 Update ChangeLogs and doc. commit a0262e53529c2f75dc4930dbeb95f47d526fd5d5 Merge: 6dd3e482 6e98a818 Author: Arnold D. Robbins <arnold@skeeve.com> Date: Mon Feb 27 21:35:08 2023 +0200 Merge branch 'gawk-5.2-stable' into private/fixes-for-readdir commit 6dd3e48226e365f8c2f1398037064c73f4f67ddb Author: Arnold D. Robbins <arnold@skeeve.com> Date: Sun Feb 26 21:45:18 2023 +0200 Improvements for setting up input parser.
-rw-r--r--ChangeLog6
-rw-r--r--NEWS6
-rw-r--r--configh.in3
-rwxr-xr-xconfigure6
-rw-r--r--configure.ac1
-rw-r--r--doc/ChangeLog1
-rw-r--r--doc/gawk.info280
-rw-r--r--doc/gawk.texi10
-rw-r--r--doc/gawktexi.in10
-rw-r--r--extension/ChangeLog5
-rw-r--r--extension/readdir.c2
-rw-r--r--io.c17
12 files changed, 205 insertions, 142 deletions
diff --git a/ChangeLog b/ChangeLog
index ad82e180..4bf60db4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,12 @@
* interpret.h (r_interpret): Handle Op_store_field in the switch.
* profile.c (pprint): Same.
+ Unrelated: Improve how information is passed to input parsers:
+
+ * io.c (iop_alloc): lstat() or stat() the file if could not be opened.
+ See the doc for explanation as to why.
+ * NEWS: Updated.
+
2023-02-26 Arnold D. Robbins <arnold@skeeve.com>
* Multiple files: Remove trailing whitespace.
diff --git a/NEWS b/NEWS
index d6437ce7..ca2ac451 100644
--- a/NEWS
+++ b/NEWS
@@ -27,7 +27,11 @@ Changes from 5.2.1 to 5.2.2
6. The time extension is no longer deprecated. The strptime() function
from gawkextlib's timex extension has been added to it.
-7. As usual, there have been several minor code cleanups and bug fixes.
+7. Better information is passed to input parsers for when they want to
+ decide whether or not to take control of a file. In particular, the
+ readdir extension is simplified for Windows because of this.
+
+8. As usual, there have been several minor code cleanups and bug fixes.
See the ChangeLog for details.
Changes from 5.2.0 to 5.2.1
diff --git a/configh.in b/configh.in
index e82ae154..fa922263 100644
--- a/configh.in
+++ b/configh.in
@@ -123,6 +123,9 @@
/* Define to 1 if the system has the type 'long long int'. */
#undef HAVE_LONG_LONG_INT
+/* Define to 1 if you have the `lstat' function. */
+#undef HAVE_LSTAT
+
/* Define to 1 if you have the `mbrlen' function. */
#undef HAVE_MBRLEN
diff --git a/configure b/configure
index b7020b38..f97ec96d 100755
--- a/configure
+++ b/configure
@@ -12246,6 +12246,12 @@ then :
printf "%s\n" "#define HAVE_ISWUPPER 1" >>confdefs.h
fi
+ac_fn_c_check_func "$LINENO" "lstat" "ac_cv_func_lstat"
+if test "x$ac_cv_func_lstat" = xyes
+then :
+ printf "%s\n" "#define HAVE_LSTAT 1" >>confdefs.h
+
+fi
ac_fn_c_check_func "$LINENO" "mbrlen" "ac_cv_func_mbrlen"
if test "x$ac_cv_func_mbrlen" = xyes
then :
diff --git a/configure.ac b/configure.ac
index 18b42bc4..e09f63aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -316,6 +316,7 @@ esac
# Need the check for mkstemp and tmpfile for missing_d/snprintf.c.
AC_CHECK_FUNCS(__etoa_l atexit btowc fmod fwrite_unlocked gai_strerror \
getgrent getgroups grantpt isascii isblank iswctype iswlower iswupper \
+ lstat \
mbrlen memcmp memcpy memmove memset \
mkstemp mtrace posix_openpt setenv setlocale setsid sigprocmask \
snprintf strcasecmp strchr strcoll strerror strftime strncasecmp \
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 315b1195..c2ffca29 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -3,6 +3,7 @@
* gawktexi.in (Include Files): Mention that -i and @include are
the same and that files are only included once, even if nested
in multiple include files.
+ (Input Parsers): Improve discussion of struct stat buf.
2023-02-26 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/doc/gawk.info b/doc/gawk.info
index 0a55097b..cf15cde5 100644
--- a/doc/gawk.info
+++ b/doc/gawk.info
@@ -26745,7 +26745,17 @@ as follows:
‘struct stat sbuf;’
If the file descriptor is valid, then ‘gawk’ will have filled in
- this structure via a call to the ‘fstat()’ system call.
+ this structure via a call to the ‘fstat()’ system call. Otherwise,
+ if the ‘lstat()’ system call is available, it will use that. If
+ ‘lstat()’ is not available, then it uses ‘stat()’. Getting the
+ file’s information allows extensions to check the type of the file
+ even if it could not be opened. This occurs, for example, on
+ Windows systems when trying to use ‘open()’ on a directory.
+
+ If ‘gawk’ was not able to get the file information, then ‘sbuf’
+ will be zeroed out. In particular, extension code can check if
+ ‘sbuf.st_mode == 0’. If that’s true, then there is no information
+ in ‘sbuf’.
The ‘XXX_can_take_file()’ function should examine these fields and
decide if the input parser should be used for the file. The decision
@@ -39775,140 +39785,140 @@ Node: Extension Functions1113097
Node: Exit Callback Functions1118673
Node: Extension Version String1119992
Node: Input Parsers1120687
-Node: Output Wrappers1134179
-Node: Two-way processors1138887
-Node: Printing Messages1141248
-Ref: Printing Messages-Footnote-11142462
-Node: Updating ERRNO1142617
-Node: Requesting Values1143416
-Ref: table-value-types-returned1144169
-Node: Accessing Parameters1145278
-Node: Symbol Table Access1146562
-Node: Symbol table by name1147078
-Ref: Symbol table by name-Footnote-11150289
-Node: Symbol table by cookie1150421
-Ref: Symbol table by cookie-Footnote-11154702
-Node: Cached values1154766
-Ref: Cached values-Footnote-11158410
-Node: Array Manipulation1158567
-Ref: Array Manipulation-Footnote-11159670
-Node: Array Data Types1159707
-Ref: Array Data Types-Footnote-11162529
-Node: Array Functions1162629
-Node: Flattening Arrays1167658
-Node: Creating Arrays1174710
-Node: Redirection API1179560
-Node: Extension API Variables1182581
-Node: Extension Versioning1183306
-Ref: gawk-api-version1183743
-Node: Extension GMP/MPFR Versioning1185531
-Node: Extension API Informational Variables1187237
-Node: Extension API Boilerplate1188398
-Node: Changes from API V11192534
-Node: Finding Extensions1194168
-Node: Extension Example1194743
-Node: Internal File Description1195567
-Node: Internal File Ops1199891
-Ref: Internal File Ops-Footnote-11211449
-Node: Using Internal File Ops1211597
-Ref: Using Internal File Ops-Footnote-11214028
-Node: Extension Samples1214306
-Node: Extension Sample File Functions1215875
-Node: Extension Sample Fnmatch1224013
-Node: Extension Sample Fork1225608
-Node: Extension Sample Inplace1226884
-Node: Extension Sample Ord1230556
-Node: Extension Sample Readdir1231432
-Ref: table-readdir-file-types1232329
-Node: Extension Sample Revout1233467
-Node: Extension Sample Rev2way1234064
-Node: Extension Sample Read write array1234816
-Node: Extension Sample Readfile1238090
-Node: Extension Sample Time1239221
-Node: Extension Sample API Tests1241511
-Node: gawkextlib1242019
-Node: Extension summary1245055
-Node: Extension Exercises1248913
-Node: Language History1250191
-Node: V7/SVR3.11251905
-Node: SVR41254255
-Node: POSIX1255787
-Node: BTL1257212
-Node: POSIX/GNU1257981
-Node: Feature History1264512
-Node: Common Extensions1283630
-Node: Ranges and Locales1284999
-Ref: Ranges and Locales-Footnote-11289800
-Ref: Ranges and Locales-Footnote-21289827
-Ref: Ranges and Locales-Footnote-31290066
-Node: Contributors1290289
-Node: History summary1296494
-Node: Installation1297940
-Node: Gawk Distribution1298904
-Node: Getting1299396
-Node: Extracting1300395
-Node: Distribution contents1302107
-Node: Unix Installation1310187
-Node: Quick Installation1311009
-Node: Compiling with MPFR1313555
-Node: Shell Startup Files1314261
-Node: Additional Configuration Options1315418
-Node: Configuration Philosophy1317805
-Node: Compiling from Git1320307
-Node: Building the Documentation1320866
-Node: Non-Unix Installation1322278
-Node: PC Installation1322754
-Node: PC Binary Installation1323627
-Node: PC Compiling1324532
-Node: PC Using1325710
-Node: Cygwin1329438
-Node: MSYS1330694
-Node: OpenVMS Installation1331326
-Node: OpenVMS Compilation1332007
-Ref: OpenVMS Compilation-Footnote-11333490
-Node: OpenVMS Dynamic Extensions1333552
-Node: OpenVMS Installation Details1335188
-Node: OpenVMS Running1337623
-Node: OpenVMS GNV1341760
-Node: Bugs1342515
-Node: Bug definition1343439
-Node: Bug address1347090
-Node: Usenet1350681
-Node: Performance bugs1351912
-Node: Asking for help1354930
-Node: Maintainers1356921
-Node: Other Versions1357948
-Node: Installation summary1366880
-Node: Notes1368264
-Node: Compatibility Mode1369074
-Node: Additions1369896
-Node: Accessing The Source1370841
-Node: Adding Code1372376
-Node: New Ports1379512
-Node: Derived Files1384022
-Ref: Derived Files-Footnote-11389869
-Ref: Derived Files-Footnote-21389904
-Ref: Derived Files-Footnote-31390521
-Node: Future Extensions1390635
-Node: Implementation Limitations1391307
-Node: Extension Design1392549
-Node: Old Extension Problems1393713
-Ref: Old Extension Problems-Footnote-11395289
-Node: Extension New Mechanism Goals1395350
-Ref: Extension New Mechanism Goals-Footnote-11398846
-Node: Extension Other Design Decisions1399047
-Node: Extension Future Growth1401246
-Node: Notes summary1401870
-Node: Basic Concepts1403083
-Node: Basic High Level1403768
-Ref: figure-general-flow1404050
-Ref: figure-process-flow1404752
-Ref: Basic High Level-Footnote-11408148
-Node: Basic Data Typing1408337
-Node: Glossary1411755
-Node: Copying1444877
-Node: GNU Free Documentation License1482638
-Node: Index1507961
+Node: Output Wrappers1134797
+Node: Two-way processors1139505
+Node: Printing Messages1141866
+Ref: Printing Messages-Footnote-11143080
+Node: Updating ERRNO1143235
+Node: Requesting Values1144034
+Ref: table-value-types-returned1144787
+Node: Accessing Parameters1145896
+Node: Symbol Table Access1147180
+Node: Symbol table by name1147696
+Ref: Symbol table by name-Footnote-11150907
+Node: Symbol table by cookie1151039
+Ref: Symbol table by cookie-Footnote-11155320
+Node: Cached values1155384
+Ref: Cached values-Footnote-11159028
+Node: Array Manipulation1159185
+Ref: Array Manipulation-Footnote-11160288
+Node: Array Data Types1160325
+Ref: Array Data Types-Footnote-11163147
+Node: Array Functions1163247
+Node: Flattening Arrays1168276
+Node: Creating Arrays1175328
+Node: Redirection API1180178
+Node: Extension API Variables1183199
+Node: Extension Versioning1183924
+Ref: gawk-api-version1184361
+Node: Extension GMP/MPFR Versioning1186149
+Node: Extension API Informational Variables1187855
+Node: Extension API Boilerplate1189016
+Node: Changes from API V11193152
+Node: Finding Extensions1194786
+Node: Extension Example1195361
+Node: Internal File Description1196185
+Node: Internal File Ops1200509
+Ref: Internal File Ops-Footnote-11212067
+Node: Using Internal File Ops1212215
+Ref: Using Internal File Ops-Footnote-11214646
+Node: Extension Samples1214924
+Node: Extension Sample File Functions1216493
+Node: Extension Sample Fnmatch1224631
+Node: Extension Sample Fork1226226
+Node: Extension Sample Inplace1227502
+Node: Extension Sample Ord1231174
+Node: Extension Sample Readdir1232050
+Ref: table-readdir-file-types1232947
+Node: Extension Sample Revout1234085
+Node: Extension Sample Rev2way1234682
+Node: Extension Sample Read write array1235434
+Node: Extension Sample Readfile1238708
+Node: Extension Sample Time1239839
+Node: Extension Sample API Tests1242129
+Node: gawkextlib1242637
+Node: Extension summary1245673
+Node: Extension Exercises1249531
+Node: Language History1250809
+Node: V7/SVR3.11252523
+Node: SVR41254873
+Node: POSIX1256405
+Node: BTL1257830
+Node: POSIX/GNU1258599
+Node: Feature History1265130
+Node: Common Extensions1284248
+Node: Ranges and Locales1285617
+Ref: Ranges and Locales-Footnote-11290418
+Ref: Ranges and Locales-Footnote-21290445
+Ref: Ranges and Locales-Footnote-31290684
+Node: Contributors1290907
+Node: History summary1297112
+Node: Installation1298558
+Node: Gawk Distribution1299522
+Node: Getting1300014
+Node: Extracting1301013
+Node: Distribution contents1302725
+Node: Unix Installation1310805
+Node: Quick Installation1311627
+Node: Compiling with MPFR1314173
+Node: Shell Startup Files1314879
+Node: Additional Configuration Options1316036
+Node: Configuration Philosophy1318423
+Node: Compiling from Git1320925
+Node: Building the Documentation1321484
+Node: Non-Unix Installation1322896
+Node: PC Installation1323372
+Node: PC Binary Installation1324245
+Node: PC Compiling1325150
+Node: PC Using1326328
+Node: Cygwin1330056
+Node: MSYS1331312
+Node: OpenVMS Installation1331944
+Node: OpenVMS Compilation1332625
+Ref: OpenVMS Compilation-Footnote-11334108
+Node: OpenVMS Dynamic Extensions1334170
+Node: OpenVMS Installation Details1335806
+Node: OpenVMS Running1338241
+Node: OpenVMS GNV1342378
+Node: Bugs1343133
+Node: Bug definition1344057
+Node: Bug address1347708
+Node: Usenet1351299
+Node: Performance bugs1352530
+Node: Asking for help1355548
+Node: Maintainers1357539
+Node: Other Versions1358566
+Node: Installation summary1367498
+Node: Notes1368882
+Node: Compatibility Mode1369692
+Node: Additions1370514
+Node: Accessing The Source1371459
+Node: Adding Code1372994
+Node: New Ports1380130
+Node: Derived Files1384640
+Ref: Derived Files-Footnote-11390487
+Ref: Derived Files-Footnote-21390522
+Ref: Derived Files-Footnote-31391139
+Node: Future Extensions1391253
+Node: Implementation Limitations1391925
+Node: Extension Design1393167
+Node: Old Extension Problems1394331
+Ref: Old Extension Problems-Footnote-11395907
+Node: Extension New Mechanism Goals1395968
+Ref: Extension New Mechanism Goals-Footnote-11399464
+Node: Extension Other Design Decisions1399665
+Node: Extension Future Growth1401864
+Node: Notes summary1402488
+Node: Basic Concepts1403701
+Node: Basic High Level1404386
+Ref: figure-general-flow1404668
+Ref: figure-process-flow1405370
+Ref: Basic High Level-Footnote-11408766
+Node: Basic Data Typing1408955
+Node: Glossary1412373
+Node: Copying1445495
+Node: GNU Free Documentation License1483256
+Node: Index1508579

End Tag Table
diff --git a/doc/gawk.texi b/doc/gawk.texi
index b49670a6..cd75aae0 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -36969,6 +36969,16 @@ able to open the file, then @code{fd} will @emph{not} be equal to
@item struct stat sbuf;
If the file descriptor is valid, then @command{gawk} will have filled
in this structure via a call to the @code{fstat()} system call.
+Otherwise, if the @code{lstat()} system call is available, it will
+use that. If @code{lstat()} is not available, then it uses @code{stat()}.
+Getting the file's information allows extensions to check the type of
+the file even if it could not be opened. This occurs, for example,
+on Windows systems when trying to use @code{open()} on a directory.
+
+If @command{gawk} was not able to get the file information, then
+@code{sbuf} will be zeroed out. In particular, extension code
+can check if @samp{sbuf.st_mode == 0}. If that's true, then there
+is no information in @code{sbuf}.
@end table
The @code{@var{XXX}_can_take_file()} function should examine these
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 3e448340..219a8929 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -35885,6 +35885,16 @@ able to open the file, then @code{fd} will @emph{not} be equal to
@item struct stat sbuf;
If the file descriptor is valid, then @command{gawk} will have filled
in this structure via a call to the @code{fstat()} system call.
+Otherwise, if the @code{lstat()} system call is available, it will
+use that. If @code{lstat()} is not available, then it uses @code{stat()}.
+Getting the file's information allows extensions to check the type of
+the file even if it could not be opened. This occurs, for example,
+on Windows systems when trying to use @code{open()} on a directory.
+
+If @command{gawk} was not able to get the file information, then
+@code{sbuf} will be zeroed out. In particular, extension code
+can check if @samp{sbuf.st_mode == 0}. If that's true, then there
+is no information in @code{sbuf}.
@end table
The @code{@var{XXX}_can_take_file()} function should examine these
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 14b95fa0..afc5e58b 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2023-02-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * readdir.c (dir_can_take_file): Test is more flexible, based on
+ change in gawk's iop.c:iop_alloc() function.
+
2023-02-09 Arnold D. Robbins <arnold@skeeve.com>
* readdir.c (dir_can_take_control_of): If ! HAVE_OPENDIR,
diff --git a/extension/readdir.c b/extension/readdir.c
index 8ec695d7..2499b4e2 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -249,7 +249,7 @@ dir_can_take_file(const awk_input_buf_t *iobuf)
if (iobuf == NULL)
return awk_false;
- return (iobuf->fd != INVALID_HANDLE && S_ISDIR(iobuf->sbuf.st_mode));
+ return (iobuf->fd != INVALID_HANDLE || S_ISDIR(iobuf->sbuf.st_mode));
}
/*
diff --git a/io.c b/io.c
index 979cad45..dcbec287 100644
--- a/io.c
+++ b/io.c
@@ -3377,12 +3377,19 @@ iop_alloc(int fd, const char *name, int errno_val)
if (fd != INVALID_HANDLE)
fstat(fd, & iop->public.sbuf);
-#if defined(__MINGW32__)
- else if (errno_val == EISDIR) {
- iop->public.sbuf.st_mode = (_S_IFDIR | _S_IRWXU);
- iop->public.fd = FAKE_FD_VALUE;
- }
+ else {
+#ifdef HAVE_LSTAT
+ int (*statf)(const char *, struct stat *) = lstat;
+#else
+ int (*statf)(const char *, struct stat *) = stat;
#endif
+ /*
+ * Try to fill in the stat struct. If it fails, zero
+ * it out.
+ */
+ if (statf(name, & iop->public.sbuf) < 0)
+ memset(& iop->public.sbuf, 0, sizeof(struct stat));
+ }
return iop;
}