From dc73df1834c98dc13ba9c22bc3d009f604c07af7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 8 Jul 2020 08:32:30 -0700 Subject: Expose low-level opendir/readdir dir traversal. * stream.c (UTF_DECL_OPENDIR): Macro defined, to enable w_opendir declaration in utf8.h. (w_opendir): Static function removed. * sysif.c (UTF_DECL_OPENDIR): Macro defined. (dir_s): Symbol defined unconditionally now, regardless of HAVE_PWUID. (dirent_s): New symbol. (dirent_st): New static variable. (struct dir): New struct type. (opendir_free, opendir_mark opendir_wrap, readdir_wrap): New static functions. (opendir_ops): New static structure. (sysif_init): Intern dirent symbol. Create dirent structure type. Register opendir and readdir intrinsic functions. Register variables dt-blk, dt-chr, dt-dir, dt-fifo, dt-lnk, dt-reg, dt-sock and dt-unknown. * utf8.c (UTF8_DECL_OPENDIR): Macro defined. (w_opendir): Function moved here from stream.c, and turned external. * utf8.h (w_opendir): Declared, conditionally on UTF8_DECL_OPENDIR being defined, so that most modules that include utf8.h don't have to include . * txr.1: Documented. diff --git a/sysif.c b/sysif.c --- utf8.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'utf8.c') diff --git a/utf8.c b/utf8.c index 2760c718..39d1e1c4 100644 --- a/utf8.c +++ b/utf8.c @@ -25,11 +25,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define UTF8_DECL_OPENDIR #include #include #include #include #include +#include #include "config.h" #include "lib.h" #include "signal.h" @@ -415,3 +417,11 @@ int w_rename(const wchar_t *wfrom, const wchar_t *wto) free(from); return err; } + +DIR *w_opendir(const wchar_t *wname) +{ + char *name = utf8_dup_to(wname); + DIR *d = opendir(name); + free(name); + return d; +} -- cgit v1.2.3