[m-rev.] for review: add dir.current_directory
Peter Wang
novalazy at gmail.com
Thu Sep 20 10:57:30 AEST 2007
On 2007-09-19, Peter Ross <pro at missioncriticalit.com> wrote:
> >
> > +:- pragma foreign_proc("C",
> > + dir.current_directory(Res::out, IO0::di, IO::uo),
> > + [may_call_mercury, promise_pure, tabled_for_io, terminates],
> > +"
> > + size_t size = 256;
> > + char *buf;
> > + MR_String str;
> > +
> > + while (1) {
> > + buf = MR_GC_NEW_ARRAY(char, size);
> > + if (getcwd(buf, size)) {
> > + MR_make_aligned_string(str, buf);
> > + Res = ML_make_io_res_1_ok_string(str);
> > + break;
> > + }
> > + if (errno != ERANGE) {
> > + ML_make_io_res_1_error_string(errno,
> > + MR_make_string_const(""dir.current_directory failed: ""),
> > + &Res);
>
> You should use strerror to get the actual error message.
ML_make_io_res_1_error_string does that.
> Note don't forget to test if the result is the empty string, in which
> case a more informatiive error message would be useful.
If that can happen it should be handled in ML_maybe_make_err_msg which
is called by everything else.
Peter
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list