Jump to page: 1 2
Thread overview
Setting errno?
Aug 15, 2004
Nick
Aug 15, 2004
Arcane Jill
Aug 15, 2004
Nick
Aug 15, 2004
Nick
Aug 15, 2004
Walter
Aug 15, 2004
Nick
Aug 16, 2004
Walter
Aug 16, 2004
Nick
Aug 17, 2004
Regan Heath
Aug 17, 2004
Walter
Aug 17, 2004
Martin M. Pedersen
Aug 18, 2004
Matthew
Aug 18, 2004
Martin M. Pedersen
August 15, 2004
Is there any simple way to set the unix error value errno to zero? D implements getErrno(), but it seems like library functions never reset errno unless a new error occurs.

Nick



August 15, 2004
In article <cfns9k$m9f$1@digitaldaemon.com>, Nick says...
>
>Is there any simple way to set the unix error value errno to zero? D implements getErrno(), but it seems like library functions never reset errno unless a new error occurs.
>
>Nick

I don't know the answer to this, but in any case, I'm not sure it's a practice we should be encouraging. The manual section "Error Handling in D" at http://www.digitalmars.com/d/errors.html explains why I think using errno is not a good idea.

Arcane Jill


August 15, 2004
In article <cfntcf$mq7$1@digitaldaemon.com>, Arcane Jill says...
>
>I don't know the answer to this, but in any case, I'm not sure it's a practice we should be encouraging. The manual section "Error Handling in D" at http://www.digitalmars.com/d/errors.html explains why I think using errno is not a good idea.

I agree with this, but my use for errno is strictly for interfacing with C library functions, not for writing new code using this method of error reporting. I plan to encapsulate the errno entirely inside a class, making the internal workings invisible to the user. You can then write wrapper functions like this

// Sets errno on failure
extern(C) { char *some_func(int); }

char[] someWrapper(int a)
{
char *p = some_func(a);
if( Errno.error() )
throw new MyException(Errno.msg()); // Errno.msg() also 'clears' the error
return std.string.toString(p);
}

The last part, where msg() clears the error, is hard to do if you can't change
errno.

Nick


August 15, 2004
In article <cfns9k$m9f$1@digitaldaemon.com>, Nick says...
>
>Is there any simple way to set the unix error value errno to zero? D implements getErrno(), but it seems like library functions never reset errno unless a new error occurs.

Nevermind, I settled for just writing it in C myself.

Nick


August 15, 2004
"Nick" <Nick_member@pathlink.com> wrote in message news:cfo8u7$u1i$1@digitaldaemon.com...
> In article <cfns9k$m9f$1@digitaldaemon.com>, Nick says...
> >
> >Is there any simple way to set the unix error value errno to zero? D
implements
> >getErrno(), but it seems like library functions never reset errno unless
a new
> >error occurs.
>
> Nevermind, I settled for just writing it in C myself.

You kind of have to write setErrno() in C, because errno is typically
defined as a macro in <errno.h>. This is why getErrno() is written in C.


August 15, 2004
In article <cfoao7$v10$1@digitaldaemon.com>, Walter says...
>
>You kind of have to write setErrno() in C, because errno is typically
>defined as a macro in <errno.h>. This is why getErrno() is written in C.
>

Yep. But I was sort of hoping you would put it in phobos like you did with getErrno() so I wouldn't have to drag along the extra object file all the time. But it's really no big deal.

Nick


August 16, 2004
"Nick" <Nick_member@pathlink.com> wrote in message news:cfocpc$10ac$1@digitaldaemon.com...
> In article <cfoao7$v10$1@digitaldaemon.com>, Walter says...
> >
> >You kind of have to write setErrno() in C, because errno is typically
> >defined as a macro in <errno.h>. This is why getErrno() is written in C.
> >
>
> Yep. But I was sort of hoping you would put it in phobos like you did with getErrno() so I wouldn't have to drag along the extra object file all the
time.
> But it's really no big deal.

I'll add it to std.c.linux.linux


August 16, 2004
In article <cfpkqs$1qpv$1@digitaldaemon.com>, Walter says...
>
>I'll add it to std.c.linux.linux
>

Thanks a bunch then ;-)

Nick


August 17, 2004
On Sun, 15 Aug 2004 23:31:27 -0700, Walter <newshound@digitalmars.com> wrote:

>
> "Nick" <Nick_member@pathlink.com> wrote in message
> news:cfocpc$10ac$1@digitaldaemon.com...
>> In article <cfoao7$v10$1@digitaldaemon.com>, Walter says...
>> >
>> >You kind of have to write setErrno() in C, because errno is typically
>> >defined as a macro in <errno.h>. This is why getErrno() is written in 
>> C.
>> >
>>
>> Yep. But I was sort of hoping you would put it in phobos like you did with
>> getErrno() so I wouldn't have to drag along the extra object file all the
> time.
>> But it's really no big deal.
>
> I'll add it to std.c.linux.linux

What about windows? errno exists on windows too.

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
August 17, 2004
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opscur54d55a2sq9@digitalmars.com...
> > I'll add it to std.c.linux.linux
>
> What about windows? errno exists on windows too.

errno really only exists in the windows C compiler runtime libraries as an attempt to fake the unix errno behavior. It is not part of the Windows API. My intention is to skip the errno "middleman" on Win32 and go straight to the Win32 API, where GetLastError() does the trick.


« First   ‹ Prev
1 2