summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-07-08 08:32:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-07-08 08:32:30 -0700
commitdc73df1834c98dc13ba9c22bc3d009f604c07af7 (patch)
tree1dcf1acbb9c7b0825e460b01feef7d5d7b410647 /utf8.c
parent107242691ea0317095bcb42378128de0eb4bbe57 (diff)
downloadtxr-dc73df1834c98dc13ba9c22bc3d009f604c07af7.tar.gz
txr-dc73df1834c98dc13ba9c22bc3d009f604c07af7.tar.bz2
txr-dc73df1834c98dc13ba9c22bc3d009f604c07af7.zip
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 <dirent.h>. * txr.1: Documented. diff --git a/sysif.c b/sysif.c
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c10
1 files changed, 10 insertions, 0 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <signal.h>
+#include <dirent.h>
#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;
+}