[m-rev.] for review: add dir.current_directory
Peter Ross
pro at missioncriticalit.com
Thu Sep 20 11:19:24 AEST 2007
On 9/20/07, Peter Wang <novalazy at gmail.com> wrote:
> 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.
>
OK, I see how it works now.
> > 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.
>
OK
--------------------------------------------------------------------------
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