From abc74473ed37336a924b135e656ba40eeecc064b Mon Sep 17 00:00:00 2001 From: Kaz Kyheku Date: Tue, 28 Jan 2020 08:28:21 -0800 Subject: ftw: throw exception on failure. The ftw function just returns -1 if, for instance, given a bad path (nonexistent or no permissions). The documentation also has issues. * ftw.c (ftw_wrap): If the return value is -1, convert it to a file-error using errno_to_file_error and throw a diagnostic exception. This situation can, of course, arise if the callback function returns -1, in which case it should prepare a value in errno. * txr.1: Return value of callbackfn documented better. Documented exception throwing behavior, and failed termination if the callback returns -1. --- ftw.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ftw.c') diff --git a/ftw.c b/ftw.c index 27b8e790..537e6d4f 100644 --- a/ftw.c +++ b/ftw.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include "config.h" #include "alloca.h" @@ -122,7 +124,11 @@ val ftw_wrap(val dirpath, val fn, val flags_in, val nopenfd_in) case 0: return t; case -1: - return nil; + { + int eno = errno; + uw_throwf(errno_to_file_error(eno), lit("ftw ~a: ~d/~s"), + dirpath, num(eno), string_utf8(strerror(eno)), nao); + } default: return num(res); } -- cgit v1.2.3