[m-users.] Bug in posix.readdir (fixed)
Julien Fischer
jfischer at opturion.com
Mon Oct 14 10:25:24 AEDT 2019
Hi Volker,
On Fri, 11 Oct 2019, Volker Wysk wrote:
> The readdir/4 predicate from the posix library is buggy. It returns an
> "unknown error code" error for the end of the directory stream.
>
>
> I've fixed it. I've changed the type from
>
> :- pred readdir(dir::in,
> posix.result(string)::out,
> io::di, io::uo) is det.
>
> to
>
> :- pred readdir(dir::in,
> posix.result(maybe(string))::out,
> io::di, io::uo) is det.
>
>
> The new version returns "posix.ok(yes(File))" for a directory entry,
> and "posix.ok(no)" for the end of the stream.
I don't like returning a maybe type like that, it means you need
two levels of switching at call sites for readdir/4. I suggest
adding the type:
:- type readdir_result
---> ok(string)
; eof
; error(posix.error).
and using that.
> See the attached file. It should replace the posix.readdir.m file from
> the posix library (after renaming from readdir to posix.readdir).
Thanks for that. I'll apply that change (except with new return type
above).
Julien.
More information about the users
mailing list