From 1d8d2214495fa29931948e08041cc8a1159fdd19 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 9 Jul 2020 20:28:31 -0700 Subject: Add missing closedir. * sysif.c (opendir_free): Since d->dir may now be null, avoid calling closedir on it in that situation. Also, set d->dir to null after closedir. (closedir_wrap): New static function. (readdir_wrap): If the d->dir is null, safely treat that as a directory entry not being available; do not pass a null DIR pointer to readdir. (sysif_init): Register intrinsic function closedir. * txr.1: Documented, plus spelling error fix under readdir. --- txr.1 | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index a86d5e6c..4fd20484 100644 --- a/txr.1 +++ b/txr.1 @@ -62862,6 +62862,10 @@ If no more directory entries remain, then .code readdir returns .codn nil . +In this situation, the +.meta dir-handle +is also closed, as if by a call to +.codn closedir . Otherwise, the next available directory entry is returned as a structure object of type @@ -62869,7 +62873,7 @@ structure object of type The .code readdir -function intenally skips and does not report the +function internally skips and does not report the .str . (dot) and @@ -62891,6 +62895,37 @@ allocates a fresh .code dirent structure. +.coNP Function @ closedir +.synb +.mets (opendir << dir-handle ) +.syne +.desc +The +.code closedir +function terminates the directory traversal managed by +.metn dir-handle , +releasing its resources. + +If this has already been done before, +.code closedir +returns +.codn nil , +otherwise it returns +.codn t . + +Further +.code readdir +calls on the same +.meta dir-handle +return +.codn nil . + +Note: the +.code readdir +function implicitly closes +.meta dir-handle +when the handle indicates that no more directory entries remain to be traversed. + .SS* Unix Sockets On platforms where the underlying system interface is available, \*(TX provides -- cgit v1.2.3